diff --git a/core/modules/simpletest/src/InstallerTestBase.php b/core/tests/Drupal/FunctionalTests/Installer/InstallerTestBase.php index ae7c734dbd..55569a28d9 100644 --- a/core/modules/simpletest/src/InstallerTestBase.php +++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerTestBase.php @@ -1,11 +1,16 @@ isInstalled = FALSE; + $this->setupBaseUrl(); + + $this->prepareDatabasePrefix(); + + // Install Drupal test site. + $this->prepareEnvironment(); + // Define information about the user 1 account. $this->rootUser = new UserSession([ 'uid' => 1, @@ -88,12 +100,13 @@ protected function setUp() { $this->writeSettings($this->settings); } - // Note that WebTestBase::installParameters() returns form input values - // suitable for a programmed \Drupal::formBuilder()->submitForm(). - // @see WebTestBase::translatePostValues() + // Note that FunctionalTestSetupTrait::installParameters() returns form + // input values suitable for a programmed + // \Drupal::formBuilder()->submitForm(). + // @see InstallerTestBase::translatePostValues() $this->parameters = $this->installParameters(); - // Set up a minimal container (required by WebTestBase). Set cookie and + // Set up a minimal container (required by BrowserTestBase). Set cookie and // server information so that XDebug works. // @see install_begin_request() $request = Request::create($GLOBALS['base_url'] . '/core/install.php', 'GET', [], $_COOKIE, [], $_SERVER); @@ -110,10 +123,25 @@ protected function setUp() { $this->container ->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager') ->addArgument(new Reference('language.default')); + $this->container + ->register('http_client', 'GuzzleHttp\Client') + ->setFactory('http_client_factory:fromOptions'); + $this->container + ->register('http_client_factory', 'Drupal\Core\Http\ClientFactory') + ->setArguments([new Reference('http_handler_stack')]); + $handler_stack = HandlerStack::create(); + $test_http_client_middleware = new TestHttpClientMiddleware(); + $handler_stack->push($test_http_client_middleware(), 'test.http_client.middleware'); + $this->container + ->set('http_handler_stack', $handler_stack); + $this->container ->set('app.root', DRUPAL_ROOT); \Drupal::setContainer($this->container); + // Setup Mink. + $this->initMink(); + $this->visitInstaller(); // Select language. @@ -147,7 +175,7 @@ protected function setUp() { // from the site directory. To allow drupal_generate_test_ua() to write // a file containing the private key for drupal_valid_test_ua(), the site // directory has to be writable. - // WebTestBase::tearDown() will delete the entire test site directory. + // BrowserTestBase::tearDown() will delete the entire test site directory. // Not using File API; a potential error must trigger a PHP warning. chmod($this->container->get('app.root') . '/' . $this->siteDirectory, 0777); $this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE); @@ -163,6 +191,14 @@ protected function setUp() { } } + /** + * {@inheritdoc} + */ + protected function initFrontPage() { + // We don't want to visit the front page with the installer when + // initializing Mink, so we do nothing here. + } + /** * Visits the interactive installer. */ @@ -226,11 +262,33 @@ protected function setUpSite() { $this->isInstalled = TRUE; } + /** + * Transforms a nested array into a flat array suitable for drupalPostForm(). + * + * @param array $values + * A multi-dimensional form values array to convert. + * + * @return array + * The flattened $edit array suitable for BrowserTestBase::drupalPostForm(). + */ + protected function translatePostValues(array $values) { + $edit = []; + // The easiest and most straightforward way to translate values suitable for + // BrowserTestBase::drupalPostForm() is to actually build the POST data + // string and convert the resulting key/value pairs back into a flat array. + $query = http_build_query($values); + foreach (explode('&', $query) as $item) { + list($key, $value) = explode('=', $item); + $edit[urldecode($key)] = urldecode($value); + } + return $edit; + } + /** * {@inheritdoc} * - * WebTestBase::refreshVariables() tries to operate on persistent storage, - * which is only available after the installer completed. + * FunctionalTestSetupTrait::refreshVariables() tries to operate on persistent + * storage, which is only available after the installer completed. */ protected function refreshVariables() { if ($this->isInstalled) { @@ -272,10 +330,11 @@ protected function continueOnExpectedWarnings($expected_warnings = []) { // Confirm that there are only the expected warnings. $warnings = []; foreach ($warning_elements as $warning) { - $warnings[] = trim((string) $warning); + $warnings[] = trim($warning->getText()); } - $this->assertEqual($expected_warnings, $warnings); + $this->assertEquals($expected_warnings, $warnings); $this->clickLink('continue anyway'); + $this->checkForMetaRefresh(); } }