2 # tests relating to searching. Especially around custom fields with long values
8 use RT::Test nodata => 1, tests => 10;
12 my $q = RT::Queue->new(RT->SystemUser);
13 my $queue = 'SearchTests-'.$$;
14 $q->Create(Name => $queue);
15 ok ($q->id, "Created the queue");
19 my $cf = RT::CustomField->new(RT->SystemUser);
20 $cf->Create(Name => 'SearchTest', Type => 'Freeform', MaxValues => 0, Queue => $q->id);
21 ok($cf->id, "Created the SearchTest CF");
22 my $cflabel = "CustomField-".$cf->id;
25 my $t1 = RT::Ticket->new(RT->SystemUser);
26 my ( $id, undef $msg ) = $t1->Create(
28 Subject => 'SearchTest1',
29 Requestor => ['search@example.com'],
35 my $t2 = RT::Ticket->new(RT->SystemUser);
36 ( $id, undef, $msg ) = $t2->Create(
38 Subject => 'SearchTest2',
39 Requestor => ['searchlong@example.com'],
40 $cflabel => 'bar' x 150,
44 my $t3 = RT::Ticket->new(RT->SystemUser);
45 ( $id, undef, $msg ) = $t3->Create(
47 Subject => 'SearchTest3',
48 Requestor => ['searchlong@example.com'],
53 # we have tickets. start searching
54 my $tix = RT::Tickets->new(RT->SystemUser);
55 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo'");
56 is($tix->Count, 1, "matched short string foo")
57 or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
59 $tix = RT::Tickets->new(RT->SystemUser);
60 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'bar'");
61 is($tix->Count, 2, "matched long+short string bar")
62 or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
64 $tix = RT::Tickets->new(RT->SystemUser);
65 $tix->FromSQL("Queue = '$queue' AND ( CF.SearchTest LIKE 'foo' OR CF.SearchTest LIKE 'bar' )");
66 is($tix->Count, 3, "matched short string foo or long+short string bar")
67 or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
69 $tix = RT::Tickets->new(RT->SystemUser);
70 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest NOT LIKE 'foo' AND CF.SearchTest LIKE 'bar'");
71 is($tix->Count, 2, "not matched short string foo and matched long+short string bar")
72 or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;
74 $tix = RT::Tickets->new(RT->SystemUser);
75 $tix->FromSQL("Queue = '$queue' AND CF.SearchTest LIKE 'foo' AND CF.SearchTest NOT LIKE 'bar'");
76 is($tix->Count, 1, "matched short string foo and not matched long+short string bar")
77 or diag "wrong results from SQL:\n". $tix->BuildSelectCountQuery;