4 use RT::Test tests => 7;
20 # ---- Create a queue to test with.
21 my $queue = "PAWSortQueue-$$";
22 my $queue_obj = RT::Queue->new($RT::SystemUser);
23 ($ret, $msg) = $queue_obj->Create(Name => $queue,
24 Description => 'queue for custom field sort testing');
25 ok($ret, "$queue test queue creation. $msg");
28 # ---- Create some users
30 my $me = RT::User->new($RT::SystemUser);
31 ($ret, $msg) = $me->Create(Name => "Me$$", EmailAddress => $$.'create-me-1@example.com');
32 ($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'OwnTicket');
33 ($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'SeeQueue');
34 ($ret, $msg) = $me->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'ShowTicket');
35 my $you = RT::User->new($RT::SystemUser);
36 ($ret, $msg) = $you->Create(Name => "You$$", EmailAddress => $$.'create-you-1@example.com');
37 ($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'OwnTicket');
38 ($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'SeeQueue');
39 ($ret, $msg) = $you->PrincipalObj->GrantRight(Object =>$queue_obj, Right => 'ShowTicket');
41 my $nobody = RT::User->new($RT::SystemUser);
42 $nobody->Load('nobody');
45 # ----- Create some tickets to test with. Assign them some values to
46 # make it easy to sort with.
57 my $t = RT::Ticket->new($RT::SystemUser);
58 $t->Create( Queue => $queue_obj->Id,
66 my ($tx, @order) = @_;
68 while (my $t = $tx->Next) {
69 push @results, $t->Subject;
71 my $results = join (" ",@results);
72 my $order = join(" ",@order);
73 is( $results, $order );
77 # The real tests start here
79 my $cme = new RT::CurrentUser( $me );
80 my $metx = new RT::Tickets( $cme );
81 # Make sure we can sort in both directions on a queue specific field.
82 $metx->FromSQL(qq[queue="$queue"] );
83 $metx->OrderBy( FIELD => "Custom.Ownership", ORDER => 'ASC' );
85 check_order( $metx, qw[2 1 6 5 4 3]);
87 $metx->OrderBy( FIELD => "Custom.Ownership", ORDER => 'DESC' );
89 check_order( $metx, reverse qw[2 1 6 5 4 3]);
93 my $cyou = new RT::CurrentUser( $you );
94 my $youtx = new RT::Tickets( $cyou );
95 # Make sure we can sort in both directions on a queue specific field.
96 $youtx->FromSQL(qq[queue="$queue"] );
97 $youtx->OrderBy( FIELD => "Custom.Ownership", ORDER => 'ASC' );
99 check_order( $youtx, qw[4 3 6 5 2 1]);