You are here

public function BlockTest::testBlockUserRoleDelete in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockUserRoleDelete()

Tests block_user_role_delete.

File

core/modules/block/tests/src/Functional/BlockTest.php, line 525

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\Tests\block\Functional

Code

public function testBlockUserRoleDelete() {
  $role1 = Role::create([
    'id' => 'test_role1',
    'name' => $this
      ->randomString(),
  ]);
  $role1
    ->save();
  $role2 = Role::create([
    'id' => 'test_role2',
    'name' => $this
      ->randomString(),
  ]);
  $role2
    ->save();
  $block = Block::create([
    'id' => $this
      ->randomMachineName(),
    'plugin' => 'system_powered_by_block',
  ]);
  $block
    ->setVisibilityConfig('user_role', [
    'roles' => [
      $role1
        ->id() => $role1
        ->id(),
      $role2
        ->id() => $role2
        ->id(),
    ],
  ]);
  $block
    ->save();
  $this
    ->assertEqual($block
    ->getVisibility()['user_role']['roles'], [
    $role1
      ->id() => $role1
      ->id(),
    $role2
      ->id() => $role2
      ->id(),
  ]);
  $role1
    ->delete();
  $block = Block::load($block
    ->id());
  $this
    ->assertEqual($block
    ->getVisibility()['user_role']['roles'], [
    $role2
      ->id() => $role2
      ->id(),
  ]);
}