public function BlockTest::testBlockUserRoleDelete in Drupal 9
Same name and namespace in other branches
- 8 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 548
Class
- BlockTest
- Tests basic block functionality.
Namespace
Drupal\Tests\block\FunctionalCode
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
->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']);
}