Skip to content

Commit

Permalink
Test cascaded deletion of cached group members
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Apr 3, 2024
1 parent f22f1b1 commit 7b87e46
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions t/api/group.t
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,33 @@ diag "Ticket role group members";
ok( !$CGM->id, 'No CGM record for admincc <-> bob still' );
}


diag "Cascade delete cached group members";
{
my $test1 = RT::Test->load_or_create_group('cascade test 1');
my $test2 = RT::Test->load_or_create_group('cascade test 2');
my $test3 = RT::Test->load_or_create_group('cascade test 3');
my $user = RT::Test->load_or_create_user( Name => 'User 1' );

ok( $test3->AddMember( $user->PrincipalId ), 'Add User 1 to test 3' );
ok( $test2->AddMember( $test3->PrincipalId ), 'Add test 3 to test 2' );
ok( $test1->AddMember( $test2->PrincipalId ), 'Add test 2 to test 1' );

ok( $test1->HasMemberRecursively( $test2->PrincipalId ), "Group test 1 has test 2 recursively" );
ok( $test1->HasMemberRecursively( $test3->PrincipalId ), "Group test 1 has test 3 recursively" );
ok( $test1->HasMemberRecursively( $user->PrincipalId ), "Group test 1 has User 1 recursively" );

my $cgms = RT::CachedGroupMembers->new( RT->SystemUser );
$cgms->Limit( FIELD => 'GroupId', VALUE => $test1->Id );
is( $cgms->Count, 4, 'Group test has 4 CachedGroupMembers rows' );

ok( $test1->DeleteMember( $test2->PrincipalId ), 'Delete test 2 from test' );
$cgms->RedoSearch;
is( $cgms->Count, 1, 'Group test has 1 CachedGroupMembers row' );

ok( !$test1->HasMemberRecursively( $test2->PrincipalId ), "Group test 1 does not have test 2 recursively" );
ok( !$test1->HasMemberRecursively( $test3->PrincipalId ), "Group test 1 does not have test 3 recursively" );
ok( !$test1->HasMemberRecursively( $user->PrincipalId ), "Group test 1 does not have User 1 recursively" );
}

done_testing;

0 comments on commit 7b87e46

Please sign in to comment.