You are here

public function PermissionEventTest::testGetGroupContentOperationPermission in Organic groups 8

Tests getting a single group content permission.

@covers ::getGroupContentOperationPermission

@dataProvider groupContentOperationPermissionsProvider

Parameters

\Drupal\og\GroupContentOperationPermission[] $permissions: An array of test permissions.

string $entity_type_id: The entity type ID of the group type to which the permissions apply.

string $bundle_id: The bundle ID of the group type to which the permissions apply.

array $group_content_bundle_ids: An array of group content bundle IDs to which the permissions apply, keyed by group content entity type ID.

File

tests/src/Unit/PermissionEventTest.php, line 79

Class

PermissionEventTest
Tests permission events.

Namespace

Drupal\Tests\og\Unit

Code

public function testGetGroupContentOperationPermission(array $permissions, $entity_type_id, $bundle_id, array $group_content_bundle_ids) {
  $event = new PermissionEvent($entity_type_id, $bundle_id, $group_content_bundle_ids);

  // An exception should be thrown if the permission doesn't exist yet.
  foreach ($permissions as $permission) {
    try {
      $event
        ->getGroupContentOperationPermission($permission
        ->getEntityType(), $permission
        ->getBundle(), $permission
        ->getOperation(), $permission
        ->getOwner());
      $this
        ->fail('Calling ::getGroupContentOperationPermission() on a non-existing permission throws an exception.');
    } catch (\InvalidArgumentException $e) {

      // Expected result.
    }
  }

  // Test that the permissions can be retrieved once they are set.
  $event
    ->setPermissions($permissions);
  foreach ($permissions as $permission) {
    $this
      ->assertEquals($permission, $event
      ->getGroupContentOperationPermission($permission
      ->getEntityType(), $permission
      ->getBundle(), $permission
      ->getOperation(), $permission
      ->getOwner()));
  }
}