annotate core/modules/block/tests/src/Functional/BlockHtmlTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\block\Functional;
Chris@0 4
Chris@0 5 use Drupal\Tests\BrowserTestBase;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Tests block HTML ID validity.
Chris@0 9 *
Chris@0 10 * @group block
Chris@0 11 */
Chris@0 12 class BlockHtmlTest extends BrowserTestBase {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Modules to install.
Chris@0 16 *
Chris@0 17 * @var array
Chris@0 18 */
Chris@0 19 public static $modules = ['block', 'block_test'];
Chris@0 20
Chris@0 21 protected function setUp() {
Chris@0 22 parent::setUp();
Chris@0 23
Chris@0 24 $this->drupalLogin($this->rootUser);
Chris@0 25
Chris@0 26 // Enable the test_html block, to test HTML ID and attributes.
Chris@0 27 \Drupal::state()->set('block_test.attributes', ['data-custom-attribute' => 'foo']);
Chris@0 28 \Drupal::state()->set('block_test.content', $this->randomMachineName());
Chris@0 29 $this->drupalPlaceBlock('test_html', ['id' => 'test_html_block']);
Chris@0 30
Chris@0 31 // Enable a menu block, to test more complicated HTML.
Chris@0 32 $this->drupalPlaceBlock('system_menu_block:admin');
Chris@0 33 }
Chris@0 34
Chris@0 35 /**
Chris@0 36 * Tests for valid HTML for a block.
Chris@0 37 */
Chris@0 38 public function testHtml() {
Chris@0 39 $this->drupalGet('');
Chris@0 40
Chris@0 41 // Ensure that a block's ID is converted to an HTML valid ID, and that
Chris@0 42 // block-specific attributes are added to the same DOM element.
Chris@0 43 $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 44
Chris@0 45 // Ensure expected markup for a menu block.
Chris@0 46 $elements = $this->xpath('//nav[contains(@class, :nav-class)]/ul[contains(@class, :ul-class)]/li', [':nav-class' => 'block-menu', ':ul-class' => 'menu']);
Chris@0 47 $this->assertTrue(!empty($elements), 'The proper block markup was found.');
Chris@0 48 }
Chris@0 49
Chris@0 50 }