function BlockTest::testBlockVisibilityListedEmpty

Same name and namespace in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockVisibilityListedEmpty()
  2. 8.9.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockVisibilityListedEmpty()
  3. 10 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 125

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\Tests\block\Functional

Code

public function testBlockVisibilityListedEmpty() : void {
  $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' => $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.