function BlockTest::testHideBlockTitle

Same name in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testHideBlockTitle()
  2. 10 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testHideBlockTitle()
  3. 11.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testHideBlockTitle()

Test block title display settings.

File

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

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->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 title was not displayed by default.');
    $edit = [
        'settings[label_display]' => TRUE,
    ];
    $this->drupalPostForm('admin/structure/block/manage/' . $id, $edit, t('Save block'));
    $this->assertText('The block configuration has been saved.', 'Block was saved');
    $this->drupalGet('admin/structure/block/manage/' . $id);
    $this->assertFieldChecked('edit-settings-label-display', 'The display_block option has the correct default value on the configuration form.');
    $this->drupalGet('user');
    $this->assertText($title, 'Block title was displayed when enabled.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.