.../Drupal/Core/Test/FunctionalTestSetupTrait.php | 38 ++++++++++++++++++++++ .../tests/src/Functional/BlockContentTypeTest.php | 1 + core/modules/simpletest/src/WebTestBase.php | 2 ++ .../tests/src/Functional/System/ThemeTest.php | 1 + .../testing/config/install/system.theme.yml | 2 -- core/profiles/testing/testing.info.yml | 3 -- .../Installer/InstallerTranslationTest.php | 7 +++- .../FunctionalTests/Update/UpdatePathTestBase.php | 5 +++ .../TestSite/Commands/TestSiteInstallCommand.php | 1 + core/tests/Drupal/Tests/BrowserTestBase.php | 10 ++++++ .../Tests/Listeners/DeprecationListenerTrait.php | 2 ++ 11 files changed, 66 insertions(+), 6 deletions(-) diff --git a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php index c085d4ec6b..a770c535e1 100644 --- a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php +++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php @@ -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; @@ -359,6 +362,25 @@ protected function initConfig(ContainerInterface $container) { $config->getEditable('system.date') ->set('timezone.default', 'Australia/Sydney') ->save(); + + // If the used install profile does not configure a default theme, require a + // default theme to be specified. For backwards compatibility, tests using + // the 'testing' install profile on Drupal 8 automatically get 'classy' set, + // but those tests will have to be updated before Drupal 9.0.0. + $default_install_path = drupal_get_path('profile', $this->profile) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY; + $profile_config_storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION); + $profile_default_theme = $profile_config_storage->read('system.theme'); + if (!$profile_default_theme) { + @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); + if ($this->profile === 'testing') { + $this->defaultTheme = 'classy'; + } + $config->getEditable('system.theme') + // @see core/modules/system/config/install/system.theme.yml + ->clear('admin') + ->set('default', $this->defaultTheme) + ->save(); + } } /** @@ -403,6 +425,22 @@ protected function initKernel(Request $request) { return $this->kernel->getContainer(); } + /** + * Install the default theme defined by `static::$defaultTheme`. + * + * 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) { + $container->get('theme_installer')->install([$this->defaultTheme], TRUE); + } + /** * Install modules defined by `static::$modules`. * diff --git a/core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php b/core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php index bd3695cae3..452bea0786 100644 --- a/core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php +++ b/core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php @@ -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. diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 3f0ab2ff13..d86aa3f252 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -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); diff --git a/core/modules/system/tests/src/Functional/System/ThemeTest.php b/core/modules/system/tests/src/Functional/System/ThemeTest.php index 1964e4172e..3b4cc2e702 100644 --- a/core/modules/system/tests/src/Functional/System/ThemeTest.php +++ b/core/modules/system/tests/src/Functional/System/ThemeTest.php @@ -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']); diff --git a/core/profiles/testing/config/install/system.theme.yml b/core/profiles/testing/config/install/system.theme.yml deleted file mode 100644 index 0defc7eaec..0000000000 --- a/core/profiles/testing/config/install/system.theme.yml +++ /dev/null @@ -1,2 +0,0 @@ -# @todo: Remove this file in https://www.drupal.org/node/2352949 -default: classy diff --git a/core/profiles/testing/testing.info.yml b/core/profiles/testing/testing.info.yml index 9924817a3d..834198a743 100644 --- a/core/profiles/testing/testing.info.yml +++ b/core/profiles/testing/testing.info.yml @@ -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 diff --git a/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php b/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php index 55ce6b534c..689117096d 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php @@ -19,6 +19,11 @@ class InstallerTranslationTest extends InstallerTestBase { */ protected $langcode = 'de'; + /** + * {@inheritdoc} + */ + protected $profile = 'standard'; + /** * {@inheritdoc} */ @@ -64,7 +69,7 @@ protected function setUpSettings() { * Verifies the expected behaviors of the installation result. */ public function testInstaller() { - $this->assertUrl('user/1'); + $this->assertUrl('node'); $this->assertResponse(200); // Verify German was configured but not English. diff --git a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php index d7bad28513..80f3ea7846 100644 --- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php +++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php @@ -74,6 +74,11 @@ abstract class UpdatePathTestBase extends BrowserTestBase { */ protected $installProfile = 'standard'; + /** + * {@inheritdoc} + */ + protected $profile = 'standard'; + /** * Flag that indicates whether the child site has been updated. * diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php index d020304018..0764c7ed0a 100644 --- a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php @@ -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(); } diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 2b1ee867b1..759b6033ea 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -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(); } diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php index 3c76756bd5..f9e346ac4c 100644 --- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php @@ -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.', ]; }