function BlockTest::testBlockVisibilityListedEmpty
Same name in other branches
- 8.9.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockVisibilityListedEmpty()
- 10 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockVisibilityListedEmpty()
- 11.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockVisibilityListedEmpty()
Tests block visibility when leaving "pages" textarea empty.
File
-
core/
modules/ block/ tests/ src/ Functional/ BlockTest.php, line 111
Class
- BlockTest
- Tests basic block functionality.
Namespace
Drupal\Tests\block\FunctionalCode
public function testBlockVisibilityListedEmpty() {
$block_name = 'system_powered_by_block';
// Create a random title for the block.
$title = $this->randomMachineName(8);
// Enable a standard block.
$default_theme = $this->config('system.theme')
->get('default');
$edit = [
'id' => strtolower($this->randomMachineName(8)),
'region' => 'sidebar_first',
'settings[label]' => $title,
'visibility[request_path][negate]' => TRUE,
];
// Set the block to be hidden on any user path, and to be shown only to
// authenticated users.
$this->drupalGet('admin/structure/block/add/' . $block_name . '/' . $default_theme);
$this->submitForm($edit, 'Save block');
$this->assertSession()
->statusMessageContains('The block configuration has been saved.', 'status');
// Confirm that block was not displayed according to block visibility
// rules.
$this->drupalGet('user');
$this->assertSession()
->pageTextNotContains($title);
// Confirm that block was not displayed according to block visibility
// rules regardless of path case.
$this->drupalGet('USER');
$this->assertSession()
->pageTextNotContains($title);
// Confirm that the block is not displayed to anonymous users.
$this->drupalLogout();
$this->drupalGet('');
$this->assertSession()
->pageTextNotContains($title);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.