BlockDemoTest.php in Drupal 8
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 {
public static $modules = [
'block',
];
protected $defaultTheme = 'classy';
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
->assertLinkByHref('admin/structure/block');
$this
->assertNoLinkByHref('admin/structure/block/list/' . $default_theme);
$available_themes = [
'bartik',
'classy',
'seven',
'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
->assertLinkByHref('admin/structure/block/list/' . $theme);
}
$this
->drupalGet('admin/structure/block/demo/invalid_theme');
$this
->assertSession()
->statusCodeEquals(403);
}
}