fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / charts / basics.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => undef;
5 use RT::Ticket;
6
7 my $q = RT::Test->load_or_create_queue( Name => 'General' );
8 ok $q && $q->id, 'loaded or created queue';
9 my $queue = $q->Name;
10
11 my @tickets = add_tix_from_data(
12     { Subject => 'n', Status => 'new' },
13     { Subject => 'o', Status => 'open' },
14     { Subject => 'o', Status => 'open' },
15     { Subject => 'r', Status => 'resolved' },
16     { Subject => 'r', Status => 'resolved' },
17     { Subject => 'r', Status => 'resolved' },
18 );
19
20 use_ok 'RT::Report::Tickets';
21
22 {
23     my $report = RT::Report::Tickets->new( RT->SystemUser );
24     my %columns = $report->SetupGroupings(
25         Query    => 'Queue = '. $q->id,
26         GroupBy  => ['Status'],
27         Function => ['COUNT'],
28     );
29     $report->SortEntries;
30
31     my @colors = RT->Config->Get("ChartColors");
32     my $expected = {
33         'thead' => [ {
34                 'cells' => [
35                     { 'value' => 'Status', 'type' => 'head' },
36                     { 'rowspan' => 1, 'value' => 'Ticket count', 'type' => 'head', 'color' => $colors[0] },
37                 ],
38         } ],
39        'tfoot' => [ {
40             'cells' => [
41                 { 'colspan' => 1, 'value' => 'Total', 'type' => 'label' },
42                 { 'value' => 6, 'type' => 'value' },
43             ],
44             'even' => 0
45         } ],
46        'tbody' => [
47             {
48                 'cells' => [
49                     { 'value' => 'new', 'type' => 'label' },
50                     { 'query' => '(Status = \'new\')', 'value' => '1', 'type' => 'value' },
51                 ],
52                 'even' => 1
53             },
54             {
55                 'cells' => [
56                     { 'value' => 'open', 'type' => 'label' },
57                     { 'query' => '(Status = \'open\')', 'value' => '2', 'type' => 'value' }
58                 ],
59                 'even' => 0
60             },
61             {
62                 'cells' => [
63                     { 'value' => 'resolved', 'type' => 'label' },
64                     { 'query' => '(Status = \'resolved\')', 'value' => '3', 'type' => 'value' }
65                 ],
66                 'even' => 1
67             },
68         ]
69     };
70
71     my %table = $report->FormatTable( %columns );
72     is_deeply( \%table, $expected, "basic table" );
73 }
74
75 done_testing;
76
77
78 sub add_tix_from_data {
79     my @data = @_;
80     my @res = ();
81     while (@data) {
82         my %info = %{ shift(@data) };
83         my $t = RT::Ticket->new($RT::SystemUser);
84         my ( $id, undef, $msg ) = $t->Create( Queue => $q->id, %info );
85         ok( $id, "ticket created" ) or diag("error: $msg");
86         is $t->Status, $info{'Status'}, 'correct status';
87         push @res, $t;
88     }
89     return @res;
90 }
91