You are here

public function BlockHtmlTest::testHtml in Drupal 9

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

Tests for valid HTML for a block.

File

core/modules/block/tests/src/Functional/BlockHtmlTest.php, line 43

Class

BlockHtmlTest
Tests block HTML ID validity.

Namespace

Drupal\Tests\block\Functional

Code

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.
  $elements = $this
    ->xpath('//nav[contains(@class, :nav-class)]/ul[contains(@class, :ul-class)]/li', [
    ':nav-class' => 'block-menu',
    ':ul-class' => 'menu',
  ]);
  $this
    ->assertTrue(!empty($elements), 'The proper block markup was found.');
}