fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / charts / group-by-cf.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 $cf = RT::CustomField->new(RT->SystemUser);
12 my ($id,$msg) = $cf->Create(Name => 'Test', Type => 'Freeform', MaxValues => '1', Queue => $q->id);
13 ok $id, $msg;
14 my $cfid = $cf->id;
15
16
17 my @tickets = RT::Test->create_tickets(
18     {},
19     { Subject => 't1', Status => 'new', CustomFields => { Test => 'a' } },
20     { Subject => 't2', Status => 'open', CustomFields => { Test => 'b' } },
21 );
22
23 use_ok 'RT::Report::Tickets';
24
25 {
26     my $report = RT::Report::Tickets->new( RT->SystemUser );
27     my %columns = $report->SetupGroupings(
28         Query    => 'Queue = '. $q->id,
29         GroupBy  => ["CF.{$cfid}"], # TODO: CF.{Name} is not supported at the moment
30         Function => ['COUNT'],
31     );
32     $report->SortEntries;
33
34     my @colors = RT->Config->Get("ChartColors");
35     my $expected = {
36         'thead' => [ {
37                 'cells' => [
38                     { 'value' => 'Custom field Test', 'type' => 'head' },
39                     { 'rowspan' => 1, 'value' => 'Ticket count', 'type' => 'head', 'color' => $colors[0] },
40                 ],
41         } ],
42        'tfoot' => [ {
43             'cells' => [
44                 { 'colspan' => 1, 'value' => 'Total', 'type' => 'label' },
45                 { 'value' => 2, 'type' => 'value' },
46             ],
47             'even' => 1
48         } ],
49        'tbody' => [
50             {
51                 'cells' => [
52                     { 'value' => 'a', 'type' => 'label' },
53                     { 'query' => "(CF.{$cfid} = 'a')", 'value' => '1', 'type' => 'value' },
54                 ],
55                 'even' => 1
56             },
57             {
58                 'cells' => [
59                     { 'value' => 'b', 'type' => 'label' },
60                     { 'query' => "(CF.{$cfid} = 'b')", 'value' => '1', 'type' => 'value' },
61                 ],
62                 'even' => 0
63             },
64         ]
65     };
66
67     my %table = $report->FormatTable( %columns );
68     is_deeply( \%table, $expected, "basic table" );
69 }
70
71 done_testing;