You are here

public function BlockTest::testHideBlockTitle in Drupal 9

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

Tests block title display settings.

File

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

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\Tests\block\Functional

Code

public function testHideBlockTitle() {
  $block_name = 'system_powered_by_block';

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

  // Enable a standard block.
  $default_theme = $this
    ->config('system.theme')
    ->get('default');
  $edit = [
    'id' => $id,
    'region' => 'sidebar_first',
    'settings[label]' => $title,
  ];
  $this
    ->drupalGet('admin/structure/block/add/' . $block_name . '/' . $default_theme);
  $this
    ->submitForm($edit, 'Save block');
  $this
    ->assertSession()
    ->pageTextContains('The block configuration has been saved.');

  // Confirm that the block is not displayed by default.
  $this
    ->drupalGet('user');
  $this
    ->assertSession()
    ->pageTextNotContains($title);
  $edit = [
    'settings[label_display]' => TRUE,
  ];
  $this
    ->drupalGet('admin/structure/block/manage/' . $id);
  $this
    ->submitForm($edit, 'Save block');
  $this
    ->assertSession()
    ->pageTextContains('The block configuration has been saved.');
  $this
    ->drupalGet('admin/structure/block/manage/' . $id);
  $this
    ->assertSession()
    ->checkboxChecked('edit-settings-label-display');

  // Confirm that the block is displayed when enabled.
  $this
    ->drupalGet('user');
  $this
    ->assertSession()
    ->pageTextContains($title);
}