diff options
author | sunnavy <sunnavy@bestpractical.com> | 2022-02-14 22:57:43 +0300 |
---|---|---|
committer | sunnavy <sunnavy@bestpractical.com> | 2022-08-03 01:47:31 +0300 |
commit | 546cf507859a0f19083d838a4eb821cf3e2ba118 (patch) | |
tree | 3ea281793fb3df14b7832935ea188fb24331bfa7 | |
parent | c01645ec2f3b0c6024b89602612194fb84f640fe (diff) |
Test searching/sorting cf values numerically5.0/cf-numeric-comparison
-rw-r--r-- | t/ticket/search_by_cf_numeric.t | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/t/ticket/search_by_cf_numeric.t b/t/ticket/search_by_cf_numeric.t new file mode 100644 index 0000000000..edc73767a7 --- /dev/null +++ b/t/ticket/search_by_cf_numeric.t @@ -0,0 +1,55 @@ + +use strict; +use warnings; + +use RT::Test nodata => 1, tests => undef; + +{ + no warnings 'redefine'; + use RT::CustomField; + *RT::CustomField::IsNumeric = sub { 1 } +} + +my $queue = RT::Test->load_or_create_queue( Name => 'General' ); +my $cf = RT::Test->load_or_create_custom_field( Name => 'test_cf', Queue => $queue->id, Type => 'FreeformSingle' ); +my $cfid = $cf->id; + +my $cf2 = RT::Test->load_or_create_custom_field( Name => 'test_cf2', Queue => $queue->id, Type => 'FreeformSingle' ); +my $cf2id = $cf2->id; + +my @tickets = RT::Test->create_tickets( + { Queue => $queue->Name }, + { Subject => 'Big', "CustomField-$cfid" => 12, "CustomField-$cf2id" => 5 }, + { Subject => 'Small', "CustomField-$cfid" => 3, "CustomField-$cf2id" => 10 }, +); + +my $tickets = RT::Tickets->new( RT->SystemUser ); +$tickets->FromSQL(q{Queue = 'General' AND CF.test_cf > 5 }); +is( $tickets->Count, 1, 'Found 1 ticket' ); +is( $tickets->First->id, $tickets[0]->id, 'Found the big ticket' ); + +$tickets->FromSQL(q{Queue = 'General' AND CF.test_cf = 12 }); +is( $tickets->Count, 1, 'Found 1 ticket' ); +is( $tickets->First->id, $tickets[0]->id, 'Found the big ticket' ); + +$tickets->FromSQL(q{Queue = 'General' AND CF.test_cf < 5}); +is( $tickets->Count, 1, 'Found 1 ticket' ); +is( $tickets->First->id, $tickets[1]->id, 'Found the small ticket' ); + +$tickets->FromSQL(q{Queue = 'General' AND CF.test_cf = 3}); +is( $tickets->Count, 1, 'Found 1 ticket' ); +is( $tickets->First->id, $tickets[1]->id, 'Found the small ticket' ); + +$tickets->FromSQL(q{Queue = 'General' AND CF.test_cf < CF.test_cf2 }); +is( $tickets->Count, 1, 'Found 1 ticket' ); +is( $tickets->First->id, $tickets[1]->id, 'Found the small ticket' ); + +$tickets->FromSQL(q{Queue = 'General'}); +is( $tickets->Count, 2, 'Found 2 tickets' ); +$tickets->OrderByCols( { FIELD => 'CustomField.test_cf' } ); +is( $tickets->First->id, $tickets[1]->id, 'Small ticket first' ); + +$tickets->OrderByCols( { FIELD => 'CustomField.test_cf', ORDER => 'DESC' } ); +is( $tickets->First->id, $tickets[0]->id, 'Big ticket first' ); + +done_testing; |