Skip to content
Snippets Groups Projects
Unverified Commit 2bb54765 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2352949 by Wim Leers, akalata, Jaesin, lauriii, dww, alexpott, Berdir,...

Issue #2352949 by Wim Leers, akalata, Jaesin, lauriii, dww, alexpott, Berdir, dawehner, tstoeckler, xjm, andypost: Deprecate using Classy as the default theme for the 'testing' profile
parent 50ac19a7
No related branches found
No related tags found
No related merge requests found
Showing with 64 additions and 5 deletions
......@@ -6,6 +6,9 @@
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Environment;
use Drupal\Core\Config\Development\ConfigSchemaChecker;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Database\Database;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Extension\MissingDependencyException;
......@@ -403,6 +406,48 @@ protected function initKernel(Request $request) {
return $this->kernel->getContainer();
}
/**
* Installs the default theme defined by `static::$defaultTheme` when needed.
*
* To install a test theme outside of the testing environment, add
* @code
* $settings['extension_discovery_scan_tests'] = TRUE;
* @endcode
* to your settings.php.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The container.
*/
protected function installDefaultThemeFromClassProperty(ContainerInterface $container) {
// Use the install profile to determine the default theme if configured and
// not already specified.
$profile = $container->getParameter('install_profile');
$default_install_path = drupal_get_path('profile', $profile) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
$profile_config_storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION);
if (!isset($this->defaultTheme) && $profile_config_storage->exists('system.theme')) {
$this->defaultTheme = $profile_config_storage->read('system.theme')['default'];
}
// Require a default theme to be specified at this point.
if (!isset($this->defaultTheme)) {
// For backwards compatibility, tests using the 'testing' install profile
// on Drupal 8 automatically get 'classy' set, and other profiles use
// 'stark'.
@trigger_error('Drupal\Tests\BrowserTestBase::$defaultTheme is required in drupal:9.0.0 when using an install profile that does not set a default theme. See https://www.drupal.org/node/2352949, which includes recommendations on which theme to use.', E_USER_DEPRECATED);
$this->defaultTheme = $profile === 'testing' ? 'classy' : 'stark';
}
// Ensure the default theme is installed.
$container->get('theme_installer')->install([$this->defaultTheme], TRUE);
$system_theme_config = $container->get('config.factory')->getEditable('system.theme');
if ($system_theme_config->get('default') !== $this->defaultTheme) {
$system_theme_config
->set('default', $this->defaultTheme)
->save();
}
}
/**
* Install modules defined by `static::$modules`.
*
......
......@@ -197,6 +197,7 @@ public function testsBlockContentAddTypes() {
foreach (['bartik', 'seven', 'stark'] as $default_theme) {
// Change the default theme.
$theme_settings->set('default', $default_theme)->save();
$this->drupalPlaceBlock('local_actions_block');
\Drupal::service('router.builder')->rebuild();
// For each installed theme, go to its block page and test the redirects.
......
......@@ -392,6 +392,8 @@ protected function setUp() {
// Initialize and override certain configurations.
$this->initConfig($container);
$this->installDefaultThemeFromClassProperty($container);
// Collect modules to install.
$this->installModulesFromClassProperty($container);
......
......@@ -334,6 +334,7 @@ public function testSwitchDefaultTheme() {
// First, install Stark and set it as the default theme programmatically.
$theme_installer->install(['stark']);
$this->config('system.theme')->set('default', 'stark')->save();
$this->drupalPlaceBlock('local_tasks_block');
// Install Bartik and set it as the default theme.
$theme_installer->install(['bartik']);
......
# @todo: Remove this file in https://www.drupal.org/node/2352949
default: classy
......@@ -9,6 +9,3 @@ install:
# tests as possible run with them enabled.
- drupal:page_cache
- dynamic_page_cache
# @todo: Remove this in https://www.drupal.org/node/2352949
themes:
- classy
......@@ -191,6 +191,8 @@ protected function setUp() {
->getEditable('system.mail')
->set('interface.default', 'test_mail_collector')
->save();
$this->installDefaultThemeFromClassProperty($this->container);
}
}
......
......@@ -198,6 +198,7 @@ protected function installDrupal() {
$this->initSettings();
$container = $this->initKernel(\Drupal::request());
$this->initConfig($container);
$this->installDefaultThemeFromClassProperty($container);
$this->installModulesFromClassProperty($container);
$this->rebuildAll();
}
......
......@@ -114,6 +114,15 @@ abstract class BrowserTestBase extends TestCase {
*/
protected $profile = 'testing';
/**
* The theme to install as the default for testing.
*
* Defaults to the install profile's default theme, if it specifies any.
*
* @var string
*/
protected $defaultTheme;
/**
* An array of custom translations suitable for drupal_rewrite_settings().
*
......@@ -557,6 +566,7 @@ public function installDrupal() {
$this->initSettings();
$container = $this->initKernel(\Drupal::request());
$this->initConfig($container);
$this->installDefaultThemeFromClassProperty($container);
$this->installModulesFromClassProperty($container);
$this->rebuildAll();
}
......
......@@ -140,6 +140,8 @@ public static function getSkippedDeprecations() {
// This deprecation comes from behat/mink-browserkit-driver when updating
// symfony/browser-kit to 4.3+.
'The "Symfony\Component\BrowserKit\Response::getStatus()" method is deprecated since Symfony 4.3, use getStatusCode() instead.',
// @todo Remove in https://www.drupal.org/project/drupal/issues/3082655
'Drupal\Tests\BrowserTestBase::$defaultTheme is required in drupal:9.0.0 when using an install profile that does not set a default theme. See https://www.drupal.org/node/2352949, which includes recommendations on which theme to use.',
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment