Namespace
Drupal\Tests\devel\Functional
File
-
tests/src/Functional/DevelLayoutInfoTest.php
View source
<?php
namespace Drupal\Tests\devel\Functional;
use PHPUnit\Framework\Attributes\Group;
class DevelLayoutInfoTest extends DevelBrowserTestBase {
protected static $modules = [
'devel',
'block',
'layout_discovery',
];
protected function setUp() : void {
parent::setUp();
$this->drupalPlaceBlock('page_title_block');
$this->drupalLogin($this->develUser);
}
public function testLayoutsInfoMenuLink() : void {
$this->drupalPlaceBlock('system_menu_block:devel');
$this->drupalGet('');
$this->clickLink('Layouts Info');
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->addressEquals('/devel/layouts');
$this->assertSession()
->pageTextContains('Layout');
}
public function testLayoutList() : void {
$this->drupalGet('/devel/layouts');
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->pageTextContains('Layouts');
$page = $this->getSession()
->getPage();
$table = $page->find('css', 'table.devel-layout-list');
$this->assertNotNull($table);
$headers = $table->findAll('css', 'thead th');
$this->assertEquals(6, count($headers));
$expected_headers = [
'Icon',
'Label',
'Description',
'Category',
'Regions',
'Provider',
];
$actual_headers = array_map(static fn($element) => $element->getText(), $headers);
$this->assertSame($expected_headers, $actual_headers);
$layout_manager = $this->container
->get('plugin.manager.core.layout');
$layouts = $layout_manager->getDefinitions();
$table_rows = $table->findAll('css', 'tbody tr');
$this->assertEquals(count($layouts), count($table_rows));
$index = 0;
foreach ($layouts as $layout) {
$cells = $table_rows[$index]->findAll('css', 'td');
$this->assertEquals(6, count($cells));
$cell_layout_icon = $cells[0];
$icon_path = $layout->getIconPath();
if ($icon_path === NULL || $icon_path === '') {
}
else {
$cell_layout_icon_text = $cell_layout_icon->getText();
$this->assertTrue($cell_layout_icon_text === '');
}
$cell_layout_label = $cells[1];
$this->assertEquals($cell_layout_label->getText(), $layout->getLabel());
$cell_layout_description = $cells[2];
$this->assertEquals($cell_layout_description->getText(), $layout->getDescription());
$cell_layout_category = $cells[3];
$this->assertEquals($cell_layout_category->getText(), $layout->getCategory());
$cell_layout_regions = $cells[4];
$this->assertEquals($cell_layout_regions->getText(), implode(', ', $layout->getRegionLabels()));
$cell_layout_provider = $cells[5];
$this->assertEquals($cell_layout_provider->getText(), $layout->getProvider());
++$index;
}
$this->drupalLogout();
$this->drupalGet('devel/layouts');
$this->assertSession()
->statusCodeEquals(403);
}
public function testLayoutDiscoveryDependency() : void {
$this->container
->get('module_installer')
->uninstall([
'layout_discovery',
]);
$this->drupalPlaceBlock('system_menu_block:devel');
$this->drupalGet('');
$this->assertSession()
->linkNotExists('Layouts Info');
$this->drupalGet('/devel/layouts');
$this->assertSession()
->statusCodeEquals(404);
$this->drupalGet('/devel/events');
$this->assertSession()
->statusCodeEquals(200);
$this->drupalGet('devel/routes');
$this->assertSession()
->statusCodeEquals(200);
$this->drupalGet('/devel/container/service');
$this->assertSession()
->statusCodeEquals(200);
}
}
Classes