diff --git a/core/scripts/setup-drupal-test.php b/core/scripts/setup-drupal-test.php index 44b0f9eaf1..94e6b9c2d3 100644 --- a/core/scripts/setup-drupal-test.php +++ b/core/scripts/setup-drupal-test.php @@ -6,10 +6,7 @@ * A command line application to install drupal for tests. */ -use Drupal\Core\DrupalKernel; -use Drupal\Core\Site\Settings; use Drupal\Setup\Commands\TestInstallationSetupApplication; -use Symfony\Component\HttpFoundation\Request; if (PHP_SAPI !== 'cli') { return; @@ -17,15 +14,8 @@ // Bootstrap. $autoloader = require __DIR__ . '/../../autoload.php'; - -$request = Request::createFromGlobals(); -$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'testing'); -DrupalKernel::bootEnvironment($kernel->getAppRoot()); - -Settings::initialize(dirname(dirname(__DIR__)), - DrupalKernel::findSitePath($request), $autoloader); - require_once __DIR__ . '/../tests/bootstrap.php'; -(new TestInstallationSetupApplication()) - ->run(); +$app = new TestInstallationSetupApplication(); +$app->setAutoloader($autoloader); +$app->run(); diff --git a/core/tests/Drupal/FunctionalTests/SetupDrupalTestScriptTest.php b/core/tests/Drupal/FunctionalTests/SetupDrupalTestScriptTest.php deleted file mode 100644 index 4c5adf5a4e..0000000000 --- a/core/tests/Drupal/FunctionalTests/SetupDrupalTestScriptTest.php +++ /dev/null @@ -1,30 +0,0 @@ - __DIR__ . '/SetupDrupalTestScript.php', - ]; - $app_tester = new ApplicationTester($app); - $output = $app_tester->run([ - 'command' => 'run', - ], $options); - $a = 123; - $this->assertTrue(FALSE); - } - -} diff --git a/core/tests/Drupal/Setup/Commands/TestInstallationSetupApplication.php b/core/tests/Drupal/Setup/Commands/TestInstallationSetupApplication.php index 312d3db757..94b42c6ec9 100644 --- a/core/tests/Drupal/Setup/Commands/TestInstallationSetupApplication.php +++ b/core/tests/Drupal/Setup/Commands/TestInstallationSetupApplication.php @@ -12,11 +12,13 @@ */ class TestInstallationSetupApplication extends Application { + protected $autoloader; + /** * SetupDrupalApplication constructor. */ public function __construct() { - parent::__construct('setup-drupal-test', '1.0.0'); + parent::__construct('setup-drupal-test', '0.0.1'); } /** @@ -36,4 +38,13 @@ protected function getDefaultCommands() { return $default_commands; } + public function setAutoloader($autoloader) { + $this->autoloader = $autoloader; + return $this; + } + + public function getAutoloader() { + return $this->autoloader; + } + } diff --git a/core/tests/Drupal/Setup/Commands/TestInstallationSetupCommand.php b/core/tests/Drupal/Setup/Commands/TestInstallationSetupCommand.php index 43704b1723..49fdafa1e2 100644 --- a/core/tests/Drupal/Setup/Commands/TestInstallationSetupCommand.php +++ b/core/tests/Drupal/Setup/Commands/TestInstallationSetupCommand.php @@ -2,11 +2,14 @@ namespace Drupal\Setup\Commands; +use Drupal\Core\DrupalKernel; +use Drupal\Core\Site\Settings; use Drupal\Setup\TestInstallationSetup; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\HttpFoundation\Request; /** * Symfony console command to setup Drupal. @@ -21,23 +24,38 @@ class TestInstallationSetupCommand extends Command { protected function configure() { $this->setName('setup-drupal-test') ->addOption('setup_file', NULL, InputOption::VALUE_OPTIONAL) - ->addOption('db_url', NULL, InputOption::VALUE_OPTIONAL, '', getenv('SIMPLETEST_DB')) - ->addOption('base_url', NULL, InputOption::VALUE_OPTIONAL, '', getenv('SIMPLETEST_BASE_URL')); + ->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')); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { - $test = new TestInstallationSetup(); - $test->setup('testing', $input->getOption('setup_file')); - $db_url = $input->getOption('db_url'); $base_url = $input->getOption('base_url'); putenv("SIMPLETEST_DB=$db_url"); putenv("SIMPLETEST_BASE_URL=$base_url"); + $this->bootstrapDrupal($this->getApplication()->getAutoloader()); + + // Manage site fixture. + $test = new TestInstallationSetup(); + $test->setup('testing', $input->getOption('setup_file')); + $output->writeln(drupal_generate_test_ua($test->getDatabasePrefix())); } + protected function bootstrapDrupal($autoloader) { + $request = Request::createFromGlobals(); + $kernel = DrupalKernel::createFromRequest($request, $autoloader, $this->getApplication()->getName()); + DrupalKernel::bootEnvironment($kernel->getAppRoot()); + + Settings::initialize( + dirname(dirname(dirname(dirname(__DIR__)))), + DrupalKernel::findSitePath($request), + $autoloader + ); + } + } diff --git a/core/tests/Drupal/FunctionalTests/SetupDrupalTestScript.php b/core/tests/Drupal/Tests/Setup/Commands/SetupDrupalTestScript.php similarity index 89% rename from core/tests/Drupal/FunctionalTests/SetupDrupalTestScript.php rename to core/tests/Drupal/Tests/Setup/Commands/SetupDrupalTestScript.php index badf721745..7162e20623 100644 --- a/core/tests/Drupal/FunctionalTests/SetupDrupalTestScript.php +++ b/core/tests/Drupal/Tests/Setup/Commands/SetupDrupalTestScript.php @@ -1,6 +1,6 @@ setAutoExit(FALSE); + + $app_tester = new ApplicationTester($app); + $output = $app_tester->run( + ['command' => 'setup-drupal-test'], + [ + 'interactive' => FALSE, + 'setup_file' => __DIR__ . '/SetupDrupalTestScript.php', + ] + ); + + $this->assertEquals(0, $output); + $this->assertNotRegExp('/AlreadyInstalledException/', $app_tester->getDisplay()); + $this->assertRegExp('/simpletest/', $app_tester->getDisplay()); + } + +}