public function GroupContentOperationAccessAlterTest::testGroupContentEntityOperationAccessAlterHook in Organic groups 8
Tests that modules can alter group content entity operation access.
This mimicks a use case where a moderator has access to edit and delete comments in all groups.
@dataProvider groupContentEntityOperationAccessAlterHookTestProvider
See also
\og_test_og_user_access_entity_operation_alter()
File
- tests/
src/ Kernel/ Access/ GroupContentOperationAccessAlterTest.php, line 140
Class
- GroupContentOperationAccessAlterTest
- Test that access to group content operations can be altered.
Namespace
Drupal\Tests\og\Kernel\AccessCode
public function testGroupContentEntityOperationAccessAlterHook(string $operation) : void {
// Check that our test user doesn't have access to edit or delete comments
// in the group.
// This is the default behavior for users that are not a group member.
$this
->assertFalse($this
->userHasAccess($operation));
// Now enable our hook which will alter the group content entity operation
// access rules to allow moderators to edit and delete comments in all
// groups. Since our user is a moderator they should now have access.
\Drupal::state()
->set('og_test_group_content_entity_operation_access_alter', TRUE);
$this
->assertTrue($this
->userHasAccess($operation));
}