function BlockTest::testBlockUserRoleDelete

Same name in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockUserRoleDelete()
  2. 8.9.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockUserRoleDelete()
  3. 10 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 587

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\Tests\block\Functional

Code

public function testBlockUserRoleDelete() : void {
    $role1 = Role::create([
        'id' => 'test_role1',
        'label' => 'Test role 1',
    ]);
    $role1->save();
    $role2 = Role::create([
        'id' => 'test_role2',
        'label' => 'Test role 2',
    ]);
    $role2->save();
    $block = Block::create([
        'id' => $this->randomMachineName(),
        'plugin' => 'system_powered_by_block',
        'theme' => 'stark',
    ]);
    $block->setVisibilityConfig('user_role', [
        'roles' => [
            $role1->id() => $role1->id(),
            $role2->id() => $role2->id(),
        ],
    ]);
    $block->save();
    $this->assertEquals([
        $role1->id() => $role1->id(),
        $role2->id() => $role2->id(),
    ], $block->getVisibility()['user_role']['roles']);
    $role1->delete();
    $block = Block::load($block->id());
    $this->assertEquals([
        $role2->id() => $role2->id(),
    ], $block->getVisibility()['user_role']['roles']);
}

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