You are here

public function BlockTest::testBlockUserRoleDelete in Zircon Profile 8

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

Tests block_user_role_delete.

File

core/modules/block/src/Tests/BlockTest.php, line 469
Contains \Drupal\block\Tests\BlockTest.

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\block\Tests

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(),
  ]);
}