diff options
| author | Ivan Kohler <ivan@freeside.biz> | 2012-07-02 14:24:21 -0700 |
|---|---|---|
| committer | Ivan Kohler <ivan@freeside.biz> | 2012-07-02 14:24:21 -0700 |
| commit | 85e677b86fc37c54e6de2b06340351a28f5a5916 (patch) | |
| tree | 11148e2c292bd1a43b7cf6c2f5212a6ca8b03e75 /rt/t/customfields/pattern.t | |
| parent | e5ab051ccdb7637d8dd2f0ed9b4fe9aaaf1d1100 (diff) | |
| parent | 92aedddd3684167abb60cd3f1d77bbc156c592e6 (diff) | |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'rt/t/customfields/pattern.t')
| -rw-r--r-- | rt/t/customfields/pattern.t | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/rt/t/customfields/pattern.t b/rt/t/customfields/pattern.t new file mode 100644 index 000000000..7d1090fa7 --- /dev/null +++ b/rt/t/customfields/pattern.t @@ -0,0 +1,44 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use RT; +use RT::Test nodata => 1, tests => 17; + +my $q = RT::Queue->new($RT::SystemUser); +works($q->Create(Name => "CF-Pattern-".$$)); + +my $cf = RT::CustomField->new($RT::SystemUser); +my @cf_args = (Name => $q->Name, Type => 'Freeform', Queue => $q->id, MaxValues => 1); + +fails($cf->Create(@cf_args, Pattern => ')))bad!regex(((')); +works($cf->Create(@cf_args, Pattern => 'good regex')); + +my $t = RT::Ticket->new($RT::SystemUser); +my ($id,undef,$msg) = $t->Create(Queue => $q->id, Subject => 'CF Test'); +works($id,$msg); + +# OK, I'm thoroughly brain washed by HOP at this point now... +sub cnt { $t->CustomFieldValues($cf->id)->Count }; +sub add { $t->AddCustomFieldValue(Field => $cf->id, Value => $_[0]) }; +sub del { $t->DeleteCustomFieldValue(Field => $cf->id, Value => $_[0]) }; + +is(cnt(), 0, "No values yet"); +fails(add('not going to match')); +is(cnt(), 0, "No values yet"); +works(add('here is a good regex')); +is(cnt(), 1, "Value filled"); +fails(del('here is a good regex')); +is(cnt(), 1, "Single CF - Value _not_ deleted"); + +$cf->SetMaxValues(0); # Unlimited MaxValues + +works(del('here is a good regex')); +is(cnt(), 0, "Multiple CF - Value deleted"); + +fails($cf->SetPattern('(?{ "insert evil code here" })')); +works($cf->SetPattern('(?!)')); # reject everything +fails(add('')); +fails(add('...')); + +undef $t; |
