diff --git a/core/tests/Drupal/KernelTests/Setup/Commands/SetupDrupalTestScriptTest.php b/core/tests/Drupal/KernelTests/Setup/Commands/SetupDrupalTestScriptTest.php index b8236f9b3f..7af4c369bc 100644 --- a/core/tests/Drupal/KernelTests/Setup/Commands/SetupDrupalTestScriptTest.php +++ b/core/tests/Drupal/KernelTests/Setup/Commands/SetupDrupalTestScriptTest.php @@ -16,6 +16,11 @@ * * @todo Move this to the \Drupal\KernelTests\Setup\Commands\ namespace after * https://www.drupal.org/project/drupal/issues/2878269 + * + * @see \Drupal\Setup\TestInstallationSetup + * @see \Drupal\Setup\Commands\TestInstallationSetupApplication + * @see \Drupal\Setup\Commands\TestInstallationSetupCommand + * @see \Drupal\Setup\Commands\TestTeardownCommand */ class SetupDrupalTestScriptTest extends KernelTestBase { @@ -91,18 +96,71 @@ public function testInstallScript() { ] ); + + $this->assertNotRegExp('/PHPUnit_Framework_Error_Warning/', $app_tester->getDisplay()); + $this->assertNotRegExp('/AlreadyInstalledException/', $app_tester->getDisplay()); + + $result = json_decode($app_tester->getDisplay(), TRUE); + $db_prefix = substr($result['db_prefix'], 4); + $this->assertNotEmpty($db_prefix); + $this->assertStringStartsWith('simpletest' . $db_prefix . ':', $result['user_agent']); + + $this->assertEqual(0, $app_tester->getStatusCode()); + + $http_client = new Client(); + $request = (new Request('GET', getenv('SIMPLETEST_BASE_URL') . '/test-page')) + ->withHeader('User-Agent', trim($result['user_agent'])); + + $response = $http_client->send($request); + // Ensure the test_page_test module got installed. + $this->assertContains('Test page | Drupal', (string) $response->getBody()); + + // Now test the tear down process as well. + $app_tester->run( + [ + 'command' => 'teardown-drupal-test', + 'db_prefix' => $this->databasePrefix, + ], + [ + 'interactive' => FALSE, + ] + ); + } + + /** + * @coversNothing + */ + public function testInstallInDifferentLanguage() { + $autoloader = $this->root . '/autoload.php'; + $app = new TestInstallationSetupApplication(require $autoloader); + $app->setAutoExit(FALSE); + + $app_tester = new ApplicationTester($app); + $app_tester->run( + [ + 'command' => 'setup-drupal-test', + '--langcode' => 'fr', + '--setup_class' => SetupDrupalTestScript::class, + ], + [ + 'interactive' => FALSE, + ] + ); + + $this->assertNotRegExp('/PHPUnit_Framework_Error_Warning/', $app_tester->getDisplay()); $this->assertNotRegExp('/AlreadyInstalledException/', $app_tester->getDisplay()); - $this->assertRegExp('/simpletest/', $app_tester->getDisplay()); $this->assertEqual(0, $app_tester->getStatusCode()); + $result = json_decode($app_tester->getDisplay(), TRUE); $http_client = new Client(); $request = (new Request('GET', getenv('SIMPLETEST_BASE_URL') . '/test-page')) - ->withHeader('User-Agent', trim($app_tester->getDisplay())); + ->withHeader('User-Agent', trim($result['user_agent'])); $response = $http_client->send($request); // Ensure the test_page_test module got installed. $this->assertContains('Test page | Drupal', (string) $response->getBody()); + $this->assertContains('lang="fr"', (string) $response->getBody()); // Now test the tear down process as well. $app_tester->run( diff --git a/core/tests/Drupal/Setup/Commands/TestInstallationSetupCommand.php b/core/tests/Drupal/Setup/Commands/TestInstallationSetupCommand.php index 325537db5e..f14bee5276 100644 --- a/core/tests/Drupal/Setup/Commands/TestInstallationSetupCommand.php +++ b/core/tests/Drupal/Setup/Commands/TestInstallationSetupCommand.php @@ -47,7 +47,9 @@ protected function configure() { $this->setName('setup-drupal-test') ->addOption('setup_class', NULL, InputOption::VALUE_OPTIONAL) ->addOption('db_url', NULL, InputOption::VALUE_OPTIONAL, 'URL for database or SIMPLETEST_DB', getenv('SIMPLETEST_DB')) - ->addOption('base_url', NULL, InputOption::VALUE_OPTIONAL, 'Base URL for site under test or SIMPLETEST_BASE_URL', getenv('SIMPLETEST_BASE_URL')); + ->addOption('base_url', NULL, InputOption::VALUE_OPTIONAL, 'Base URL for site under test or SIMPLETEST_BASE_URL', getenv('SIMPLETEST_BASE_URL')) + ->addOption('langcode', NULL, InputOption::VALUE_OPTIONAL, 'The language to install the site in.') + ; } /** @@ -63,9 +65,12 @@ protected function execute(InputInterface $input, OutputInterface $output) { // Manage site fixture. $test = new TestInstallationSetup(); - $test->setup('testing', $input->getOption('setup_class')); + $test->setup('testing', $input->getOption('setup_class'), $input->getOption('langcode')); - $output->writeln(drupal_generate_test_ua($test->getDatabasePrefix())); + $output->writeln(json_encode([ + 'db_prefix' => $test->getDatabasePrefix(), + 'user_agent' => drupal_generate_test_ua($test->getDatabasePrefix()), + ])); } protected function bootstrapDrupal() { diff --git a/core/tests/Drupal/Setup/TestInstallationSetup.php b/core/tests/Drupal/Setup/TestInstallationSetup.php index 4e816c1c06..25d33d530d 100644 --- a/core/tests/Drupal/Setup/TestInstallationSetup.php +++ b/core/tests/Drupal/Setup/TestInstallationSetup.php @@ -42,6 +42,14 @@ class TestInstallationSetup { */ protected $databasePrefix; + + /** + * The language to install the site in. + * + * @var string + */ + protected $langcode = 'en'; + /** * Creates a test drupal installation. * @@ -50,9 +58,12 @@ class TestInstallationSetup { * @param string $setup_class * (optional) Setup class. A PHP class to setup configuration used by the * test. + * @param string $langcode + * (optional) The language to install the site in. */ - public function setup($profile = 'testing', $setup_class = NULL) { + public function setup($profile = 'testing', $setup_class = NULL, $langcode = 'en') { $this->profile = $profile; + $this->langcode = $langcode; $this->setupBaseUrl(); $this->prepareEnvironment(); $this->installDrupal(); @@ -161,7 +172,7 @@ protected function installParameters() { 'interactive' => FALSE, 'parameters' => [ 'profile' => $this->profile, - 'langcode' => 'en', + 'langcode' => $this->langcode, ], 'forms' => [ 'install_settings_form' => [