X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2Ft%2Fregression%2F23cfsort.t;h=ba404f2ba33aedd46db10b7e392eb6c9c0736e74;hb=fc6209f398899f0211cfcedeb81a3cd65e04a941;hp=e90fa36b25aa4dff9ab76631c6d5b724bae7c7ef;hpb=ef20b2b6b1feb47ad02b5ff7525f1a0fd11d0fa4;p=freeside.git diff --git a/rt/lib/t/regression/23cfsort.t b/rt/lib/t/regression/23cfsort.t index e90fa36b2..ba404f2ba 100644 --- a/rt/lib/t/regression/23cfsort.t +++ b/rt/lib/t/regression/23cfsort.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -use Test::More tests => 15; +use Test::More tests => 21; use RT; RT::LoadConfig(); RT::Init(); @@ -16,12 +16,16 @@ my($ret,$msg); # Test Sorting by custom fields. +# TODO: it's hard to read this file, conver to new style, +# for example look at 23cfsort-freeform-single.t # ---- Create a queue to test with. my $queue = "CFSortQueue-$$"; -my $queue_obj = RT::Queue->new($RT::SystemUser); -($ret, $msg) = $queue_obj->Create(Name => $queue, - Description => 'queue for custom field sort testing'); +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 custom fields. We're not currently using all of @@ -34,7 +38,7 @@ my $cfC = RT::CustomField->new($RT::SystemUser); ($ret, $msg) = $cfO->Create( Name => 'Order', Queue => 0, SortOrder => 1, - Description => q[Something to compare results for, since we can't guarantee ticket ID], + Description => q{Something to compare results for, since we can't guarantee ticket ID}, Type=> 'FreeformSingle'); ok($ret, "Custom Field Order created"); @@ -86,7 +90,8 @@ sub check_order { } my $results = join (" ",@results); my $order = join(" ",@order); - is( $results, $order , "Ordered correctly: $order"); + @_ = ($results, $order , "Ordered correctly: $order"); + goto \&is; } # The real tests start here @@ -110,10 +115,18 @@ check_order( $tx, 2, 1); # in Tickets_Overlay. $tx = new RT::Tickets( $RT::SystemUser ); $tx->FromSQL(qq[queue="$queue"] ); -$tx->OrderBy( FIELD => "CF.{Charlie}", ORDER => 'DES' ); +$tx->OrderBy( FIELD => "CF.{Charlie}", ORDER => 'DESC' ); +diag $tx->BuildSelectQuery; is($tx->Count,2); check_order( $tx, 1, 2); +$tx = new RT::Tickets( $RT::SystemUser ); +$tx->FromSQL(qq[queue="$queue"] ); +$tx->OrderBy( FIELD => "CF.{Charlie}", ORDER => 'ASC' ); +diag $tx->BuildSelectQuery; +is($tx->Count,2); +check_order( $tx, 2, 1); + # Add a new ticket, to test sorting on multiple columns. my $t3 = RT::Ticket->new($RT::SystemUser); $t3->Create( Queue => $queue_obj->Id, @@ -126,18 +139,39 @@ $t3->AddCustomFieldValue(Field => $cfC->Id, Value => 'AAA'); $tx = new RT::Tickets( $RT::SystemUser ); $tx->FromSQL(qq[queue="$queue"] ); -$tx->OrderByCols({FIELD => "CF.${queue}.{Charlie}", ORDER => 'ASC'}, - {FIELD => "CF.${queue}.{Alpha}", ORDER => 'DES'} - ); +$tx->OrderByCols( + { FIELD => "CF.${queue}.{Charlie}", ORDER => 'ASC' }, + { FIELD => "CF.${queue}.{Alpha}", ORDER => 'DES' }, +); is($tx->Count,3); check_order( $tx, 3, 2, 1); +$tx = new RT::Tickets( $RT::SystemUser ); +$tx->FromSQL(qq[queue="$queue"] ); +$tx->OrderByCols( + { FIELD => "CF.${queue}.{Charlie}", ORDER => 'DES' }, + { FIELD => "CF.${queue}.{Alpha}", ORDER => 'ASC' }, +); +is($tx->Count,3); +check_order( $tx, 1, 2, 3); + # Reverse the order of the secondary column, which changes the order # of the first two tickets. $tx = new RT::Tickets( $RT::SystemUser ); $tx->FromSQL(qq[queue="$queue"] ); -$tx->OrderByCols({FIELD => "CF.${queue}.{Charlie}", ORDER => 'ASC'}, - {FIELD => "CF.${queue}.{Alpha}", ORDER => 'ASC'} - ); +$tx->OrderByCols( + { FIELD => "CF.${queue}.{Charlie}", ORDER => 'ASC' }, + { FIELD => "CF.${queue}.{Alpha}", ORDER => 'ASC' }, +); is($tx->Count,3); check_order( $tx, 2, 3, 1); + +$tx = new RT::Tickets( $RT::SystemUser ); +$tx->FromSQL(qq[queue="$queue"] ); +$tx->OrderByCols( + { FIELD => "CF.${queue}.{Charlie}", ORDER => 'DES' }, + { FIELD => "CF.${queue}.{Alpha}", ORDER => 'DES' }, +); +is($tx->Count,3); +check_order( $tx, 1, 3, 2); +