View source
<?php
namespace Drupal\Tests\system\Functional\Theme;
use Drupal\Tests\BrowserTestBase;
class ToolbarClaroOverridesTest extends BrowserTestBase {
protected static $modules = [
'toolbar',
'test_page_test',
'shortcut',
'node',
];
protected $defaultTheme = 'stark';
protected $themeInstaller;
protected function setUp() : void {
parent::setUp();
$this->themeInstaller = $this->container
->get('theme_installer');
$this->themeManager = $this->container
->get('theme.manager');
$this->themeInstaller
->install([
'claro',
]);
$this
->drupalLogin($this
->drupalCreateUser([
'access toolbar',
'access shortcuts',
'administer shortcuts',
'access content overview',
]));
}
public function testClaroAssets() {
$default_stylesheets = [
'core/modules/toolbar/css/toolbar.module.css',
'core/modules/toolbar/css/toolbar.menu.css',
'core/modules/toolbar/css/toolbar.theme.css',
'core/modules/toolbar/css/toolbar.icons.theme.css',
];
$claro_stylesheets = [
'core/themes/claro/css/components/toolbar.module.css',
'core/themes/claro/css/state/toolbar.menu.css',
'core/themes/claro/css/theme/toolbar.theme.css',
'core/themes/claro/css/theme/toolbar.icons.theme.css',
];
$this
->config('system.theme')
->set('admin', 'stark')
->save();
$this
->drupalGet('test-page');
$this
->assertSession()
->statusCodeEquals(200);
$admin_theme = \Drupal::configFactory()
->get('system.theme')
->get('admin');
$default_theme = \Drupal::configFactory()
->get('system.theme')
->get('default');
$this
->assertEquals('stark', $admin_theme);
$this
->assertEquals('stark', $default_theme);
$head = $this
->getSession()
->getPage()
->find('css', 'head')
->getHtml();
$stylesheet_positions = [];
foreach ($default_stylesheets as $stylesheet) {
$this
->assertStringContainsString($stylesheet, $head);
$stylesheet_positions[] = strpos($head, $stylesheet);
}
$sorted_stylesheet_positions = $stylesheet_positions;
sort($sorted_stylesheet_positions);
$this
->assertEquals($sorted_stylesheet_positions, $stylesheet_positions);
foreach ($claro_stylesheets as $stylesheet) {
$this
->assertStringNotContainsString($stylesheet, $head);
}
$this
->assertFalse($this
->getSession()
->getPage()
->find('css', '#toolbar-administration')
->hasAttribute('data-drupal-claro-processed-toolbar'));
$this
->assertFalse($this
->getSession()
->getPage()
->find('css', '.toolbar-menu')
->hasClass('claro-toolbar-menu'));
$this
->assertFalse($this
->getSession()
->getPage()
->find('css', '.toolbar')
->hasClass('claro-toolbar'));
$this
->config('system.theme')
->set('admin', 'claro')
->save();
$this
->drupalGet('test-page');
$this
->assertSession()
->statusCodeEquals(200);
$admin_theme = \Drupal::configFactory()
->get('system.theme')
->get('admin');
$default_theme = \Drupal::configFactory()
->get('system.theme')
->get('default');
$this
->assertEquals('claro', $admin_theme);
$this
->assertEquals('stark', $default_theme);
$head = $this
->getSession()
->getPage()
->find('css', 'head')
->getHtml();
$stylesheet_positions = [];
foreach ($claro_stylesheets as $stylesheet) {
$this
->assertStringContainsString($stylesheet, $head);
$stylesheet_positions[] = strpos($head, $stylesheet);
}
$sorted_stylesheet_positions = $stylesheet_positions;
sort($sorted_stylesheet_positions);
$this
->assertEquals($sorted_stylesheet_positions, $stylesheet_positions);
foreach ($default_stylesheets as $stylesheet) {
$this
->assertStringNotContainsString($stylesheet, $head);
}
$this
->assertTrue($this
->getSession()
->getPage()
->find('css', '#toolbar-administration')
->hasAttribute('data-drupal-claro-processed-toolbar'));
$this
->assertTrue($this
->getSession()
->getPage()
->find('css', '.toolbar')
->hasClass('claro-toolbar'));
$this
->assertTrue($this
->getSession()
->getPage()
->find('css', '.toolbar-menu')
->hasClass('claro-toolbar-menu'));
}
}