BlockHtmlTest.php in Drupal 8
File
core/modules/block/tests/src/Functional/BlockHtmlTest.php
View source
<?php
namespace Drupal\Tests\block\Functional;
use Drupal\Tests\BrowserTestBase;
class BlockHtmlTest extends BrowserTestBase {
public static $modules = [
'block',
'block_test',
];
protected $defaultTheme = 'classy';
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this->rootUser);
\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',
]);
$this
->drupalPlaceBlock('system_menu_block:admin');
}
public function testHtml() {
$this
->drupalGet('');
$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.');
$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.');
}
}