diff options
Diffstat (limited to 'rt/t/charts')
-rw-r--r-- | rt/t/charts/basics.t | 91 | ||||
-rw-r--r-- | rt/t/charts/compound-sql-function.t | 121 | ||||
-rw-r--r-- | rt/t/charts/group-by-cf.t | 71 |
3 files changed, 283 insertions, 0 deletions
diff --git a/rt/t/charts/basics.t b/rt/t/charts/basics.t new file mode 100644 index 000000000..0f93e5a24 --- /dev/null +++ b/rt/t/charts/basics.t @@ -0,0 +1,91 @@ +use strict; +use warnings; + +use RT::Test tests => undef; +use RT::Ticket; + +my $q = RT::Test->load_or_create_queue( Name => 'General' ); +ok $q && $q->id, 'loaded or created queue'; +my $queue = $q->Name; + +my @tickets = add_tix_from_data( + { Subject => 'n', Status => 'new' }, + { Subject => 'o', Status => 'open' }, + { Subject => 'o', Status => 'open' }, + { Subject => 'r', Status => 'resolved' }, + { Subject => 'r', Status => 'resolved' }, + { Subject => 'r', Status => 'resolved' }, +); + +use_ok 'RT::Report::Tickets'; + +{ + my $report = RT::Report::Tickets->new( RT->SystemUser ); + my %columns = $report->SetupGroupings( + Query => 'Queue = '. $q->id, + GroupBy => ['Status'], + Function => ['COUNT'], + ); + $report->SortEntries; + + my @colors = RT->Config->Get("ChartColors"); + my $expected = { + 'thead' => [ { + 'cells' => [ + { 'value' => 'Status', 'type' => 'head' }, + { 'rowspan' => 1, 'value' => 'Ticket count', 'type' => 'head', 'color' => $colors[0] }, + ], + } ], + 'tfoot' => [ { + 'cells' => [ + { 'colspan' => 1, 'value' => 'Total', 'type' => 'label' }, + { 'value' => 6, 'type' => 'value' }, + ], + 'even' => 0 + } ], + 'tbody' => [ + { + 'cells' => [ + { 'value' => 'new', 'type' => 'label' }, + { 'query' => '(Status = \'new\')', 'value' => '1', 'type' => 'value' }, + ], + 'even' => 1 + }, + { + 'cells' => [ + { 'value' => 'open', 'type' => 'label' }, + { 'query' => '(Status = \'open\')', 'value' => '2', 'type' => 'value' } + ], + 'even' => 0 + }, + { + 'cells' => [ + { 'value' => 'resolved', 'type' => 'label' }, + { 'query' => '(Status = \'resolved\')', 'value' => '3', 'type' => 'value' } + ], + 'even' => 1 + }, + ] + }; + + my %table = $report->FormatTable( %columns ); + is_deeply( \%table, $expected, "basic table" ); +} + +done_testing; + + +sub add_tix_from_data { + my @data = @_; + my @res = (); + while (@data) { + my %info = %{ shift(@data) }; + my $t = RT::Ticket->new($RT::SystemUser); + my ( $id, undef, $msg ) = $t->Create( Queue => $q->id, %info ); + ok( $id, "ticket created" ) or diag("error: $msg"); + is $t->Status, $info{'Status'}, 'correct status'; + push @res, $t; + } + return @res; +} + diff --git a/rt/t/charts/compound-sql-function.t b/rt/t/charts/compound-sql-function.t new file mode 100644 index 000000000..3e6a3fdfe --- /dev/null +++ b/rt/t/charts/compound-sql-function.t @@ -0,0 +1,121 @@ + +use strict; +use warnings; + +use RT::Test tests => 14; +use RT::Ticket; + +my $q1 = RT::Test->load_or_create_queue( Name => 'One' ); +ok $q1 && $q1->id, 'loaded or created queue'; + +my $q2 = RT::Test->load_or_create_queue( Name => 'Two' ); +ok $q2 && $q2->id, 'loaded or created queue'; + +my @tickets = add_tix_from_data( + { Queue => $q1->id, Resolved => 3*60 }, + { Queue => $q1->id, Resolved => 3*60*60 }, + { Queue => $q1->id, Resolved => 3*24*60*60 }, + { Queue => $q1->id, Resolved => 3*30*24*60*60 }, + { Queue => $q1->id, Resolved => 9*30*24*60*60 }, + { Queue => $q2->id, Resolved => 7*60 }, + { Queue => $q2->id, Resolved => 7*60*60 }, + { Queue => $q2->id, Resolved => 7*24*60*60 }, + { Queue => $q2->id, Resolved => 7*30*24*60*60 }, + { Queue => $q2->id, Resolved => 24*30*24*60*60 }, +); + +use_ok 'RT::Report::Tickets'; + +{ + my $report = RT::Report::Tickets->new( RT->SystemUser ); + my %columns = $report->SetupGroupings( + Query => 'id > 0', + GroupBy => ['Queue'], + Function => ['ALL(Created-Resolved)'], + ); + $report->SortEntries; + + my @colors = RT->Config->Get("ChartColors"); + my $expected = { + 'thead' => [ + { + 'cells' => [ + { 'rowspan' => 2, 'value' => 'Queue', 'type' => 'head' }, + { 'colspan' => 4, 'value' => 'Summary of Created-Resolved', 'type' => 'head' } + ] + }, + { + 'cells' => [ + { 'value' => 'Minimum', 'type' => 'head', 'color' => $colors[0] }, + { 'value' => 'Average', 'type' => 'head', 'color' => $colors[1] }, + { 'value' => 'Maximum', 'type' => 'head', 'color' => $colors[2] }, + { 'value' => 'Total', 'type' => 'head', 'color' => $colors[3] } + ] + } + ], + 'tfoot' => [ + { + 'cells' => [ + { 'colspan' => 1, 'value' => 'Total', 'type' => 'label' }, + { 'value' => '10m', 'type' => 'value' }, + { 'value' => '8M 2W 3d', 'type' => 'value' }, + { 'value' => '2Y 8M 2W', 'type' => 'value' }, + { 'value' => '3Y 6M 3W', 'type' => 'value' } + ], + 'even' => 1 + } + ], + 'tbody' => [ + { + 'cells' => [ + { 'value' => 'One', 'type' => 'label' }, + { 'query' => '(Queue = 3)', 'value' => '3m', 'type' => 'value' }, + { 'query' => '(Queue = 3)', 'value' => '2M 1W 5d', 'type' => 'value' }, + { 'query' => '(Queue = 3)', 'value' => '8M 3W 6d', 'type' => 'value' }, + { 'query' => '(Queue = 3)', 'value' => '11M 4W 8h', 'type' => 'value' } + ], + 'even' => 1 + }, + { + 'cells' => [ + { 'value' => 'Two', 'type' => 'label' }, + { 'query' => '(Queue = 4)', 'value' => '7m', 'type' => 'value' }, + { 'query' => '(Queue = 4)', 'value' => '6M 4d 20h', 'type' => 'value' }, + { 'query' => '(Queue = 4)', 'value' => '1Y 11M 3W', 'type' => 'value' }, + { 'query' => '(Queue = 4)', 'value' => '2Y 6M 3W', 'type' => 'value' } + ], + 'even' => 0 + } + ] + }; + + my %table = $report->FormatTable( %columns ); + is_deeply( \%table, $expected, "basic table" ); +} + + +sub add_tix_from_data { + my @data = @_; + my @res = (); + + my $created = RT::Date->new( $RT::SystemUser ); + $created->SetToNow; + + my $resolved = RT::Date->new( $RT::SystemUser ); + + while (@data) { + $resolved->Set( Value => $created->Unix ); + $resolved->AddSeconds( $data[0]{'Resolved'} ); + my $t = RT::Ticket->new($RT::SystemUser); + my ( $id, undef $msg ) = $t->Create( + %{ shift(@data) }, + Created => $created->ISO, + Resolved => $resolved->ISO, + ); + ok( $id, "ticket created" ) or diag("error: $msg"); + push @res, $t; + } + return @res; +} + + diff --git a/rt/t/charts/group-by-cf.t b/rt/t/charts/group-by-cf.t new file mode 100644 index 000000000..f6bfb35e4 --- /dev/null +++ b/rt/t/charts/group-by-cf.t @@ -0,0 +1,71 @@ +use strict; +use warnings; + +use RT::Test tests => undef; +use RT::Ticket; + +my $q = RT::Test->load_or_create_queue( Name => 'General' ); +ok $q && $q->id, 'loaded or created queue'; +my $queue = $q->Name; + +my $cf = RT::CustomField->new(RT->SystemUser); +my ($id,$msg) = $cf->Create(Name => 'Test', Type => 'Freeform', MaxValues => '1', Queue => $q->id); +ok $id, $msg; +my $cfid = $cf->id; + + +my @tickets = RT::Test->create_tickets( + {}, + { Subject => 't1', Status => 'new', CustomFields => { Test => 'a' } }, + { Subject => 't2', Status => 'open', CustomFields => { Test => 'b' } }, +); + +use_ok 'RT::Report::Tickets'; + +{ + my $report = RT::Report::Tickets->new( RT->SystemUser ); + my %columns = $report->SetupGroupings( + Query => 'Queue = '. $q->id, + GroupBy => ["CF.{$cfid}"], # TODO: CF.{Name} is not supported at the moment + Function => ['COUNT'], + ); + $report->SortEntries; + + my @colors = RT->Config->Get("ChartColors"); + my $expected = { + 'thead' => [ { + 'cells' => [ + { 'value' => 'Custom field Test', 'type' => 'head' }, + { 'rowspan' => 1, 'value' => 'Ticket count', 'type' => 'head', 'color' => $colors[0] }, + ], + } ], + 'tfoot' => [ { + 'cells' => [ + { 'colspan' => 1, 'value' => 'Total', 'type' => 'label' }, + { 'value' => 2, 'type' => 'value' }, + ], + 'even' => 1 + } ], + 'tbody' => [ + { + 'cells' => [ + { 'value' => 'a', 'type' => 'label' }, + { 'query' => "(CF.{$cfid} = 'a')", 'value' => '1', 'type' => 'value' }, + ], + 'even' => 1 + }, + { + 'cells' => [ + { 'value' => 'b', 'type' => 'label' }, + { 'query' => "(CF.{$cfid} = 'b')", 'value' => '1', 'type' => 'value' }, + ], + 'even' => 0 + }, + ] + }; + + my %table = $report->FormatTable( %columns ); + is_deeply( \%table, $expected, "basic table" ); +} + +done_testing; |