You are here

public function UrlAliasPermissionsTest::testPermissions in URL Alias Permissions 8

Test the permissions created by UrlAliasPermPermissions.

@covers ::urlAliasPermissions

File

tests/src/Kernel/UrlAliasPermissionsTest.php, line 99

Class

UrlAliasPermissionsTest
Tests the UrlAliasPermPermissions class.

Namespace

Drupal\Tests\url_alias_permissions\Kernel

Code

public function testPermissions() {
  $this
    ->createContentType([
    'type' => 'bar',
  ]);
  $this
    ->createContentType([
    'type' => 'foo',
  ]);
  $this
    ->assertEquals([
    // Make sure permissions for nodes are created.
    'edit bar node url alias',
    'edit foo node url alias',
    // Make sure permissions are created for entities that don't support
    // bundles.
    'edit entity_test url alias',
  ], array_keys($this->urlAliasPermPermissions
    ->urlAliasPermissions()));
  $this
    ->createContentType([
    'type' => 'test',
  ]);
  $this
    ->assertEquals([
    'edit bar node url alias',
    'edit foo node url alias',
    'edit test node url alias',
    'edit entity_test url alias',
  ], array_keys($this->urlAliasPermPermissions
    ->urlAliasPermissions()));
  $node_type = $this->nodeTypeStorage
    ->load('test');
  $node_type
    ->delete();
  $this
    ->assertEquals([
    'edit bar node url alias',
    'edit foo node url alias',
    'edit entity_test url alias',
  ], array_keys($this->urlAliasPermPermissions
    ->urlAliasPermissions()));

  // Make sure permissions for taxonomies are also created.
  $vocabulary = $this
    ->createVocabulary();
  $this
    ->assertEquals([
    'edit bar node url alias',
    'edit foo node url alias',
    'edit entity_test url alias',
    'edit ' . $vocabulary
      ->id() . ' taxonomy_term url alias',
  ], array_keys($this->urlAliasPermPermissions
    ->urlAliasPermissions()));
}