6 use RT::Test tests => 17;
9 sub fails { ok(!$_[0], "This should fail: $_[1]") }
10 sub works { ok($_[0], $_[1] || 'This works') }
14 return $class->new($RT::SystemUser);
17 my $q = new(RT::Queue);
18 works($q->Create(Name => "CF-Pattern-".$$));
20 my $cf = new(RT::CustomField);
21 my @cf_args = (Name => $q->Name, Type => 'Freeform', Queue => $q->id, MaxValues => 1);
23 fails($cf->Create(@cf_args, Pattern => ')))bad!regex((('));
24 works($cf->Create(@cf_args, Pattern => 'good regex'));
26 my $t = new(RT::Ticket);
27 my ($id,undef,$msg) = $t->Create(Queue => $q->id, Subject => 'CF Test');
30 # OK, I'm thoroughly brain washed by HOP at this point now...
31 sub cnt { $t->CustomFieldValues($cf->id)->Count };
32 sub add { $t->AddCustomFieldValue(Field => $cf->id, Value => $_[0]) };
33 sub del { $t->DeleteCustomFieldValue(Field => $cf->id, Value => $_[0]) };
35 is(cnt(), 0, "No values yet");
36 fails(add('not going to match'));
37 is(cnt(), 0, "No values yet");
38 works(add('here is a good regex'));
39 is(cnt(), 1, "Value filled");
40 fails(del('here is a good regex'));
41 is(cnt(), 1, "Single CF - Value _not_ deleted");
43 $cf->SetMaxValues(0); # Unlimited MaxValues
45 works(del('here is a good regex'));
46 is(cnt(), 0, "Multiple CF - Value deleted");
48 fails($cf->SetPattern('(?{ "insert evil code here" })'));
49 works($cf->SetPattern('(?!)')); # reject everything