3 use RT::Test tests => 19;
10 my $tix = RT::Tickets->new($RT::SystemUser);
12 my $query = "Status = 'open'";
13 my ($status, $msg) = $tix->FromSQL($query);
14 ok ($status, "correct query") or diag("error: $msg");
18 my (@created,%created);
19 my $string = 'subject/content SQL test';
21 my $t = RT::Ticket->new($RT::SystemUser);
22 ok( $t->Create(Queue => 'General', Subject => $string), "Ticket Created");
23 $created{ $t->Id }++; push @created, $t->Id;
27 my $Message = MIME::Entity->build(
28 Subject => 'this is my subject',
29 From => 'jesse@example.com',
33 my $t = RT::Ticket->new($RT::SystemUser);
34 ok( $t->Create( Queue => 'General',
35 Requestor => 'jesse@example.com',
36 Subject => 'another ticket',
38 MemberOf => $created[0]
42 $created{ $t->Id }++; push @created, $t->Id;
46 my $query = ("Subject LIKE '$string' OR Content LIKE '$string'");
47 my ($status, $msg) = $tix->FromSQL($query);
48 ok ($status, "correct query") or diag("error: $msg");
51 while (my $tick = $tix->Next) {
52 $count++ if $created{ $tick->id };
54 is ($count, scalar @created, "number of returned tickets same as entered");
58 my $query = "id = $created[0] OR MemberOf = $created[0]";
59 my ($status, $msg) = $tix->FromSQL($query);
60 ok ($status, "correct query") or diag("error: $msg");
63 while (my $tick = $tix->Next) {
64 $count++ if $created{ $tick->id };
66 is ($count, scalar @created, "number of returned tickets same as entered");
69 diag "Make sure we don't barf on invalid input for IS / IS NOT";
71 my ($status, $msg) = $tix->FromSQL("Subject IS 'foobar'");
72 ok ($status, "valid query") or diag("error: $msg");
73 is $tix->Count, 0, "found no tickets";
74 unlike $tix->BuildSelectQuery, qr/foobar/, "didn't find foobar in the select";
75 like $tix->BuildSelectQuery, qr/Subject IS NULL/, "found right clause";
77 my ($status, $msg) = $tix->FromSQL("Subject IS NOT 'foobar'");
78 ok ($status, "valid query") or diag("error: $msg");
79 is $tix->Count, 2, "found two tickets";
80 unlike $tix->BuildSelectQuery, qr/foobar/, "didn't find foobar in the select";
81 like $tix->BuildSelectQuery, qr/Subject IS NOT NULL/, "found right clause";
85 my ($status, $msg) = $tix->FromSQL("Requestor.Signature LIKE 'foo'");
86 ok (!$status, "invalid query - Signature not valid") or diag("error: $msg");
88 my ($status, $msg) = $tix->FromSQL("Requestor.EmailAddress LIKE 'jesse'");
89 ok ($status, "valid query") or diag("error: $msg");
90 is $tix->Count, 1, "found one ticket";
91 like $tix->First->Subject, qr/another ticket/, "found the right ticket";