first pass RT4 merge, RT#13852
[freeside.git] / rt / t / web / charting.t
1 use strict;
2 use warnings;
3
4 BEGIN {
5     require RT::Test;
6
7     if (eval { require GD; 1 }) {
8         RT::Test->import(plan => 'no_plan');
9     }
10     else {
11         RT::Test->import(skip_all => 'GD required.');
12     }
13 }
14
15 for my $n (1..7) {
16     my $ticket = RT::Ticket->new( RT->SystemUser );
17     my $req = 'root' . ($n % 2) . '@localhost';
18     my ( $ret, $msg ) = $ticket->Create(
19         Subject   => "base ticket $_",
20         Queue     => "General",
21         Owner     => "root",
22         Requestor => $req,
23         MIMEObj   => MIME::Entity->build(
24             From    => $req,
25             To      => 'rt@localhost',
26             Subject => "base ticket $_",
27             Data    => "Content $_",
28         ),
29     );
30     ok( $ret, "ticket $n created: $msg" );
31 }
32
33 my ($url, $m) = RT::Test->started_ok;
34 ok( $m->login, "Logged in" );
35
36 # Test that defaults work
37 $m->get_ok( "/Search/Chart.html?Query=id>0" );
38 $m->content_like(qr{<th[^>]*>Queue\s*</th>\s*<th[^>]*>Tickets\s*</th>}, "Grouped by queue");
39 $m->content_like(qr{General</a>\s*</td>\s*<td[^>]*>\s*<a[^>]*>7</a>}, "Found results in table");
40 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
41
42 $m->get_ok( "/Search/Chart?Query=id>0" );
43 is( $m->content_type, "image/png" );
44 ok( length($m->content), "Has content" );
45
46
47 # Group by Queue
48 $m->get_ok( "/Search/Chart.html?Query=id>0&PrimaryGroupBy=Queue" );
49 $m->content_like(qr{<th[^>]*>Queue\s*</th>\s*<th[^>]*>Tickets\s*</th>}, "Grouped by queue");
50 $m->content_like(qr{General</a>\s*</td>\s*<td[^>]*>\s*<a[^>]*>7</a>}, "Found results in table");
51 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
52
53 $m->get_ok( "/Search/Chart?Query=id>0&PrimaryGroupBy=Queue" );
54 is( $m->content_type, "image/png" );
55 ok( length($m->content), "Has content" );
56
57
58 # Group by Requestor email
59 $m->get_ok( "/Search/Chart.html?Query=id>0&PrimaryGroupBy=Requestor.EmailAddress" );
60 $m->content_like(qr{<th[^>]*>Requestor\.EmailAddress\s*</th>\s*<th[^>]*>Tickets\s*</th>},
61                  "Grouped by requestor");
62 $m->content_like(qr{root0\@localhost</a>\s*</td>\s*<td[^>]*>\s*<a[^>]*>3</a>}, "Found results in table");
63 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
64
65 $m->get_ok( "/Search/Chart?Query=id>0&PrimaryGroupBy=Requestor.Email" );
66 is( $m->content_type, "image/png" );
67 ok( length($m->content), "Has content" );
68
69
70 # Group by Requestor phone -- which is bogus, and falls back to queue
71 $m->get_ok( "/Search/Chart.html?Query=id>0&PrimaryGroupBy=Requestor.Phone" );
72 $m->content_like(qr{General</a>\s*</td>\s*<td[^>]*>\s*<a[^>]*>7</a>},
73                  "Found queue results in table, as a default");
74 $m->content_like(qr{<img src="/Search/Chart\?}, "Found image");
75
76 $m->get_ok( "/Search/Chart?Query=id>0&PrimaryGroupBy=Requestor.Phone" );
77 is( $m->content_type, "image/png" );
78 ok( length($m->content), "Has content" );