BlockListElementsTest.php in Block permissions 8
File
tests/src/Functional/BlockListElementsTest.php
View source
<?php
namespace Drupal\Tests\block_permissions\Functional;
use Drupal\Core\Url;
class BlockListElementsTest extends BlockPermissionsBrowserTestBase {
protected $coreBlocksUser;
protected $systemBlocksUser;
protected function setUp() : void {
parent::setUp();
$this->coreBlocksUser = $this
->drupalCreateUser([
'administer blocks',
"administer block settings for theme {$this->defaultTheme}",
'administer blocks provided by core',
]);
$this->systemBlocksUser = $this
->drupalCreateUser([
'administer blocks',
"administer block settings for theme {$this->defaultTheme}",
'administer blocks provided by system',
]);
}
public function testBlockListPage() {
$block_admin_display_path = Url::fromRoute('block.admin_display');
$this
->drupalLogin($this->coreBlocksUser);
$this
->drupalGet($block_admin_display_path);
$this
->assertSession()
->pageTextContains($this->pageTitleBlock
->label());
$this
->assertSession()
->pageTextContains($this->systemBrandingBlock
->label());
$this
->assertBlockElementsExists($this->pageTitleBlock
->id());
$this
->assertBlockElementsNotExists($this->systemBrandingBlock
->id());
$this
->drupalLogin($this->systemBlocksUser);
$this
->drupalGet($block_admin_display_path);
$this
->assertSession()
->pageTextContains($this->pageTitleBlock
->label());
$this
->assertSession()
->pageTextContains($this->systemBrandingBlock
->label());
$this
->assertBlockElementsNotExists($this->pageTitleBlock
->id());
$this
->assertBlockElementsExists($this->systemBrandingBlock
->id());
}
protected function assertBlockElementsExists($id) {
$row = $this
->assertSession()
->elementExists('css', "tr[data-drupal-selector=\"edit-blocks-{$id}\"]");
$this
->assertSession()
->elementExists('css', 'ul.dropbutton', $row);
$this
->assertSession()
->elementExists('css', 'select.block-weight', $row);
$this
->assertSession()
->elementExists('css', 'select.block-region-select', $row);
$this
->assertStringContainsString('draggable', $row
->getAttribute('class'));
}
protected function assertBlockElementsNotExists($id) {
$row = $this
->assertSession()
->elementExists('css', "tr[data-drupal-selector=\"edit-blocks-{$id}\"]");
$this
->assertSession()
->elementNotExists('css', 'ul.dropbutton', $row);
$this
->assertSession()
->elementNotExists('css', 'select.block-weight', $row);
$this
->assertSession()
->elementNotExists('css', 'select.block-region-select', $row);
$this
->assertStringContainsString('undraggable', $row
->getAttribute('class'));
}
}