fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / charting.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => undef;
5
6 plan skip_all => 'GD required'
7     unless GD->require;
8
9 for my $n (1..7) {
10     my $ticket = RT::Ticket->new( RT->SystemUser );
11     my $req = 'root' . ($n % 2) . '@localhost';
12     my ( $ret, $msg ) = $ticket->Create(
13         Subject   => "base ticket $_",
14         Queue     => "General",
15         Owner     => "root",
16         Requestor => $req,
17         MIMEObj   => MIME::Entity->build(
18             From    => $req,
19             To      => 'rt@localhost',
20             Subject => "base ticket $_",
21             Data    => "Content $_",
22         ),
23     );
24     ok( $ret, "ticket $n created: $msg" );
25 }
26
27 my ($url, $m) = RT::Test->started_ok;
28 ok( $m->login, "Logged in" );
29
30 # Test that defaults work
31 $m->get_ok( "/Search/Chart.html?Query=id>0" );
32 $m->content_like(qr{<th[^>]*>Status\s*</th>\s*<th[^>]*>Ticket count\s*</th>}, "Grouped by status");
33 $m->content_like(qr{new\s*</th>\s*<td[^>]*>\s*<a[^>]*>7</a>}, "Found results in table");
34 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
35
36 $m->get_ok( "/Search/Chart?Query=id>0" );
37 is( $m->content_type, "image/png" );
38 ok( length($m->content), "Has content" );
39
40
41 # Group by Queue
42 $m->get_ok( "/Search/Chart.html?Query=id>0&GroupBy=Queue" );
43 $m->content_like(qr{<th[^>]*>Queue\s*</th>\s*<th[^>]*>Ticket count\s*</th>}, "Grouped by queue");
44 $m->content_like(qr{General\s*</th>\s*<td[^>]*>\s*<a[^>]*>7</a>}, "Found results in table");
45 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
46
47 $m->get_ok( "/Search/Chart?Query=id>0&GroupBy=Queue" );
48 is( $m->content_type, "image/png" );
49 ok( length($m->content), "Has content" );
50
51
52 # Group by Requestor email
53 $m->get_ok( "/Search/Chart.html?Query=id>0&GroupBy=Requestor.EmailAddress" );
54 $m->content_like(qr{<th[^>]*>Requestor\s+EmailAddress</th>\s*<th[^>]*>Ticket count\s*</th>},
55                  "Grouped by requestor");
56 $m->content_like(qr{root0\@localhost\s*</th>\s*<td[^>]*>\s*<a[^>]*>3</a>}, "Found results in table");
57 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
58
59 $m->get_ok( "/Search/Chart?Query=id>0&GroupBy=Requestor.EmailAddress" );
60 is( $m->content_type, "image/png" );
61 ok( length($m->content), "Has content" );
62
63 # Group by Requestor phone -- which is bogus, and falls back to queue
64
65 $m->get_ok( "/Search/Chart.html?Query=id>0&GroupBy=Requestor.Phone" );
66 $m->warning_like( qr{'Requestor\.Phone' is not a valid grouping for reports} );
67
68 TODO: {
69     local $TODO = "UI should show that it's group by status";
70     $m->content_like(qr{new\s*</th>\s*<td[^>]*>\s*<a[^>]*>7</a>},
71                  "Found queue results in table, as a default");
72 }
73 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
74
75 $m->get_ok( "/Search/Chart?Query=id>0&GroupBy=Requestor.Phone" );
76 $m->warning_like( qr{'Requestor\.Phone' is not a valid grouping for reports} );
77 is( $m->content_type, "image/png" );
78 ok( length($m->content), "Has content" );
79
80 diag "Confirm subnav links use Query param before saved search in session.";
81
82 $m->get_ok( "/Search/Chart.html?Query=id>0" );
83 my $advanced = $m->find_link( text => 'Advanced' )->URI->equery;
84 like( $advanced, qr{Query=id%3E0},
85       'Advanced link has Query param with id search'
86     );
87
88 # Load the session with another search.
89 $m->get_ok( "/Search/Results.html?Query=Queue='General'" );
90
91 $m->get_ok( "/Search/Chart.html?Query=id>0" );
92 $advanced = $m->find_link( text => 'Advanced' )->URI->equery;
93 like( $advanced, qr{Query=id%3E0},
94       'Advanced link still has Query param with id search'
95     );
96
97 undef $m;
98 done_testing;