function BlockHtmlTest::testHtml

Same name in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockHtmlTest.php \Drupal\Tests\block\Functional\BlockHtmlTest::testHtml()
  2. 10 core/modules/block/tests/src/Functional/BlockHtmlTest.php \Drupal\Tests\block\Functional\BlockHtmlTest::testHtml()
  3. 11.x 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.');
}

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