Chris@0: drupalLogin($this->rootUser); Chris@0: Chris@0: // Enable the test_html block, to test HTML ID and attributes. Chris@0: \Drupal::state()->set('block_test.attributes', ['data-custom-attribute' => 'foo']); Chris@0: \Drupal::state()->set('block_test.content', $this->randomMachineName()); Chris@0: $this->drupalPlaceBlock('test_html', ['id' => 'test_html_block']); Chris@0: Chris@0: // Enable a menu block, to test more complicated HTML. Chris@0: $this->drupalPlaceBlock('system_menu_block:admin'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests for valid HTML for a block. Chris@0: */ Chris@0: public function testHtml() { Chris@0: $this->drupalGet(''); Chris@0: Chris@0: // Ensure that a block's ID is converted to an HTML valid ID, and that Chris@0: // block-specific attributes are added to the same DOM element. Chris@0: $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.'); Chris@0: Chris@0: // Ensure expected markup for a menu block. Chris@0: $elements = $this->xpath('//nav[contains(@class, :nav-class)]/ul[contains(@class, :ul-class)]/li', [':nav-class' => 'block-menu', ':ul-class' => 'menu']); Chris@0: $this->assertTrue(!empty($elements), 'The proper block markup was found.'); Chris@0: } Chris@0: Chris@0: }