1 #!/opt/perl/bin/perl -w
3 # tests relating to searching. Especially around custom fields with long values
9 use RT::Test tests => 10;
13 my $q = RT::Queue->new($RT::SystemUser);
14 my $queue = 'SearchTests-'.$$;
15 $q->Create(Name => $queue);
16 ok ($q->id, "Created the queue");
20 my $cf = RT::CustomField->new($RT::SystemUser);
21 $cf->Create(Name => 'SearchTest', Type => 'Freeform', MaxValues => 0, Queue => $q->id);
22 ok($cf->id, "Created the SearchTest CF");
23 my $cflabel = "CustomField-".$cf->id;
26 my $t1 = RT::Ticket->new($RT::SystemUser);
27 my ( $id, undef $msg ) = $t1->Create(
29 Subject => 'SearchTest1',
30 Requestor => ['search@example.com'],
36 my $t2 = RT::Ticket->new($RT::SystemUser);
37 ( $id, undef, $msg ) = $t2->Create(
39 Subject => 'SearchTest2',
40 Requestor => ['searchlong@example.com'],
41 $cflabel => 'bar' x 150,
45 my $t3 = RT::Ticket->new($RT::SystemUser);
46 ( $id, undef, $msg ) = $t3->Create(
48 Subject => 'SearchTest3',
49 Requestor => ['searchlong@example.com'],
54 # we have tickets. start searching
55 my $tix = RT::Tickets->new($RT::SystemUser);
56 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo'");
57 is($tix->Count, 1, "matched short string foo")
58 or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
60 $tix = RT::Tickets->new($RT::SystemUser);
61 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'bar'");
62 is($tix->Count, 2, "matched long+short string bar")
63 or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
65 $tix = RT::Tickets->new($RT::SystemUser);
66 $tix->FromSQL("Queue = '$queue' AND ( CF.SearchTest LIKE 'foo' OR CF.SearchTest LIKE 'bar' )");
67 is($tix->Count, 3, "matched short string foo or long+short string bar")
68 or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
70 $tix = RT::Tickets->new($RT::SystemUser);
71 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest NOT LIKE 'foo' AND CF.SearchTest LIKE 'bar'");
72 is($tix->Count, 2, "not matched short string foo and matched long+short string bar")
73 or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
75 $tix = RT::Tickets->new($RT::SystemUser);
76 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo' AND CF.SearchTest NOT LIKE 'bar'");
77 is($tix->Count, 1, "matched short string foo and not matched long+short string bar")
78 or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;