
| Current Path : /var/www/html/pallets_old/web/core/modules/block/tests/src/Functional/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/pallets_old/web/core/modules/block/tests/src/Functional/BlockHtmlTest.php |
<?php
namespace Drupal\Tests\block\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests block HTML ID validity.
*
* @group block
*/
class BlockHtmlTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = ['block', 'block_test'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
protected function setUp(): void {
parent::setUp();
$this->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', ['id' => 'test_menu_block']);
}
/**
* 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->assertSession()->elementExists('xpath', '//div[@id="block-test-html-block" and @data-custom-attribute="foo"]');
// Ensure expected markup for a menu block.
$elements = $this->xpath('//nav[@id="block-test-menu-block"]/ul/li');
$this->assertNotEmpty($elements, 'The proper block markup was found.');
}
}