function QuickStartTest::testQuickStartInstallAndServerCommands
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Command/QuickStartTest.php \Drupal\Tests\Core\Command\QuickStartTest::testQuickStartInstallAndServerCommands()
- 8.9.x core/tests/Drupal/Tests/Core/Command/QuickStartTest.php \Drupal\Tests\Core\Command\QuickStartTest::testQuickStartInstallAndServerCommands()
- 10 core/tests/Drupal/Tests/Core/Command/QuickStartTest.php \Drupal\Tests\Core\Command\QuickStartTest::testQuickStartInstallAndServerCommands()
Tests the quick-start commands.
File
-
core/
tests/ Drupal/ Tests/ Core/ Command/ QuickStartTest.php, line 146
Class
- QuickStartTest
- Tests the quick-start commands.
Namespace
Drupal\Tests\Core\CommandCode
public function testQuickStartInstallAndServerCommands() : void {
$sqlite = (new \PDO('sqlite::memory:'))->query('select sqlite_version()')
->fetch()[0];
if (version_compare($sqlite, Tasks::SQLITE_MINIMUM_VERSION) < 0) {
$this->markTestSkipped();
}
// Install a site.
$install_command = [
$this->php,
'core/scripts/drupal',
'install',
'testing',
"--password='secret'",
"--site-name='Test site {$this->testDb->getDatabasePrefix()}'",
];
$install_process = new Process($install_command, NULL, [
'DRUPAL_DEV_SITE_PATH' => $this->testDb
->getTestSitePath(),
]);
$install_process->setTimeout(500);
$result = $install_process->run();
// The progress bar uses STDERR to write messages.
$this->assertStringContainsString('Congratulations, you installed Drupal!', $install_process->getErrorOutput());
$this->assertStringContainsString("Password: 'secret'", $install_process->getOutput());
$this->assertSame(0, $result);
// Run the PHP built-in webserver.
$server_command = [
$this->php,
'core/scripts/drupal',
'server',
'--suppress-login',
];
$server_process = new Process($server_command, NULL, [
'DRUPAL_DEV_SITE_PATH' => $this->testDb
->getTestSitePath(),
]);
$server_process->start();
$guzzle = new Client();
$port = FALSE;
$server_process->waitUntil(function ($type, $output) use (&$port) {
if (preg_match('/127.0.0.1:(\\d+)\\/user\\/reset\\/1\\//', $output, $match)) {
$port = $match[1];
return TRUE;
}
});
$this->assertEquals('', $server_process->getErrorOutput());
$this->assertStringContainsString("127.0.0.1:{$port}/user/reset/1/", $server_process->getOutput());
$this->assertNotFalse($port, "Web server running on port {$port}");
// Give the server a couple of seconds to be ready.
sleep(2);
// Generate a cookie so we can make a request against the installed site.
define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
chmod($this->testDb
->getTestSitePath(), 0755);
$cookieJar = CookieJar::fromArray([
'SIMPLETEST_USER_AGENT' => drupal_generate_test_ua($this->testDb
->getDatabasePrefix()),
], '127.0.0.1');
$response = $guzzle->get('http://127.0.0.1:' . $port, [
'cookies' => $cookieJar,
]);
$content = (string) $response->getBody();
$this->assertStringContainsString('Test site ' . $this->testDb
->getDatabasePrefix(), $content);
// Try to re-install over the top of an existing site.
$install_command = [
$this->php,
'core/scripts/drupal',
'install',
'testing',
"--site-name='Test another site {$this->testDb->getDatabasePrefix()}'",
];
$install_process = new Process($install_command, NULL, [
'DRUPAL_DEV_SITE_PATH' => $this->testDb
->getTestSitePath(),
]);
$install_process->setTimeout(500);
$result = $install_process->run();
$this->assertStringContainsString('Drupal is already installed.', $install_process->getOutput());
$this->assertSame(0, $result);
// Ensure the site name has not changed.
$response = $guzzle->get('http://127.0.0.1:' . $port, [
'cookies' => $cookieJar,
]);
$content = (string) $response->getBody();
$this->assertStringContainsString('Test site ' . $this->testDb
->getDatabasePrefix(), $content);
// Stop the web server.
$server_process->stop();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.