Issue #3087862 by heddn: TestSiteInstallCommand doesn't work with build tests
(cherry picked from commit 16097ece55
)
merge-requests/2809/head
parent
9cfe94efe8
commit
ec5cf9f6de
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\BuildTests\TestSiteApplication;
|
||||
|
||||
use Drupal\BuildTests\Framework\BuildTestBase;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
|
||||
/**
|
||||
* @group Build
|
||||
* @group TestSiteApplication
|
||||
*/
|
||||
class InstallTest extends BuildTestBase {
|
||||
|
||||
public function testInstall() {
|
||||
$this->copyCodebase();
|
||||
$fs = new Filesystem();
|
||||
$fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000);
|
||||
|
||||
// Composer tells you stuff in error output.
|
||||
$this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-interaction');
|
||||
$this->assertErrorOutputContains('Generating autoload files');
|
||||
|
||||
// We have to stand up the server first so we can know the port number to
|
||||
// pass along to the install command.
|
||||
$this->standUpServer();
|
||||
|
||||
$php_finder = new PhpExecutableFinder();
|
||||
$install_command = [
|
||||
$php_finder->find(),
|
||||
'./core/scripts/test-site.php',
|
||||
'install',
|
||||
'--base-url=http://localhost:' . $this->getPortNumber(),
|
||||
'--db-url=sqlite://localhost/foo.sqlite',
|
||||
'--install-profile=minimal',
|
||||
'--json',
|
||||
];
|
||||
$this->assertNotEmpty($output_json = $this->executeCommand(implode(' ', $install_command))->getOutput());
|
||||
$this->assertCommandSuccessful();
|
||||
$connection_details = json_decode($output_json, TRUE);
|
||||
foreach (['db_prefix', 'user_agent', 'site_path'] as $key) {
|
||||
$this->assertArrayHasKey($key, $connection_details);
|
||||
}
|
||||
|
||||
// Visit paths with expectations.
|
||||
$this->visit();
|
||||
$this->assertDrupalVisit();
|
||||
}
|
||||
|
||||
}
|
|
@ -14,6 +14,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
|||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
/**
|
||||
* Command to create a test Drupal site.
|
||||
|
@ -120,6 +121,18 @@ class TestSiteInstallCommand extends Command {
|
|||
// Manage site fixture.
|
||||
$this->setup($input->getOption('install-profile'), $class_name, $input->getOption('langcode'));
|
||||
|
||||
// Make sure there is an entry in sites.php for the new site.
|
||||
$fs = new Filesystem();
|
||||
if (!$fs->exists($root . '/sites/sites.php')) {
|
||||
$fs->copy($root . '/sites/example.sites.php', $root . '/sites/sites.php');
|
||||
}
|
||||
$parsed = parse_url($base_url);
|
||||
$port = $parsed['port'] ?? 80;
|
||||
$host = $parsed['host'] ?? 'localhost';
|
||||
// Remove 'sites/' from the beginning of the path.
|
||||
$site_path = substr($this->siteDirectory, 6);
|
||||
$fs->appendToFile($root . '/sites/sites.php', "\$sites['$port.$host'] = '$site_path';");
|
||||
|
||||
$user_agent = drupal_generate_test_ua($this->databasePrefix);
|
||||
if ($input->getOption('json')) {
|
||||
$output->writeln(json_encode([
|
||||
|
|
Loading…
Reference in New Issue