function BlockContentPermissionsTest::testDynamicPermissions

Same name and namespace in other branches
  1. 11.x core/modules/block_content/tests/src/Kernel/BlockContentPermissionsTest.php \Drupal\Tests\block_content\Kernel\BlockContentPermissionsTest::testDynamicPermissions()

@covers ::blockTypePermissions

File

core/modules/block_content/tests/src/Kernel/BlockContentPermissionsTest.php, line 51

Class

BlockContentPermissionsTest
Tests the permissions of content blocks.

Namespace

Drupal\Tests\block_content\Kernel

Code

public function testDynamicPermissions() : void {
  $permissions = $this->permissionHandler
    ->getPermissions();
  $this->assertArrayNotHasKey('edit any basic block content', $permissions, 'The per-block-type permission does not exist.');
  $this->assertArrayNotHasKey('edit any square block content', $permissions, 'The per-block-type permission does not exist.');
  // Create a basic block content type.
  BlockContentType::create([
    'id' => 'basic',
    'label' => 'A basic block type',
    'description' => 'Provides a basic block type',
  ])->save();
  // Create a square block content type.
  BlockContentType::create([
    'id' => 'square',
    'label' => 'A square block type',
    'description' => 'Provides a block type that is square',
  ])->save();
  $permissions = $this->permissionHandler
    ->getPermissions();
  // Assert the basic permission has been created.
  $this->assertArrayHasKey('edit any basic block content', $permissions, 'The per-block-type permission exists.');
  $this->assertEquals('<em class="placeholder">A basic block type</em>: Edit content block', $permissions['edit any basic block content']['title']->render());
  // Assert the square permission has been created.
  $this->assertArrayHasKey('edit any square block content', $permissions, 'The per-block-type permission exists.');
  $this->assertEquals('<em class="placeholder">A square block type</em>: Edit content block', $permissions['edit any square block content']['title']->render());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.