Skip to content

Commit

Permalink
Test searching/sorting cf values numerically
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Oct 11, 2023
1 parent b8e1433 commit 01bbe3e
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions t/ticket/search_by_cf_numeric.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

use strict;
use warnings;

use RT::Test nodata => 1, tests => undef;

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' );
ok( $cf->SetNumericValues(1) );
my $cfid = $cf->id;

my $cf2 = RT::Test->load_or_create_custom_field( Name => 'test_cf2', Queue => $queue->id, Type => 'FreeformSingle' );
ok( $cf2->SetNumericValues(1) );
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;

0 comments on commit 01bbe3e

Please sign in to comment.