Initial Drupal 11 with DDEV setup
This commit is contained in:
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\FunctionalTests\Theme;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the layout builder with the Claro theme.
|
||||
*
|
||||
* @group claro
|
||||
*/
|
||||
class ClaroLayoutBuilderTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultTheme = 'claro';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = [
|
||||
'views',
|
||||
'layout_builder',
|
||||
'layout_builder_views_test',
|
||||
'layout_test',
|
||||
'field_ui',
|
||||
'block',
|
||||
'block_test',
|
||||
'node',
|
||||
'layout_builder_test',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('local_tasks_block', ['region' => 'header']);
|
||||
|
||||
// Create two nodes.
|
||||
$this->createContentType([
|
||||
'type' => 'bundle_with_section_field',
|
||||
'name' => 'Bundle with section field',
|
||||
]);
|
||||
$this->createNode([
|
||||
'type' => 'bundle_with_section_field',
|
||||
'title' => 'The first node title',
|
||||
'body' => [
|
||||
[
|
||||
'value' => 'The first node body',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$this->createNode([
|
||||
'type' => 'bundle_with_section_field',
|
||||
'title' => 'The second node title',
|
||||
'body' => [
|
||||
[
|
||||
'value' => 'The second node body',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the layout builder has expected contextual links with Claro.
|
||||
*
|
||||
* @see claro.theme
|
||||
*/
|
||||
public function testContextualLinks(): void {
|
||||
$assert_session = $this->assertSession();
|
||||
$page = $this->getSession()->getPage();
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'configure any layout',
|
||||
'administer node display',
|
||||
'administer node fields',
|
||||
'access contextual links',
|
||||
]));
|
||||
|
||||
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
|
||||
|
||||
// From the manage display page, go to manage the layout.
|
||||
$this->drupalGet("$field_ui_prefix/display/default");
|
||||
$assert_session->linkNotExists('Manage layout');
|
||||
$assert_session->fieldDisabled('layout[allow_custom]');
|
||||
|
||||
$this->submitForm(['layout[enabled]' => TRUE], 'Save');
|
||||
$assert_session->linkExists('Manage layout');
|
||||
$this->clickLink('Manage layout');
|
||||
|
||||
// Add a new block.
|
||||
$assert_session->linkExists('Add block');
|
||||
$this->clickLink('Add block');
|
||||
$assert_session->linkExists('Powered by Drupal');
|
||||
$this->clickLink('Powered by Drupal');
|
||||
$page->fillField('settings[label]', 'This is the label');
|
||||
$page->checkField('settings[label_display]');
|
||||
$page->pressButton('Add block');
|
||||
|
||||
// Test that the block has the contextual class applied and the container
|
||||
// for contextual links.
|
||||
$assert_session->elementExists('css', 'div.block-system-powered-by-block.contextual-region div[data-contextual-id]');
|
||||
|
||||
// Ensure other blocks do not have contextual links.
|
||||
$assert_session->elementExists('css', 'div.block-page-title-block');
|
||||
$assert_session->elementNotExists('css', 'div.block-page-title-block.contextual-region div[data-contextual-id]');
|
||||
}
|
||||
|
||||
}
|
||||
104
web/core/tests/Drupal/FunctionalTests/Theme/ClaroTest.php
Normal file
104
web/core/tests/Drupal/FunctionalTests/Theme/ClaroTest.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\FunctionalTests\Theme;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the Claro theme.
|
||||
*
|
||||
* @group claro
|
||||
*/
|
||||
class ClaroTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* Install the shortcut module so that claro.settings has its schema checked.
|
||||
* There's currently no way for Claro to provide a default and have valid
|
||||
* configuration as themes cannot react to a module install.
|
||||
*
|
||||
* Install dblog and pager_test for testing of pager attributes.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $modules = ['dblog', 'shortcut', 'pager_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultTheme = 'claro';
|
||||
|
||||
/**
|
||||
* Testing that Claro theme's global library is always attached.
|
||||
*
|
||||
* @see claro.info.yml
|
||||
*/
|
||||
public function testRegressionMissingElementsCss(): void {
|
||||
$this->drupalGet('');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
// This can be any CSS file from the global library.
|
||||
$this->assertSession()->responseContains('claro/css/base/elements.css');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Claro's configuration schema.
|
||||
*/
|
||||
public function testConfigSchema(): void {
|
||||
$permissions = [
|
||||
'administer modules',
|
||||
];
|
||||
$this->drupalLogin($this->drupalCreateUser($permissions));
|
||||
$this->drupalGet('admin/modules');
|
||||
$this->assertSession()->elementNotExists('css', '#block-claro-help');
|
||||
|
||||
// Install the block module to ensure Claro's configuration is valid
|
||||
// according to schema.
|
||||
\Drupal::service('module_installer')->install(['block', 'help']);
|
||||
$this->rebuildAll();
|
||||
|
||||
$this->drupalGet('admin/modules');
|
||||
$this->assertSession()->elementExists('css', '#block-claro-help');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the Claro theme can be uninstalled.
|
||||
*/
|
||||
public function testIsUninstallable(): void {
|
||||
$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 Claro theme"]')[0]->click();
|
||||
$this->assertSession()->pageTextContains('The Claro theme has been uninstalled.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests pager attribute is present using pager_test.
|
||||
*/
|
||||
public function testPagerAttribute(): void {
|
||||
// Insert 300 log messages.
|
||||
$logger = $this->container->get('logger.factory')->get('pager_test');
|
||||
for ($i = 0; $i < 300; $i++) {
|
||||
$logger->debug($this->randomString());
|
||||
}
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser(['access site reports']));
|
||||
|
||||
$this->drupalGet('admin/reports/dblog', ['query' => ['page' => 1]]);
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
|
||||
$this->assertNotEmpty($elements, 'Pager found.');
|
||||
|
||||
// Check all links for pager-test attribute.
|
||||
foreach ($elements as $page => $element) {
|
||||
$link = $element->find('css', 'a');
|
||||
$this->assertNotEmpty($link, "Link to page $page found.");
|
||||
$this->assertTrue($link->hasAttribute('pager-test'), 'Pager item has attribute pager-test');
|
||||
$this->assertTrue($link->hasClass('lizards'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
177
web/core/tests/Drupal/FunctionalTests/Theme/OliveroTest.php
Normal file
177
web/core/tests/Drupal/FunctionalTests/Theme/OliveroTest.php
Normal file
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\FunctionalTests\Theme;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||
|
||||
/**
|
||||
* Tests the Olivero theme.
|
||||
*
|
||||
* @group olivero
|
||||
*/
|
||||
class OliveroTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $profile = 'minimal';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultTheme = 'olivero';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = [
|
||||
'olivero_test',
|
||||
'pager_test',
|
||||
'dblog',
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests that the Olivero theme always adds base library files.
|
||||
*
|
||||
* @see olivero.libraries.yml
|
||||
*/
|
||||
public function testBaseLibraryAvailable(): void {
|
||||
$this->drupalGet('');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->responseContains('olivero/css/base/base.css');
|
||||
$this->assertSession()->responseContains('olivero/js/navigation-utils.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Olivero's configuration schema.
|
||||
*/
|
||||
public function testConfigSchema(): void {
|
||||
// Required configuration.
|
||||
$this->drupalGet('');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->elementExists('css', '#block-olivero-content');
|
||||
$this->assertSession()->elementNotExists('css', '#block-olivero-search-form-wide');
|
||||
|
||||
// Optional configuration.
|
||||
\Drupal::service('module_installer')->install(
|
||||
['search', 'image', 'help', 'node']
|
||||
);
|
||||
$this->rebuildAll();
|
||||
$this->drupalLogin(
|
||||
$this->drupalCreateUser(['search content'])
|
||||
);
|
||||
|
||||
// Confirm search block was installed.
|
||||
$this->assertSession()->elementExists('css', '#block-olivero-search-form-wide');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that olivero_preprocess_block is functioning as expected.
|
||||
*
|
||||
* @see olivero.libraries.yml
|
||||
*/
|
||||
public function testPreprocessBlock(): void {
|
||||
$this->drupalGet('');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
|
||||
// Confirm that search narrow and search wide libraries haven't yet been
|
||||
// added.
|
||||
$this->assertSession()->responseNotContains('olivero/css/components/header-search-wide.css');
|
||||
$this->assertSession()->responseNotContains('olivero/css/components/header-search-narrow.css');
|
||||
|
||||
// Enable modules that will exercise preprocess block logic.
|
||||
\Drupal::service('module_installer')->install(
|
||||
['search', 'menu_link_content']
|
||||
);
|
||||
|
||||
// Add at least one link to the main menu.
|
||||
$parent_menu_link_content = MenuLinkContent::create([
|
||||
'title' => 'Home',
|
||||
'menu_name' => 'main',
|
||||
'link' => ['uri' => 'route:<front>'],
|
||||
]);
|
||||
$parent_menu_link_content->save();
|
||||
|
||||
// Set branding color.
|
||||
$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'])
|
||||
);
|
||||
|
||||
// Confirm that search narrow and search wide libraries were added by
|
||||
// preprocess.
|
||||
$this->assertSession()->responseContains('olivero/css/components/header-search-wide.css');
|
||||
$this->assertSession()->responseContains('olivero/css/components/header-search-narrow.css');
|
||||
|
||||
// Confirm primary-nav class was added to main menu navigation block.
|
||||
$this->assertSession()->elementExists('css', '#block-olivero-main-menu.primary-nav');
|
||||
|
||||
// Ensure branding background color class was added.
|
||||
$this->assertSession()->elementExists('css', '#block-olivero-site-branding.site-branding--bg-gray');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the Olivero theme can be uninstalled.
|
||||
*/
|
||||
public function testIsUninstallable(): void {
|
||||
$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.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests pager attribute is present using pager_test.
|
||||
*/
|
||||
public function testPagerAttribute(): void {
|
||||
// Insert 300 log messages.
|
||||
$logger = \Drupal::logger('pager_test');
|
||||
for ($i = 0; $i < 300; $i++) {
|
||||
$logger->debug($this->randomString());
|
||||
}
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser(['access site reports']));
|
||||
|
||||
$this->drupalGet('pager-test/multiple-pagers', ['query' => ['page' => 1]]);
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
|
||||
$this->assertNotEmpty($elements, 'Pager found.');
|
||||
|
||||
// Check all links for pager-test attribute.
|
||||
foreach ($elements as $element) {
|
||||
$link = $element->find('css', 'a');
|
||||
// Current page does not have a link.
|
||||
if (empty($link)) {
|
||||
continue;
|
||||
}
|
||||
$this->assertTrue($link->hasAttribute('pager-test'), 'Pager item has attribute pager-test');
|
||||
$this->assertTrue($link->hasClass('lizards'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests slogan of system branding block.
|
||||
*/
|
||||
public function testSystemSiteBrandingSlogan(): void {
|
||||
$this->config('system.site')
|
||||
->set('slogan', 'Community carpentry')
|
||||
->save();
|
||||
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertSession()->pageTextContains('Community carpentry');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user