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