BlockListsRoutesAccessTest.php in Block permissions 8
File
tests/src/Functional/BlockListsRoutesAccessTest.php
View source
<?php
namespace Drupal\Tests\block_permissions\Functional;
use Drupal\Core\Url;
class BlockListsRoutesAccessTest extends BlockPermissionsBrowserTestBase {
protected $defaultThemeUser;
protected $secondThemeUser;
protected function setUp() : void {
parent::setUp();
$this->defaultThemeUser = $this
->drupalCreateUser([
'administer blocks',
"administer block settings for theme {$this->defaultTheme}",
]);
$this->secondThemeUser = $this
->drupalCreateUser([
'administer blocks',
"administer block settings for theme {$this->secondTheme}",
]);
}
public function testBlockListAccess() {
$block_admin_display_path = Url::fromRoute('block.admin_display');
$this
->drupalLogin($this->defaultThemeUser);
$this
->drupalGet($block_admin_display_path);
$this
->assertBlockListPageHasAccess();
$this
->drupalLogin($this->secondThemeUser);
$this
->drupalGet($block_admin_display_path);
$this
->assertSession()
->statusCodeEquals(403);
}
public function testBlockThemeListAccess() {
$this
->drupalLogin($this->defaultThemeUser);
$this
->drupalGet($this
->getBlockAdminDisplayThemeUrl($this->defaultTheme));
$this
->assertBlockListPageHasAccess();
$this
->drupalGet($this
->getBlockAdminDisplayThemeUrl($this->secondTheme));
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalLogin($this->secondThemeUser);
$this
->drupalGet($this
->getBlockAdminDisplayThemeUrl($this->defaultTheme));
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalGet($this
->getBlockAdminDisplayThemeUrl($this->secondTheme));
$this
->assertBlockListPageHasAccess();
}
protected function getBlockAdminDisplayThemeUrl($theme) {
return Url::fromRoute('block.admin_display_theme', [
'theme' => $theme,
]);
}
protected function assertBlockListPageHasAccess() {
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Block layout');
}
}