BlockPermissionsBlockLibraryControllerTest.php in Block permissions 8
File
tests/src/Functional/BlockPermissionsBlockLibraryControllerTest.php
View source
<?php
namespace Drupal\Tests\block_permissions\Functional;
use Drupal\Core\Url;
class BlockPermissionsBlockLibraryControllerTest extends BlockPermissionsBrowserTestBase {
protected $coreBlocksUser;
protected $systemBlocksUser;
protected function setUp() : void {
parent::setUp();
$this->coreBlocksUser = $this
->drupalCreateUser([
'administer blocks',
'administer blocks provided by core',
"administer block settings for theme {$this->defaultTheme}",
]);
$this->systemBlocksUser = $this
->drupalCreateUser([
'administer blocks',
'administer blocks provided by system',
"administer block settings for theme {$this->secondTheme}",
]);
}
public function testListBlocks() {
$page_title_block_definition = \Drupal::service('plugin.manager.block')
->getDefinition('page_title_block');
$system_branding_block_definition = \Drupal::service('plugin.manager.block')
->getDefinition('system_branding_block');
$this
->drupalLogin($this->coreBlocksUser);
$this
->drupalGet($this
->getBlockAdminLibraryThemeUrl($this->defaultTheme));
$this
->assertBlockLibraryPageHasAccess();
$this
->assertSession()
->pageTextContains($page_title_block_definition['admin_label']);
$this
->assertSession()
->pageTextNotContains($system_branding_block_definition['admin_label']);
$this
->drupalGet($this
->getBlockAdminLibraryThemeUrl($this->secondTheme));
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalLogin($this->systemBlocksUser);
$this
->drupalGet($this
->getBlockAdminLibraryThemeUrl($this->defaultTheme));
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalGet($this
->getBlockAdminLibraryThemeUrl($this->secondTheme));
$this
->assertBlockLibraryPageHasAccess();
$this
->assertSession()
->pageTextNotContains($page_title_block_definition['admin_label']);
$this
->assertSession()
->pageTextContains($system_branding_block_definition['admin_label']);
}
protected function assertBlockLibraryPageHasAccess() {
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Place block');
}
protected function getBlockAdminLibraryThemeUrl($theme) {
return Url::fromRoute('block.admin_library', [
'theme' => $theme,
]);
}
}