function BlockTest::testBlockVisibilityListedEmpty

Test block visibility when using "pages" restriction but leaving "pages" textarea empty

File

drupal/core/modules/block/lib/Drupal/block/Tests/BlockTest.php, line 69
Contains \Drupal\block\Tests\BlockTest.

Class

BlockTest
Provides testing for basic block module functionality.

Namespace

Drupal\block\Tests

Code

function testBlockVisibilityListedEmpty() {
  $block_name = 'system_powered_by_block';

  // Create a random title for the block.
  $title = $this
    ->randomName(8);

  // Enable a standard block.
  $default_theme = config('system.theme')
    ->get('default');
  $edit = array(
    'machine_name' => strtolower($this
      ->randomName(8)),
    'region' => 'sidebar_first',
    'settings[label]' => $title,
    'visibility[path][visibility]' => BLOCK_VISIBILITY_LISTED,
  );

  // Set the block to be hidden on any user path, and to be shown only to
  // authenticated users.
  $this
    ->drupalPost('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.');
}