Skip to content

Commit

Permalink
Test role member's "NULL" searches
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Oct 23, 2024
1 parent d137e6f commit ef8f9e4
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions t/api/tickets.t
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,29 @@ diag "Ticket role group member custom fields";
my $richard = RT::Test->load_or_create_user( Name => 'richard' );
ok( $richard->AddCustomFieldValue( Field => 'manager', Value => 'alice' ) );

my $root = RT::Test->load_or_create_user( Name => 'root' );

my $tickets = RT::Tickets->new( RT->SystemUser );

$tickets->FromSQL("Subject = 'test role member cfs' AND Owner.CustomField.{manager} = 'bob'");
ok( !$tickets->Count, 'No tickets found' );

$tickets->FromSQL("Subject = 'test role member cfs' AND Owner.CustomField.{manager} IS NOT NULL");
ok( !$tickets->Count, 'No tickets found' );

$tickets->FromSQL("Subject = 'test role member cfs' AND Owner.CustomField.{manager} IS NULL");
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

( $ret, $msg ) = $ticket->SetOwner('root');
ok( $ret, $msg );
$tickets->FromSQL("Subject = 'test role member cfs' AND Owner.CustomField.{manager} IS NULL");
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

$tickets->FromSQL("Subject = 'test role member cfs' AND Owner.CustomField.{manager} IS NOT NULL");
ok( !$tickets->Count, 'No tickets found' );

$alice->PrincipalObj->GrantRight( Right => 'OwnTicket' );
( $ret, $msg ) = $ticket->SetOwner('alice');
ok( $ret, $msg );
Expand All @@ -425,6 +443,20 @@ diag "Ticket role group member custom fields";
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

$tickets->FromSQL("Subject = 'test role member cfs' AND Owner.CustomField.{manager} IS NOT NULL");
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

$tickets->FromSQL("Subject = 'test role member cfs' AND Requestor IS NULL");
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

$tickets->FromSQL("Subject = 'test role member cfs' AND Requestor.CustomField.manager IS NULL");
ok( !$tickets->Count, 'No tickets found' );

$tickets->FromSQL("Subject = 'test role member cfs' AND Requestor.CustomField.manager IS NOT NULL");
ok( !$tickets->Count, 'No tickets found' );

$tickets->FromSQL("Subject = 'test role member cfs' AND Requestor.CustomField.manager = 'alice'");
ok( !$tickets->Count, 'No tickets found' );

Expand All @@ -435,6 +467,34 @@ diag "Ticket role group member custom fields";
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

$tickets->FromSQL("Subject = 'test role member cfs' AND Requestor.CustomField.manager IS NOT NULL");
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

$tickets->FromSQL("Subject = 'test role member cfs' AND Requestor.CustomField.manager IS NULL");
ok( !$tickets->Count, 'No tickets found' );

( $ret, $msg ) = $ticket->RoleGroup('Requestor')->AddMember( $root->Id );
ok( $ret, $msg );

$tickets->FromSQL("Subject = 'test role member cfs' AND Requestor.CustomField.manager IS NULL");
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

$tickets->FromSQL("Subject = 'test role member cfs' AND Requestor.CustomField.manager IS NOT NULL");
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

$tickets->FromSQL("Subject = 'test role member cfs' AND CustomRole.{Engineer}.Name IS NULL");
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

$tickets->FromSQL("Subject = 'test role member cfs' AND CustomRole.{Engineer}.CustomField.manager IS NULL");
ok( !$tickets->Count, 'No tickets found' );

$tickets->FromSQL("Subject = 'test role member cfs' AND CustomRole.{Engineer}.CustomField.manager IS NOT NULL");
ok( !$tickets->Count, 'No tickets found' );

$tickets->FromSQL("Subject = 'test role member cfs' AND CustomRole.{Engineer}.CustomField.{manager} = 'root'");
ok( !$tickets->Count, 'No tickets found' );

Expand All @@ -450,6 +510,25 @@ diag "Ticket role group member custom fields";
$tickets->FromSQL("Subject = 'test role member cfs' AND CustomRole.{Engineer}.CustomField.{manager} = 'root'");
ok( !$tickets->Count, 'No tickets found' );

$tickets->FromSQL("Subject = 'test role member cfs' AND CustomRole.{Engineer}.CustomField.manager IS NOT NULL");
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

$tickets->FromSQL("Subject = 'test role member cfs' AND CustomRole.{Engineer}.CustomField.manager IS NULL");
ok( !$tickets->Count, 'No tickets found' );

( $ret, $msg ) = $ticket->RoleGroup( $cr->GroupType )->AddMember( $root->Id );
ok( $ret, $msg );

$tickets->FromSQL("Subject = 'test role member cfs' AND CustomRole.{Engineer}.CustomField.manager IS NOT NULL");
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );

$tickets->FromSQL("Subject = 'test role member cfs' AND CustomRole.{Engineer}.CustomField.manager IS NULL");
is( $tickets->Count, 1, 'Found 1 ticket' );
is( $tickets->First->id, $ticket->id, 'Found the ticket' );


$alice->PrincipalObj->GrantRight( Right => 'ShowTicket' );
my $alice_current_user = RT::CurrentUser->new( RT->SystemUser );
$alice_current_user->Load( $alice->Id );
Expand Down

0 comments on commit ef8f9e4

Please sign in to comment.