You are here

function BlockTest::testBlockVisibilityListedEmpty in Zircon Profile 8

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

Test block visibility when leaving "pages" textarea empty.

File

core/modules/block/src/Tests/BlockTest.php, line 105
Contains \Drupal\block\Tests\BlockTest.

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\block\Tests

Code

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 = array(
    '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.');
}