function BlockTest::testBlockTitle

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

Tests block title.

File

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

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\Tests\block\Functional

Code

public function testBlockTitle() : void {
    // Create a custom title for the block.
    $title = "This block's <b>great!</b>";
    // Enable a standard block.
    $default_theme = $this->config('system.theme')
        ->get('default');
    $edit = [
        'id' => 'test',
        'region' => 'sidebar_first',
        'settings[label]' => $title,
        'settings[label_display]' => TRUE,
    ];
    // Set the block to be shown only to authenticated users.
    $edit['visibility[user_role][roles][' . RoleInterface::AUTHENTICATED_ID . ']'] = TRUE;
    $this->drupalGet('admin/structure/block/add/foo/' . $default_theme);
    $this->submitForm($edit, 'Save block');
    // Ensure that the title is displayed as plain text.
    $elements = $this->xpath('//table/tbody/tr//td[contains(@class, "block")]');
    $this->assertEquals($title, $elements[0]->getText());
    $this->clickLink('Disable');
    $elements = $this->xpath('//table/tbody/tr//td[contains(@class, "block")]');
    $this->assertEquals("{$title} (disabled)", $elements[0]->getText());
}

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