You are here

public function GroupContentPermissionProviderTest::testBuildPermissions in Group 8

Tests the permission builder.

@covers ::buildPermissions @dataProvider buildPermissionsProvider

Parameters

string $plugin_id: The plugin ID.

array $definition: The plugin definition.

bool $implements_owner: Whether the plugin's entity type deals with ownership.

bool $implements_published: Whether the plugin's entity type deals with publishing of entities.

File

tests/src/Unit/GroupContentPermissionProviderTest.php, line 577

Class

GroupContentPermissionProviderTest
Tests the default GroupContentEnabler permission_provider handler.

Namespace

Drupal\Tests\group\Unit

Code

public function testBuildPermissions($plugin_id, array $definition, $implements_owner, $implements_published) {
  $permission_provider = $this
    ->createPermissionProvider($plugin_id, $definition, $implements_owner, $implements_published);
  $permissions = $permission_provider
    ->buildPermissions();

  // Test the admin permission being restricted.
  if (!empty($definition['admin_permission'])) {
    $admin_permission = $permission_provider
      ->getAdminPermission();
    $this
      ->assertArrayHasKey($admin_permission, $permissions);
    $this
      ->assertArrayHasKey('restrict access', $permissions[$admin_permission]);
    $this
      ->assertTrue($permissions[$admin_permission]['restrict access']);
  }

  // We do not test all permissions here as they are thoroughly covered in
  // their dedicated getter test. Simply test that the labels of common
  // permissions are prefixed properly.
  if ($permission = $permission_provider
    ->getRelationViewPermission()) {
    $this
      ->assertArrayHasKey($permission, $permissions);
    $this
      ->assertStringStartsWith('Relation: ', $permissions[$permission]['title']);
  }
  if ($permission = $permission_provider
    ->getEntityViewPermission()) {
    $this
      ->assertArrayHasKey($permission, $permissions);
    $this
      ->assertStringStartsWith('Entity: ', $permissions[$permission]['title']);
  }
}