Skip to content
Snippets Groups Projects
Commit 8556a4d5 authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3088135 by alexpott, mikelutz, Wim Leers, Berdir, heddn:...

Issue #3088135 by alexpott, mikelutz, Wim Leers, Berdir, heddn: TestSiteApplicationTest::testInstallInDifferentLanguage requires localize.drupal.org
parent 5ed00496
No related branches found
No related tags found
6 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards
......@@ -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);
}
}
/**
......
<?php
namespace Drupal\TestSite;
/**
* Allows running code prior to a test site install.
*
* @see \Drupal\TestSite\Commands\TestSiteInstallCommand
*/
interface TestPreinstallInterface {
/**
* Runs code prior to a test site install.
*
* This method is run after FunctionalTestSetupTrait::prepareEnvironment()
* but before Drupal is installed. As such, there is limited setup of the
* environment and no Drupal API is available.
*
* @param string $db_prefix
* The database prefix.
* @param string $site_directory
* The site directory.
*
* @see \Drupal\TestSite\TestSiteInstallTestScript
*/
public function preinstall($db_prefix, $site_directory);
}
<?php
namespace Drupal\TestSite;
/**
* Setup file used by TestSiteApplicationTest.
*
* @see \Drupal\Tests\Scripts\TestSiteApplicationTest
*/
class TestSiteMultilingualInstallTestScript implements TestSetupInterface, TestPreinstallInterface {
/**
* {@inheritdoc}
*/
public function preinstall($db_prefix, $site_directory) {
// Place a custom local translation in the translations directory.
mkdir($site_directory . '/files/translations', 0777, TRUE);
file_put_contents($site_directory . '/files/translations/drupal-8.0.0.fr.po', "msgid \"\"\nmsgstr \"\"\nmsgid \"Save and continue\"\nmsgstr \"Enregistrer et continuer\"");
}
/**
* {@inheritdoc}
*/
public function setup() {
\Drupal::service('module_installer')->install(['test_page_test']);
}
}
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment