class BlockHtmlTest
Same name and namespace in other branches
- 11.x core/modules/block/tests/src/Functional/BlockHtmlTest.php \Drupal\Tests\block\Functional\BlockHtmlTest
- 10 core/modules/block/tests/src/Functional/BlockHtmlTest.php \Drupal\Tests\block\Functional\BlockHtmlTest
- 8.9.x core/modules/block/tests/src/Functional/BlockHtmlTest.php \Drupal\Tests\block\Functional\BlockHtmlTest
Tests block HTML ID validity.
@group block
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\block\Functional\BlockHtmlTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of BlockHtmlTest
File
-
core/
modules/ block/ tests/ src/ Functional/ BlockHtmlTest.php, line 12
Namespace
Drupal\Tests\block\FunctionalView source
class BlockHtmlTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'block',
'block_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->drupalLogin($this->rootUser);
// Enable the test_html block, to test HTML ID and attributes.
\Drupal::state()->set('block_test.attributes', [
'data-custom-attribute' => 'foo',
]);
\Drupal::state()->set('block_test.content', $this->randomMachineName());
$this->drupalPlaceBlock('test_html', [
'id' => 'test_html_block',
]);
// Enable a menu block, to test more complicated HTML.
$this->drupalPlaceBlock('system_menu_block:admin', [
'id' => 'test_menu_block',
]);
}
/**
* Tests for valid HTML for a block.
*/
public function testHtml() {
$this->drupalGet('');
// Ensure that a block's ID is converted to an HTML valid ID, and that
// block-specific attributes are added to the same DOM element.
$this->assertSession()
->elementExists('xpath', '//div[@id="block-test-html-block" and @data-custom-attribute="foo"]');
// Ensure expected markup for a menu block.
$this->assertSession()
->elementExists('xpath', '//nav[@id="block-test-menu-block"]/ul/li');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.