You are here

public function EntityBrowserTest::testDynamicPermissions in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/Extension/EntityBrowserTest.php \Drupal\Tests\entity_browser\Kernel\Extension\EntityBrowserTest::testDynamicPermissions()

Tests dynamically generated permissions.

File

tests/src/Kernel/Extension/EntityBrowserTest.php, line 279

Class

EntityBrowserTest
Tests the entity_browser config entity.

Namespace

Drupal\Tests\entity_browser\Kernel\Extension

Code

public function testDynamicPermissions() {
  $this
    ->installConfig([
    'entity_browser_test',
  ]);
  $permissions = $this->container
    ->get('user.permissions')
    ->getPermissions();

  /** @var \Drupal\entity_browser\EntityBrowserInterface $entity */
  $entity = $this->controller
    ->load('test');
  $expected_permission_name = 'access ' . $entity
    ->id() . ' entity browser pages';
  $expected_permission = [
    'title' => $this->container
      ->get('string_translation')
      ->translate('Access @name pages', [
      '@name' => $entity
        ->label(),
    ])
      ->render(),
    'description' => $this->container
      ->get('string_translation')
      ->translate('Access pages that %browser uses to operate.', [
      '%browser' => $entity
        ->label(),
    ])
      ->render(),
    'provider' => 'entity_browser',
  ];
  $this
    ->assertSame($permissions[$expected_permission_name]['title']
    ->render(), $expected_permission['title'], 'Dynamically generated permission title found.');
  $this
    ->assertSame($permissions[$expected_permission_name]['description']
    ->render(), $expected_permission['description'], 'Dynamically generated permission description found.');
  $this
    ->assertSame($permissions[$expected_permission_name]['provider'], $expected_permission['provider'], 'Dynamically generated permission provider found.');
}