diff options
author | ivan <ivan> | 2009-12-31 13:16:41 +0000 |
---|---|---|
committer | ivan <ivan> | 2009-12-31 13:16:41 +0000 |
commit | 63a268637b2d51a8766412617724b9436439deb6 (patch) | |
tree | a50f6d4c7829d5c80905e989144317192a44dc90 /rt/t/ticket/sort-by-custom-ownership.t | |
parent | 65a561e3cd8c1ba94f6282f5d2a1cd9783afbd21 (diff) | |
parent | b4b0c7e72d7eaee2fbfc7022022c9698323203dd (diff) |
This commit was generated by cvs2svn to compensate for changes in r8690,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'rt/t/ticket/sort-by-custom-ownership.t')
-rw-r--r-- | rt/t/ticket/sort-by-custom-ownership.t | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/rt/t/ticket/sort-by-custom-ownership.t b/rt/t/ticket/sort-by-custom-ownership.t new file mode 100644 index 000000000..9739c5aec --- /dev/null +++ b/rt/t/ticket/sort-by-custom-ownership.t @@ -0,0 +1,103 @@ +#!/usr/bin/perl + +use RT; +use RT::Test tests => 7; + + +use strict; +use warnings; + +use RT::Tickets; +use RT::Queue; +use RT::CustomField; + +my($ret,$msg); + +# Test Paw Sort + + + +# ---- Create a queue to test with. +my $queue = "PAWSortQueue-$$"; +my $queue_obj = RT::Queue->new($RT::SystemUser); +($ret, $msg) = $queue_obj->Create(Name => $queue, + Description => 'queue for custom field sort testing'); +ok($ret, "$queue test queue creation. $msg"); + + +# ---- Create some users + +my $me = RT::User->new($RT::SystemUser); +($ret, $msg) = $me->Create(Name => "Me$$", EmailAddress => $$.'create-me-1@example.com'); +($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'OwnTicket'); +($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'SeeQueue'); +($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'ShowTicket'); +my $you = RT::User->new($RT::SystemUser); +($ret, $msg) = $you->Create(Name => "You$$", EmailAddress => $$.'create-you-1@example.com'); +($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'OwnTicket'); +($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'SeeQueue'); +($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'ShowTicket'); + +my $nobody = RT::User->new($RT::SystemUser); +$nobody->Load('nobody'); + + +# ----- Create some tickets to test with. Assign them some values to +# make it easy to sort with. + +my @tickets = ( + [qw[1 10], $me], + [qw[2 20], $me], + [qw[3 20], $you], + [qw[4 30], $you], + [qw[5 5], $nobody], + [qw[6 55], $nobody], + ); +for (@tickets) { + my $t = RT::Ticket->new($RT::SystemUser); + $t->Create( Queue => $queue_obj->Id, + Subject => $_->[0], + Owner => $_->[2]->Id, + Priority => $_->[1], + ); +} + +sub check_order { + my ($tx, @order) = @_; + my @results; + while (my $t = $tx->Next) { + push @results, $t->Subject; + } + my $results = join (" ",@results); + my $order = join(" ",@order); + is( $results, $order ); +} + + +# The real tests start here + +my $cme = new RT::CurrentUser( $me ); +my $metx = new RT::Tickets( $cme ); +# Make sure we can sort in both directions on a queue specific field. +$metx->FromSQL(qq[queue="$queue"] ); +$metx->OrderBy( FIELD => "Custom.Ownership", ORDER => 'ASC' ); +is($metx->Count,6); +check_order( $metx, qw[2 1 6 5 4 3]); + +$metx->OrderBy( FIELD => "Custom.Ownership", ORDER => 'DESC' ); +is($metx->Count,6); +check_order( $metx, reverse qw[2 1 6 5 4 3]); + + + +my $cyou = new RT::CurrentUser( $you ); +my $youtx = new RT::Tickets( $cyou ); +# Make sure we can sort in both directions on a queue specific field. +$youtx->FromSQL(qq[queue="$queue"] ); +$youtx->OrderBy( FIELD => "Custom.Ownership", ORDER => 'ASC' ); +is($youtx->Count,6); +check_order( $youtx, qw[4 3 6 5 2 1]); + +__END__ + + |