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