.../Drupal/Core/Test/FunctionalTestSetupTrait.php | 42 ++++++++++++++++++++++ .../testing/config/install/system.theme.yml | 2 -- core/profiles/testing/testing.info.yml | 3 -- core/tests/Drupal/Tests/BrowserTestBase.php | 8 +++++ .../Tests/Listeners/DeprecationListenerTrait.php | 2 ++ 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php index 3f8a74326a..b05c05d39c 100644 --- a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php +++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php @@ -8,6 +8,8 @@ use Drupal\Core\Config\Development\ConfigSchemaChecker; use Drupal\Core\Database\Database; use Drupal\Core\DrupalKernel; +use Drupal\Core\Extension\Exception\UnknownExtensionException; +use Drupal\Core\Extension\ExtensionNameLengthException; use Drupal\Core\Extension\MissingDependencyException; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Serialization\Yaml; @@ -359,6 +361,20 @@ protected function initConfig(ContainerInterface $container) { $config->getEditable('system.date') ->set('timezone.default', 'Australia/Sydney') ->save(); + + if (empty($this->theme)) { + @trigger_error('Drupal\Tests\BrowserTestBase::$theme is required in drupal:9.0.0. See https://www.drupal.org/node/2352949', E_USER_DEPRECATED); + $this->theme = 'classy'; + if ($this->profile === 'demo_umami') { + $this->theme = 'umami'; + } + elseif ($this->profile === 'standard') { + $this->theme = 'bartik'; + } + } + $config->getEditable('system.theme') + ->set('default', $this->theme) + ->save(); } /** @@ -403,6 +419,32 @@ protected function initKernel(Request $request) { return $this->kernel->getContainer(); } + /** + * Install the theme defined by `static::$theme`. + * + * 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 installThemeFromClassProperty(ContainerInterface $container) { + try { + $container->get('theme_installer')->install([$this->theme], TRUE); + } + catch (UnknownExtensionException $e) { + // The exception message has all the details. + $this->fail($e->getMessage()); + } + catch (ExtensionNameLengthException $e) { + // The exception message has all the details. + $this->fail($e->getMessage()); + } + } + /** * Install modules defined by `static::$modules`. * 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/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 2b1ee867b1..617e326fbf 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -114,6 +114,13 @@ abstract class BrowserTestBase extends TestCase { */ protected $profile = 'testing'; + /** + * The theme to install as the default for testing. + * + * @var string + */ + protected $theme; + /** * An array of custom translations suitable for drupal_rewrite_settings(). * @@ -557,6 +564,7 @@ public function installDrupal() { $this->initSettings(); $container = $this->initKernel(\Drupal::request()); $this->initConfig($container); + $this->installThemeFromClassProperty($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..da5256c82f 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 … + 'Drupal\Tests\BrowserTestBase::$theme is required in drupal:9.0.0. See https://www.drupal.org/node/2352949', ]; }