BlockDemoTest.php in Drupal 10
File
core/modules/block/tests/src/Functional/BlockDemoTest.php
View source
<?php
namespace Drupal\Tests\block\Functional;
use Drupal\Tests\BrowserTestBase;
class BlockDemoTest extends BrowserTestBase {
protected static $modules = [
'block',
];
protected $defaultTheme = 'stark';
public function testBlockDemo() {
$admin_user = $this
->drupalCreateUser([
'administer blocks',
'administer themes',
]);
$this
->drupalLogin($admin_user);
$config = $this->container
->get('config.factory')
->get('system.theme');
$default_theme = $config
->get('default');
$this
->drupalGet('admin/structure/block/demo/' . $default_theme);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->linkByHrefExists('admin/structure/block');
$this
->assertSession()
->linkByHrefNotExists('admin/structure/block/list/' . $default_theme);
$available_themes = [
'olivero',
'claro',
'stark',
];
$themes = array_diff($available_themes, [
$default_theme,
]);
foreach ($themes as $theme) {
$this->container
->get('theme_installer')
->install([
$theme,
]);
$this
->drupalGet('admin/structure/block/demo/' . $theme);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->linkByHrefExists('admin/structure/block/list/' . $theme);
}
$this
->drupalGet('admin/structure/block/demo/invalid_theme');
$this
->assertSession()
->statusCodeEquals(403);
}
}