You are here

public function BlockHtmlTest::testHtml in Drupal 8

Same name and namespace in other branches
  1. 9 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
    ->assertFieldByXPath('//div[@id="block-test-html-block" and @data-custom-attribute="foo"]', NULL, 'HTML ID and attributes for test block are valid and on the same DOM element.');

  // 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.');
}