diff --git a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php index 2ca73fa7c6..1b061ce870 100644 --- a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php +++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php @@ -609,12 +609,7 @@ protected function prepareEnvironment() { // Reset statics. drupal_static_reset(); - // Ensure there is no service container. - if (empty($this->originalContainer)) { - $this->originalContainer = $this->initKernel(\Drupal::request()); - } $this->container = NULL; - \Drupal::unsetContainer(); // Unset globals. unset($GLOBALS['config_directories']); @@ -658,9 +653,13 @@ protected function prepareEnvironment() { * An array of available database driver installer objects. */ protected function getDatabaseTypes() { - \Drupal::setContainer($this->originalContainer); + if ($this->originalContainer) { + \Drupal::setContainer($this->originalContainer); + } $database_types = drupal_get_database_types(); - \Drupal::unsetContainer(); + if ($this->originalContainer) { + \Drupal::unsetContainer(); + } return $database_types; } diff --git a/core/lib/Drupal/Core/Test/TestSetupTrait.php b/core/lib/Drupal/Core/Test/TestSetupTrait.php index f968576730..44409078db 100644 --- a/core/lib/Drupal/Core/Test/TestSetupTrait.php +++ b/core/lib/Drupal/Core/Test/TestSetupTrait.php @@ -158,7 +158,7 @@ protected function changeDatabasePrefix() { // If the test is run with argument dburl then use it. $db_url = getenv('SIMPLETEST_DB'); if (!empty($db_url)) { - $database = Database::convertDbUrlToConnectionInfo($db_url, DRUPAL_ROOT); + $database = Database::convertDbUrlToConnectionInfo($db_url, isset($this->root) ? $this->root : DRUPAL_ROOT); Database::addConnectionInfo('default', 'default', $database); } diff --git a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php index f8311bcae3..b05a5b8fba 100644 --- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php +++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php @@ -7,6 +7,8 @@ use Behat\Mink\Selector\SelectorsHandler; use Behat\Mink\Session; use Drupal\Component\Utility\Crypt; +use Drupal\Core\DrupalKernel; +use Drupal\Core\Test\TestRunnerKernel; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\HiddenFieldSelector; use Drupal\Tests\SchemaCheckTestTrait; @@ -152,6 +154,20 @@ public function __construct($test_id = NULL) { * container that would normally be done via the installer. */ protected function setUp() { + $request = Request::createFromGlobals(); + + // Boot up Drupal into a state where calling the database API is possible. + // This is used to initialize the database system, so we can load the dump + // files. + $autoloader = require_once __DIR__ . '/../../../../../autoload.php'; + $kernel = TestRunnerKernel::createFromRequest($request, $autoloader); + $kernel->loadLegacyIncludes(); + + $this->changeDatabasePrefix(); + $this->runDbTasks(); + // Allow classes to set database dump files. + $this->setDatabaseDumpFiles(); + // We are going to set a missing zlib requirement property for usage // during the performUpgrade() and tearDown() methods. Also set that the // tests failed. diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 9ab09b262e..c118942949 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -257,6 +257,12 @@ */ protected $metaRefreshCount = 0; + public function __construct($name = null, array $data = array(), $dataName = '') { + parent::__construct($name, $data, $dataName); + + $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)))); + } + /** * Initializes Mink sessions. */