comparison core/modules/block/tests/src/Functional/BlockHtmlTest.php @ 0:4c8ae668cc8c

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