You are here

public function BlockTest::testBlockVisibilityListedEmpty in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testBlockVisibilityListedEmpty()

Test block visibility when leaving "pages" textarea empty.

File

core/modules/block/tests/src/Functional/BlockTest.php, line 108

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\Tests\block\Functional

Code

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
    ->drupalPostForm('admin/structure/block/add/' . $block_name . '/' . $default_theme, $edit, t('Save block'));
  $this
    ->assertText('The block configuration has been saved.', 'Block was saved');
  $this
    ->drupalGet('user');
  $this
    ->assertNoText($title, 'Block was not displayed according to block visibility rules.');
  $this
    ->drupalGet('USER');
  $this
    ->assertNoText($title, 'Block was not displayed according to block visibility rules regardless of path case.');

  // Confirm that the block is not displayed to anonymous users.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('');
  $this
    ->assertNoText($title, 'Block was not displayed to anonymous users on the front page.');
}