fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / ticket / search_long_cf_values.t
1
2 # tests relating to searching. Especially around custom fields with long values
3 # (> 255 chars)
4
5 use strict;
6 use warnings;
7
8 use RT::Test nodata => 1, tests => 10;
9
10 # setup the queue
11
12 my $q = RT::Queue->new(RT->SystemUser);
13 my $queue = 'SearchTests-'.$$;
14 $q->Create(Name => $queue);
15 ok ($q->id, "Created the queue");
16
17
18 # setup the CF
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;
23
24 # setup some tickets
25 my $t1 = RT::Ticket->new(RT->SystemUser);
26 my ( $id, undef $msg ) = $t1->Create(
27     Queue      => $q->id,
28     Subject    => 'SearchTest1',
29     Requestor  => ['search@example.com'],
30     $cflabel   => 'foo',
31 );
32 ok( $id, $msg );
33
34
35 my $t2 = RT::Ticket->new(RT->SystemUser);
36 ( $id, undef, $msg ) = $t2->Create(
37     Queue      => $q->id,
38     Subject    => 'SearchTest2',
39     Requestor  => ['searchlong@example.com'],
40     $cflabel   => 'bar' x 150,
41 );
42 ok( $id, $msg );
43
44 my $t3 = RT::Ticket->new(RT->SystemUser);
45 ( $id, undef, $msg ) = $t3->Create(
46     Queue      => $q->id,
47     Subject    => 'SearchTest3',
48     Requestor  => ['searchlong@example.com'],
49     $cflabel   => 'bar',
50 );
51 ok( $id, $msg );
52
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;
58
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;
63
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;
68
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;
73
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;
78