public function PermissionEventTest::testPermissionEventIntegration in Organic groups 8
Tests that the two OG modules can provide their own OG permissions.
Some permissions (such as 'subscribe', 'manage members', etc.) are available for all group types. In addition to this there are also OG permissions for creating, editing and deleting the group content that associated with the group.
In this test we will check that the correct permissions are generated for our test group (which includes permissions to create, edit and delete group content of type 'test_group_content'), as well as a control group which doesn't have any group content - in this case it should only return the default permissions that are available to all group types.
@dataProvider permissionEventDataProvider
Parameters
array $group_content_bundle_ids: An array of group content bundle IDs that are associated with the test group.
array $expected_permissions: An array of permission names that are expected to be returned.
\Drupal\og\PermissionInterface[] $expected_full_permissions: An array of full permissions that are expected to be returned. This is a subset of the permissions. It is not necessary to test the full permission data for each entry, testing the data for only a couple of permissions is sufficient.
File
- tests/
src/ Kernel/ PermissionEventTest.php, line 93
Class
- PermissionEventTest
- Tests the implementations of the PermissionEvent in 'og' and 'og_ui'.
Namespace
Drupal\Tests\og\KernelCode
public function testPermissionEventIntegration(array $group_content_bundle_ids, array $expected_permissions, array $expected_full_permissions) {
// Retrieve the permissions from the listeners.
/** @var \Drupal\og\Event\PermissionEvent $permission_event */
$event = new PermissionEvent($this
->randomMachineName(), $this
->randomMachineName(), $group_content_bundle_ids);
$permission_event = $this->eventDispatcher
->dispatch(PermissionEventInterface::EVENT_NAME, $event);
$actual_permissions = array_keys($permission_event
->getPermissions());
// Sort the permission arrays so they can be compared.
sort($expected_permissions);
sort($actual_permissions);
$this
->assertEquals($expected_permissions, $actual_permissions);
// When testing the group content bundles, check that the bundle info has
// been correctly retrieved from the group content bundle that was created
// in the setUp() and used to create the permissions.
foreach ($expected_full_permissions as $permission) {
$this
->assertPermission($permission, $permission_event
->getPermission($permission
->getName()));
}
}