Chris@16: 'Save and continue', Chris@16: ]; Chris@16: Chris@16: /** Chris@16: * Whether the installer has completed. Chris@16: * Chris@16: * @var bool Chris@16: */ Chris@16: protected $isInstalled = FALSE; Chris@16: Chris@16: /** Chris@16: * {@inheritdoc} Chris@16: */ Chris@16: protected function setUp() { Chris@16: $this->isInstalled = FALSE; Chris@16: Chris@16: $this->setupBaseUrl(); Chris@16: Chris@16: $this->prepareDatabasePrefix(); Chris@16: Chris@16: // Install Drupal test site. Chris@16: $this->prepareEnvironment(); Chris@16: Chris@16: // Define information about the user 1 account. Chris@16: $this->rootUser = new UserSession([ Chris@16: 'uid' => 1, Chris@16: 'name' => 'admin', Chris@16: 'mail' => 'admin@example.com', Chris@16: 'pass_raw' => $this->randomMachineName(), Chris@16: ]); Chris@16: Chris@16: // If any $settings are defined for this test, copy and prepare an actual Chris@16: // settings.php, so as to resemble a regular installation. Chris@16: if (!empty($this->settings)) { Chris@16: // Not using File API; a potential error must trigger a PHP warning. Chris@16: copy(DRUPAL_ROOT . '/sites/default/default.settings.php', DRUPAL_ROOT . '/' . $this->siteDirectory . '/settings.php'); Chris@16: $this->writeSettings($this->settings); Chris@16: } Chris@16: Chris@16: // Note that FunctionalTestSetupTrait::installParameters() returns form Chris@16: // input values suitable for a programmed Chris@16: // \Drupal::formBuilder()->submitForm(). Chris@16: // @see InstallerTestBase::translatePostValues() Chris@16: $this->parameters = $this->installParameters(); Chris@16: Chris@16: // Set up a minimal container (required by BrowserTestBase). Set cookie and Chris@16: // server information so that XDebug works. Chris@16: // @see install_begin_request() Chris@16: $request = Request::create($GLOBALS['base_url'] . '/core/install.php', 'GET', [], $_COOKIE, [], $_SERVER); Chris@16: $this->container = new ContainerBuilder(); Chris@16: $request_stack = new RequestStack(); Chris@16: $request_stack->push($request); Chris@16: $this->container Chris@16: ->set('request_stack', $request_stack); Chris@16: $this->container Chris@16: ->setParameter('language.default_values', Language::$defaultValues); Chris@16: $this->container Chris@16: ->register('language.default', 'Drupal\Core\Language\LanguageDefault') Chris@16: ->addArgument('%language.default_values%'); Chris@16: $this->container Chris@16: ->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager') Chris@16: ->addArgument(new Reference('language.default')); Chris@16: $this->container Chris@16: ->register('http_client', 'GuzzleHttp\Client') Chris@16: ->setFactory('http_client_factory:fromOptions'); Chris@16: $this->container Chris@16: ->register('http_client_factory', 'Drupal\Core\Http\ClientFactory') Chris@16: ->setArguments([new Reference('http_handler_stack')]); Chris@16: $handler_stack = HandlerStack::create(); Chris@16: $test_http_client_middleware = new TestHttpClientMiddleware(); Chris@16: $handler_stack->push($test_http_client_middleware(), 'test.http_client.middleware'); Chris@16: $this->container Chris@16: ->set('http_handler_stack', $handler_stack); Chris@16: Chris@16: $this->container Chris@16: ->set('app.root', DRUPAL_ROOT); Chris@16: \Drupal::setContainer($this->container); Chris@16: Chris@16: // Setup Mink. Chris@16: $this->initMink(); Chris@16: Chris@17: // Set up the browser test output file. Chris@17: $this->initBrowserOutputFile(); Chris@17: Chris@16: $this->visitInstaller(); Chris@16: Chris@16: // Select language. Chris@16: $this->setUpLanguage(); Chris@16: Chris@16: // Select profile. Chris@16: $this->setUpProfile(); Chris@16: Chris@16: // Address the requirements problem screen, if any. Chris@16: $this->setUpRequirementsProblem(); Chris@16: Chris@16: // Configure settings. Chris@16: $this->setUpSettings(); Chris@16: Chris@16: // @todo Allow test classes based on this class to act on further installer Chris@16: // screens. Chris@16: Chris@16: // Configure site. Chris@16: $this->setUpSite(); Chris@16: Chris@16: if ($this->isInstalled) { Chris@16: // Import new settings.php written by the installer. Chris@16: $request = Request::createFromGlobals(); Chris@16: $class_loader = require $this->container->get('app.root') . '/autoload.php'; Chris@16: Settings::initialize($this->container->get('app.root'), DrupalKernel::findSitePath($request), $class_loader); Chris@16: foreach ($GLOBALS['config_directories'] as $type => $path) { Chris@16: $this->configDirectories[$type] = $path; Chris@16: } Chris@16: Chris@16: // After writing settings.php, the installer removes write permissions Chris@16: // from the site directory. To allow drupal_generate_test_ua() to write Chris@16: // a file containing the private key for drupal_valid_test_ua(), the site Chris@16: // directory has to be writable. Chris@16: // BrowserTestBase::tearDown() will delete the entire test site directory. Chris@16: // Not using File API; a potential error must trigger a PHP warning. Chris@16: chmod($this->container->get('app.root') . '/' . $this->siteDirectory, 0777); Chris@16: $this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE); Chris@16: $this->kernel->prepareLegacyRequest($request); Chris@16: $this->container = $this->kernel->getContainer(); Chris@16: Chris@16: // Manually configure the test mail collector implementation to prevent Chris@16: // tests from sending out emails and collect them in state instead. Chris@16: $this->container->get('config.factory') Chris@16: ->getEditable('system.mail') Chris@16: ->set('interface.default', 'test_mail_collector') Chris@16: ->save(); Chris@16: } Chris@16: } Chris@16: Chris@16: /** Chris@16: * {@inheritdoc} Chris@16: */ Chris@16: protected function initFrontPage() { Chris@16: // We don't want to visit the front page with the installer when Chris@16: // initializing Mink, so we do nothing here. Chris@16: } Chris@16: Chris@16: /** Chris@16: * Visits the interactive installer. Chris@16: */ Chris@16: protected function visitInstaller() { Chris@16: $this->drupalGet($GLOBALS['base_url'] . '/core/install.php'); Chris@16: } Chris@16: Chris@16: /** Chris@16: * Installer step: Select language. Chris@16: */ Chris@16: protected function setUpLanguage() { Chris@16: $edit = [ Chris@16: 'langcode' => $this->langcode, Chris@16: ]; Chris@16: $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']); Chris@16: } Chris@16: Chris@16: /** Chris@16: * Installer step: Select installation profile. Chris@16: */ Chris@16: protected function setUpProfile() { Chris@16: $edit = [ Chris@16: 'profile' => $this->profile, Chris@16: ]; Chris@16: $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']); Chris@16: } Chris@16: Chris@16: /** Chris@16: * Installer step: Configure settings. Chris@16: */ Chris@16: protected function setUpSettings() { Chris@16: $edit = $this->translatePostValues($this->parameters['forms']['install_settings_form']); Chris@16: $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']); Chris@16: } Chris@16: Chris@16: /** Chris@16: * Installer step: Requirements problem. Chris@16: * Chris@16: * Override this method to test specific requirements warnings or errors Chris@16: * during the installer. Chris@16: * Chris@16: * @see system_requirements() Chris@16: */ Chris@16: protected function setUpRequirementsProblem() { Chris@16: // By default, skip the "recommended PHP version" warning on older test Chris@16: // environments. This allows the installer to be tested consistently on Chris@16: // both recommended PHP versions and older (but still supported) versions. Chris@16: if (version_compare(phpversion(), '7.0') < 0) { Chris@16: $this->continueOnExpectedWarnings(['PHP']); Chris@16: } Chris@16: } Chris@16: Chris@16: /** Chris@16: * Final installer step: Configure site. Chris@16: */ Chris@16: protected function setUpSite() { Chris@16: $edit = $this->translatePostValues($this->parameters['forms']['install_configure_form']); Chris@16: $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']); Chris@16: // If we've got to this point the site is installed using the regular Chris@16: // installation workflow. Chris@16: $this->isInstalled = TRUE; Chris@16: } Chris@16: Chris@16: /** Chris@16: * {@inheritdoc} Chris@16: * Chris@16: * FunctionalTestSetupTrait::refreshVariables() tries to operate on persistent Chris@16: * storage, which is only available after the installer completed. Chris@16: */ Chris@16: protected function refreshVariables() { Chris@16: if ($this->isInstalled) { Chris@16: parent::refreshVariables(); Chris@16: } Chris@16: } Chris@16: Chris@16: /** Chris@16: * Continues installation when an expected warning is found. Chris@16: * Chris@16: * @param string[] $expected_warnings Chris@16: * A list of warning summaries to expect on the requirements screen (e.g. Chris@16: * 'PHP', 'PHP OPcode caching', etc.). If only the expected warnings Chris@16: * are found, the test will click the "continue anyway" link to go to the Chris@16: * next screen of the installer. If an expected warning is not found, or if Chris@16: * a warning not in the list is present, a fail is raised. Chris@16: */ Chris@16: protected function continueOnExpectedWarnings($expected_warnings = []) { Chris@16: // Don't try to continue if there are errors. Chris@16: if (strpos($this->getTextContent(), 'Errors found') !== FALSE) { Chris@16: return; Chris@16: } Chris@16: // Allow only details elements that are directly after the warning header Chris@16: // or each other. There is no guaranteed wrapper we can rely on across Chris@16: // distributions. When there are multiple warnings, the selectors will be: Chris@16: // - h3#warning+details summary Chris@16: // - h3#warning+details+details summary Chris@16: // - etc. Chris@16: // We add one more selector than expected warnings to confirm that there Chris@16: // isn't any other warning before clicking the link. Chris@16: // @todo Make this more reliable in Chris@16: // https://www.drupal.org/project/drupal/issues/2927345. Chris@16: $selectors = []; Chris@16: for ($i = 0; $i <= count($expected_warnings); $i++) { Chris@16: $selectors[] = 'h3#warning' . implode('', array_fill(0, $i + 1, '+details')) . ' summary'; Chris@16: } Chris@16: $warning_elements = $this->cssSelect(implode(', ', $selectors)); Chris@16: Chris@16: // Confirm that there are only the expected warnings. Chris@16: $warnings = []; Chris@16: foreach ($warning_elements as $warning) { Chris@16: $warnings[] = trim($warning->getText()); Chris@16: } Chris@16: $this->assertEquals($expected_warnings, $warnings); Chris@16: $this->clickLink('continue anyway'); Chris@16: $this->checkForMetaRefresh(); Chris@16: } Chris@16: Chris@16: }