default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / rt / t / api / tickets_overlay_sql.t
1 use strict;
2 use warnings;
3 use RT::Test tests => 20, config => 'Set( %FullTextSearch, Enable => 1 );';
4 use Test::Warn;
5
6 my $tix = RT::Tickets->new(RT->SystemUser);
7 {
8     my $query = "Status = 'open'";
9     my ($status, $msg)  = $tix->FromSQL($query);
10     ok ($status, "correct query") or diag("error: $msg");
11 }
12
13
14 my (@created,%created);
15 my $string = 'subject/content SQL test';
16 {
17     my $t = RT::Ticket->new(RT->SystemUser);
18     ok( $t->Create(Queue => 'General', Subject => $string), "Ticket Created");
19     $created{ $t->Id }++; push @created, $t->Id;
20 }
21
22 {
23     my $Message = MIME::Entity->build(
24                      Subject     => 'this is my subject',
25                      From        => 'jesse@example.com',
26                      Data        => [ $string ],
27             );
28
29     my $t = RT::Ticket->new(RT->SystemUser);
30     ok( $t->Create( Queue => 'General',
31                     Requestor => 'jesse@example.com',
32                     Subject => 'another ticket',
33                     MIMEObj => $Message,
34                     MemberOf => $created[0]
35                   ),
36         "Ticket Created"
37     );
38     $created{ $t->Id }++; push @created, $t->Id;
39 }
40
41 {
42     my $query = ("Subject LIKE '$string' OR Content LIKE '$string'");
43     my ($status, $msg) = $tix->FromSQL($query);
44     ok ($status, "correct query") or diag("error: $msg");
45
46     my $count = 0;
47     while (my $tick = $tix->Next) {
48         $count++ if $created{ $tick->id };
49     }
50     is ($count, scalar @created, "number of returned tickets same as entered");
51 }
52
53 {
54     my $query = "id = $created[0] OR MemberOf = $created[0]";
55     my ($status, $msg) = $tix->FromSQL($query);
56     ok ($status, "correct query") or diag("error: $msg");
57
58     my $count = 0;
59     while (my $tick = $tix->Next) {
60         $count++ if $created{ $tick->id };
61     }
62     is ($count, scalar @created, "number of returned tickets same as entered");
63 }
64
65 diag "Make sure we don't barf on invalid input for IS / IS NOT";
66 {
67     my ($status, $msg) = $tix->FromSQL("Subject IS 'foobar'");
68     ok ($status, "valid query") or diag("error: $msg");
69     is $tix->Count, 0, "found no tickets";
70     unlike $tix->BuildSelectQuery, qr/foobar/, "didn't find foobar in the select";
71     like $tix->BuildSelectQuery, qr/Subject IS NULL/, "found right clause";
72     
73     ($status, $msg) = $tix->FromSQL("Subject IS NOT 'foobar'");
74     ok ($status, "valid query") or diag("error: $msg");
75     is $tix->Count, 2, "found two tickets";
76     unlike $tix->BuildSelectQuery, qr/foobar/, "didn't find foobar in the select";
77     like $tix->BuildSelectQuery, qr/Subject IS NOT NULL/, "found right clause";
78 }
79
80 {
81     my ($status, $msg);
82
83     warning_like {
84         ($status, $msg) = $tix->FromSQL("Requestor.Signature LIKE 'foo'");
85     } qr/Invalid watcher subfield: 'Signature'/;
86     ok(!$status, "invalid query - Signature not valid") or diag("error: $msg");
87
88     ($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";
92 }
93