X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fblock%2Ftests%2Fsrc%2FFunctional%2FBlockHtmlTest.php;fp=web%2Fcore%2Fmodules%2Fblock%2Ftests%2Fsrc%2FFunctional%2FBlockHtmlTest.php;h=5f9afe916f7d15bfcc27700f3d041e2f39664205;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/block/tests/src/Functional/BlockHtmlTest.php b/web/core/modules/block/tests/src/Functional/BlockHtmlTest.php new file mode 100644 index 000000000..5f9afe916 --- /dev/null +++ b/web/core/modules/block/tests/src/Functional/BlockHtmlTest.php @@ -0,0 +1,50 @@ +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'); + } + + /** + * 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->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.'); + } + +}