243,419d242 < diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php < index 77e6ef7e1e..a0e08cc1d0 100644 < --- a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php < +++ b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php < @@ -6,6 +6,7 @@ < use Drupal\Core\Test\FunctionalTestSetupTrait; < use Drupal\Core\Test\TestDatabase; < use Drupal\Core\Test\TestSetupTrait; < +use Drupal\TestSite\TestPreinstallInterface; < use Drupal\TestSite\TestSetupInterface; < use Drupal\Tests\RandomGeneratorTrait; < use Symfony\Component\Console\Command\Command; < @@ -66,13 +67,13 @@ protected function configure() { < $this->setName('install') < ->setDescription('Creates a test Drupal site') < ->setHelp('The details to connect to the test site created will be displayed upon success. It will contain the database prefix and the user agent.') < - ->addOption('setup-file', NULL, InputOption::VALUE_OPTIONAL, 'The path to a PHP file containing a class to setup configuration used by the test, for example, core/tests/Drupal/TestSite/TestSiteInstallTestScript.php.') < + ->addOption('setup-file', NULL, InputOption::VALUE_OPTIONAL, 'The path to a PHP file containing a class to setup configuration used by the test, for example, core/tests/Drupal/TestSite/TestSiteMultilingualInstallTestScript.php.') < ->addOption('db-url', NULL, InputOption::VALUE_OPTIONAL, 'URL for database. Defaults to the environment variable SIMPLETEST_DB.', getenv('SIMPLETEST_DB')) < ->addOption('base-url', NULL, InputOption::VALUE_OPTIONAL, 'Base URL for site under test. Defaults to the environment variable SIMPLETEST_BASE_URL.', getenv('SIMPLETEST_BASE_URL')) < ->addOption('install-profile', NULL, InputOption::VALUE_OPTIONAL, 'Install profile to install the site in. Defaults to testing.', 'testing') < ->addOption('langcode', NULL, InputOption::VALUE_OPTIONAL, 'The language to install the site in. Defaults to en.', 'en') < ->addOption('json', NULL, InputOption::VALUE_NONE, 'Output test site connection details in JSON.') < - ->addUsage('--setup-file core/tests/Drupal/TestSite/TestSiteInstallTestScript.php --json') < + ->addUsage('--setup-file core/tests/Drupal/TestSite/TestSiteMultilingualInstallTestScript.php --json') < ->addUsage('--install-profile demo_umami --langcode fr') < ->addUsage('--base-url "http://example.com" --db-url "mysql://username:password@localhost/databasename#table_prefix"'); < } < @@ -129,7 +130,8 @@ protected function execute(InputInterface $input, OutputInterface $output) { < * < * @throws \InvalidArgumentException < * Thrown if the file does not exist, does not contain a class or the class < - * does not implement \Drupal\TestSite\TestSetupInterface. < + * does not implement \Drupal\TestSite\TestSetupInterface or < + * \Drupal\TestSite\TestPreinstallInterface. < */ < protected function getSetupClass($file) { < if ($file === NULL) { < @@ -147,8 +149,8 @@ protected function getSetupClass($file) { < } < $class = array_pop($new_classes); < < - if (!is_subclass_of($class, TestSetupInterface::class)) { < - throw new \InvalidArgumentException("The class $class contained in $file needs to implement \Drupal\TestSite\TestSetupInterface"); < + if (!is_subclass_of($class, TestSetupInterface::class) && !is_subclass_of($class, TestPreinstallInterface::class)) { < + throw new \InvalidArgumentException("The class $class contained in $file needs to implement \Drupal\TestSite\TestSetupInterface or \Drupal\TestSite\TestPreinstallInterface"); < } < return $class; < } < @@ -183,11 +185,9 @@ public function setup($profile = 'testing', $setup_class = NULL, $langcode = 'en < $this->langcode = $langcode; < $this->setupBaseUrl(); < $this->prepareEnvironment(); < + $this->executePreinstallClass($setup_class); < $this->installDrupal(); < - < - if ($setup_class) { < - $this->executeSetupClass($setup_class); < - } < + $this->executeSetupClass($setup_class); < } < < /** < @@ -216,9 +216,29 @@ protected function installDrupal() { < * @see \Drupal\TestSite\TestSetupInterface < */ < protected function executeSetupClass($class) { < - /** @var \Drupal\TestSite\TestSetupInterface $instance */ < - $instance = new $class(); < - $instance->setup(); < + if (is_subclass_of($class, TestSetupInterface::class)) { < + /** @var \Drupal\TestSite\TestSetupInterface $instance */ < + $instance = new $class(); < + $instance->setup(); < + } < + } < + < + /** < + * Uses the setup file to configure the environment prior to install. < + * < + * @param string $class < + * The fully qualified class name, which should set up the environment prior < + * to installing Drupal for tests. For example this class could create < + * translations that are used during the installer. < + * < + * @see \Drupal\TestSite\TestPreinstallInterface < + */ < + protected function executePreinstallClass($class) { < + if (is_subclass_of($class, TestPreinstallInterface::class)) { < + /** @var \Drupal\TestSite\TestPreinstallInterface $instance */ < + $instance = new $class(); < + $instance->preinstall($this->databasePrefix, $this->siteDirectory); < + } < } < < /** < diff --git a/core/tests/Drupal/TestSite/TestPreinstallInterface.php b/core/tests/Drupal/TestSite/TestPreinstallInterface.php < new file mode 100644 < index 0000000000..e209fd0142 < --- /dev/null < +++ b/core/tests/Drupal/TestSite/TestPreinstallInterface.php < @@ -0,0 +1,28 @@ < +install(['test_page_test']); < + } < + < +} < diff --git a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php < index 4f7b39bdf2..2762b8c68d 100644 < --- a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php < +++ b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php < @@ -211,7 +211,7 @@ public function testInstallInDifferentLanguage() { < $this->markTestSkipped("Requires the directory $simpletest_path to exist and be writable"); < } < < - $command_line = $this->php . ' core/scripts/test-site.php install --json --langcode fr --setup-file core/tests/Drupal/TestSite/TestSiteInstallTestScript.php --db-url "' . getenv('SIMPLETEST_DB') . '"'; < + $command_line = $this->php . ' core/scripts/test-site.php install --json --langcode fr --setup-file core/tests/Drupal/TestSite/TestSiteMultilingualInstallTestScript.php --db-url "' . getenv('SIMPLETEST_DB') . '"'; < $process = new Process($command_line, $this->root); < $process->setTimeout(500); < $process->run();