diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php index 188af9c38ca..89930adbb4a 100644 --- a/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -8,6 +8,7 @@ namespace Drupal\simpletest; use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Variable; use Drupal\Core\Database\Database; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DrupalKernel; @@ -139,23 +140,52 @@ abstract class KernelTestBase extends TestBase { $settings = Settings::getAll(); // Allow for test-specific overrides. + $directory = DRUPAL_ROOT . '/' . $this->siteDirectory; $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml'; + $container_yamls = []; if (file_exists($settings_services_file)) { // Copy the testing-specific service overrides in place. - $testing_services_file = DRUPAL_ROOT . '/' . $this->siteDirectory . '/services.yml'; + $testing_services_file = $directory . '/services.yml'; copy($settings_services_file, $testing_services_file); - $this->settingsSet('container_yamls', [$testing_services_file]); + $container_yamls[] = $testing_services_file; + } + $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php'; + if (file_exists($settings_testing_file)) { + // Copy the testing-specific settings.php overrides in place. + copy($settings_testing_file, $directory . '/settings.testing.php'); + } + + if (file_exists($directory . '/settings.testing.php')) { + // Add the name of the testing class to settings.php and include the + // testing specific overrides + $hash_salt = Settings::getHashSalt(); + $test_class = get_class($this); + $container_yamls_export = Variable::export($container_yamls); + $php = <<kernel = new DrupalKernel('testing', $class_loader, FALSE); $request = Request::create('/'); - $this->kernel->setSitePath(DrupalKernel::findSitePath($request)); + $site_path = DrupalKernel::findSitePath($request); + $this->kernel->setSitePath($site_path); + if (file_exists($directory . '/settings.testing.php')) { + Settings::initialize(DRUPAL_ROOT, $site_path, $class_loader); + } $this->kernel->boot(); // Save the original site directory path, so that extensions in the diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php index 4d094903a95..218d0b989aa 100644 --- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php @@ -27,6 +27,21 @@ class KernelTestBaseTest extends KernelTestBase { * {@inheritdoc} */ protected function setUp() { + $php = <<<'EOS' +# Make sure that the $test_class variable is defined when this file is included. +if ($test_class) { +} +siteDirectory . '/settings.testing.php'; + file_put_contents($settings_testing_file, $php); + $original_container = $this->originalContainer; parent::setUp(); $this->assertNotIdentical(\Drupal::getContainer(), $original_container, 'KernelTestBase test creates a new container.'); @@ -48,6 +63,9 @@ class KernelTestBaseTest extends KernelTestBase { // Verify that no modules have been installed. $this->assertFalse(db_table_exists($table), "'$table' database table not found."); + + // Verify that the settings.testing.php got taken into account. + $this->assertTrue(function_exists('simpletest_test_stub_settings_function')); } /**