BlockHtmlTest.php in Drupal 10
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 {
protected static $modules = [
'block',
'block_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
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', [
'id' => 'test_menu_block',
]);
}
public function testHtml() {
$this
->drupalGet('');
$this
->assertSession()
->elementExists('xpath', '//div[@id="block-test-html-block" and @data-custom-attribute="foo"]');
$elements = $this
->xpath('//nav[@id="block-test-menu-block"]/ul/li');
$this
->assertNotEmpty($elements, 'The proper block markup was found.');
}
}