You are here

public function QuickStartTest::testQuickStartCommand in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Command/QuickStartTest.php \Drupal\Tests\Core\Command\QuickStartTest::testQuickStartCommand()

Tests the quick-start command.

File

core/tests/Drupal/Tests/Core/Command/QuickStartTest.php, line 87

Class

QuickStartTest
Tests the quick-start commands.

Namespace

Drupal\Tests\Core\Command

Code

public function testQuickStartCommand() {
  if (version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) < 0) {
    $this
      ->markTestSkipped();
  }
  if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) {
    $this
      ->markTestSkipped();
  }

  // Install a site using the standard profile to ensure the one time login
  // link generation works.
  $install_command = [
    $this->php,
    'core/scripts/drupal',
    'quick-start',
    'standard',
    "--site-name='Test site {$this->testDb->getDatabasePrefix()}'",
    '--suppress-login',
  ];
  $process = new Process($install_command, NULL, [
    'DRUPAL_DEV_SITE_PATH' => $this->testDb
      ->getTestSitePath(),
  ]);
  $process
    ->setTimeout(500);
  $process
    ->start();
  $guzzle = new Client();
  $port = FALSE;
  while ($process
    ->isRunning()) {
    if (preg_match('/127.0.0.1:(\\d+)/', $process
      ->getOutput(), $match)) {
      $port = $match[1];
      break;
    }

    // Wait for more output.
    sleep(1);
  }

  // The progress bar uses STDERR to write messages.
  $this
    ->assertStringContainsString('Congratulations, you installed Drupal!', $process
    ->getErrorOutput());
  $this
    ->assertNotFalse($port, "Web server running on port {$port}");

  // Give the server a couple of seconds to be ready.
  sleep(2);
  $this
    ->assertStringContainsString("127.0.0.1:{$port}/user/reset/1/", $process
    ->getOutput());

  // 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);

  // Stop the web server.
  $process
    ->stop();
}