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