OliveroTest.php in Drupal 10
File
core/tests/Drupal/FunctionalTests/Theme/OliveroTest.php
View source
<?php
namespace Drupal\FunctionalTests\Theme;
use Drupal\Tests\BrowserTestBase;
use Drupal\menu_link_content\Entity\MenuLinkContent;
class OliveroTest extends BrowserTestBase {
protected $profile = 'minimal';
protected $defaultTheme = 'olivero';
protected static $modules = [
'olivero_test',
];
public function testBaseLibraryAvailable() {
$this
->drupalGet('');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('olivero/css/base/base.css');
$this
->assertSession()
->responseContains('olivero/js/navigation-utils.js');
}
public function testConfigSchema() {
$this
->drupalGet('');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->elementExists('css', '#block-olivero-content');
$this
->assertSession()
->elementNotExists('css', '#block-olivero-search-form-wide');
\Drupal::service('module_installer')
->install([
'search',
'image',
'book',
'help',
'node',
]);
$this
->rebuildAll();
$this
->drupalLogin($this
->drupalCreateUser([
'search content',
]));
$this
->assertSession()
->elementExists('css', '#block-olivero-search-form-wide');
}
public function testPreprocessBlock() {
$this
->drupalGet('');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseNotContains('olivero/css/components/header-search-wide.css');
$this
->assertSession()
->responseNotContains('olivero/css/components/header-search-narrow.css');
\Drupal::service('module_installer')
->install([
'search',
'menu_link_content',
]);
$parent_menu_link_content = MenuLinkContent::create([
'title' => 'Home',
'menu_name' => 'main',
'link' => [
'uri' => 'route:<front>',
],
]);
$parent_menu_link_content
->save();
$system_theme_config = $this->container
->get('config.factory')
->getEditable('olivero.settings');
$system_theme_config
->set('site_branding_bg_color', 'gray')
->save();
$this
->rebuildAll();
$this
->drupalLogin($this
->drupalCreateUser([
'search content',
]));
$this
->assertSession()
->responseContains('olivero/css/components/header-search-wide.css');
$this
->assertSession()
->responseContains('olivero/css/components/header-search-narrow.css');
$this
->assertSession()
->elementExists('css', '#block-olivero-main-menu.primary-nav');
$this
->assertSession()
->elementExists('css', '#block-olivero-site-branding.site-branding--bg-gray');
}
public function testIsUninstallable() {
$this
->drupalLogin($this
->drupalCreateUser([
'access administration pages',
'administer themes',
]));
$this
->drupalGet('admin/appearance');
$this
->cssSelect('a[title="Install <strong>Test theme</strong> as default theme"]')[0]
->click();
$this
->cssSelect('a[title="Uninstall Olivero theme"]')[0]
->click();
$this
->assertSession()
->pageTextContains('The Olivero theme has been uninstalled.');
}
}