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@18: // Do nothing. 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: }