Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Commands/core/SiteInstallCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public function install(array $profile, $options = ['db-url' => self::REQ, 'db-p
$db_spec = $sql->getDbSpec();

$account_pass = $options['account-pass'] ?: StringUtils::generatePassword();

// Was giving error during validate() so its here for now.
if ($options['existing-config']) {
$existing_config_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
if (!is_dir($existing_config_dir)) {
throw new \Exception(dt('Existing config directory @dir not found', ['@dir' => $existing_config_dir]));
}
$this->logger()->info(dt('Installing from existing config at @dir', ['@dir' => $existing_config_dir]));
}

$settings = [
'parameters' => [
'profile' => $profile,
Expand Down
36 changes: 26 additions & 10 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Unish;

use Composer\Semver\Comparator;

/**
* Tests for Configuration Management commands for D8+.
* @group commands
Expand All @@ -14,24 +16,25 @@ public function setUp()
{
if (!$this->getSites()) {
$this->setUpDrupal(1, true);
$this->drush('pm-enable', ['config']);
// Field module is needed for now for --existing-config. It is not actually
// enabled after testing profile is installed. Its required by file and update though.
$this->drush('pm:enable', ['config, field']);
}
}

public function testConfigGetSet()
{
$this->drush('config-set', ['system.site', 'name', 'config_test']);
$this->drush('config-get', ['system.site', 'name']);
$this->drush('config:set', ['system.site', 'name', 'config_test']);
$this->drush('config:get', ['system.site', 'name']);
$this->assertEquals("'system.site:name': config_test", $this->getOutput(), 'Config was successfully set and get.');
}

public function testConfigExportImportStatus()
public function testConfigExportImportStatusExistingConfig()
{
// Get path to sync dir.
$this->drush('core-status', [], ['format' => 'json', 'fields' => 'config-sync']);
$this->drush('core:status', [], ['format' => 'json', 'fields' => 'config-sync']);
$sync = $this->webroot() . '/' . $this->getOutputFromJSON('config-sync');
$system_site_yml = $sync . '/system.site.yml';
$core_extension_yml = $sync . '/core.extension.yml';

// Test export.
$this->drush('config-export');
Expand All @@ -40,12 +43,12 @@ public function testConfigExportImportStatus()
// Test import and status by finishing the round trip.
$contents = file_get_contents($system_site_yml);
$contents = preg_replace('/front: .*/', 'front: unish', $contents);
$contents = file_put_contents($system_site_yml, $contents);
file_put_contents($system_site_yml, $contents);

// Test status of changed configuration.
$this->drush('config:status');
$this->assertContains('system.site', $this->getOutput(), 'config:status correctly reports changes.');

// Test import.
$this->drush('config-import');
$this->drush('config-get', ['system.site', 'page'], ['format' => 'json']);
Expand All @@ -55,7 +58,7 @@ public function testConfigExportImportStatus()
// Test status of identical configuration.
$this->drush('config:status', [], ['format' => 'list']);
$this->assertEquals('', $this->getOutput(), 'config:status correctly reports identical config.');

// Similar, but this time via --partial option.
$contents = file_get_contents($system_site_yml);
$contents = preg_replace('/front: .*/', 'front: unish partial', $contents);
Expand All @@ -66,5 +69,18 @@ public function testConfigExportImportStatus()
$this->drush('config-get', ['system.site', 'page'], ['format' => 'json']);
$page = $this->getOutputFromJSON('system.site:page');
$this->assertContains('unish partial', $page->front, '--partial was successfully imported.');

// Test the --existing-config option for site:install.
$this->drush('core:status', ['drupal-version'], ['format' => 'string']);
$drupal_version = $this->getOutputRaw();
if (Comparator::greaterThanOrEqualTo($drupal_version, '8.6')) {
$contents = file_get_contents($system_site_yml);
$contents = preg_replace('/front: .*/', 'front: unish existing', $contents);
file_put_contents($system_site_yml, $contents);
$this->setUpDrupal(1, true, ['existing-config' => null]);
$this->drush('config-get', ['system.site', 'page'], ['format' => 'json']);
$page = $this->getOutputFromJSON('system.site:page');
$this->assertContains('unish existing', $page->front, 'Existing config was successfully imported during site:install.');
}
}
}
25 changes: 13 additions & 12 deletions tests/UnishTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,11 @@ public function log($message, $type = 'notice')

public function logLevel()
{
$argv = $_SERVER['argv'];
// -d is reserved by `phpunit`
if (in_array('--debug', $_SERVER['argv'])) {
if (in_array(['--debug'], $argv) || in_array('-vvv', $argv)) {
return 'debug';
} elseif (in_array('--verbose', $_SERVER['argv']) || in_array('-v', $_SERVER['argv'])) {
} elseif (in_array('--verbose', $argv) || in_array('-v', $argv)) {
return 'verbose';
}
}
Expand Down Expand Up @@ -537,15 +538,15 @@ public function createSettings($subdir)
*
* It is no longer supported to pass alternative versions of Drupal or an alternative install_profile.
*/
public function setUpDrupal($num_sites = 1, $install = false)
public function setUpDrupal($num_sites = 1, $install = false, $options = [])
{
$sites_subdirs_all = ['dev', 'stage', 'prod', 'retired', 'elderly', 'dead', 'dust'];
$sites_subdirs = array_slice($sites_subdirs_all, 0, $num_sites);
$root = $this->webroot();

// Install (if needed).
foreach ($sites_subdirs as $subdir) {
$this->installDrupal($subdir, $install);
$this->installDrupal($subdir, $install, $options);
}

// Write an empty sites.php. Needed for multi-site on D8+.
Expand Down Expand Up @@ -590,22 +591,22 @@ public function createAliasFile($sites_subdirs, $aliasGroup = 'unish')
*
* It is no longer supported to pass alternative versions of Drupal or an alternative install_profile.
*/
public function installDrupal($env = 'dev', $install = false)
public function installDrupal($env = 'dev', $install = false, $options = [])
{
$root = $this->webroot();
$uri = $env;
$site = "$root/sites/$uri";

// If specified, install Drupal as a multi-site.
if ($install) {
$options = [
'root' => $root,
'db-url' => $this->dbUrl($env),
'sites-subdir' => $uri,
'yes' => null,
'quiet' => null,
$options += [
'root' => $root,
'db-url' => $this->dbUrl($env),
'sites-subdir' => $uri,
'yes' => null,
'quiet' => null,
];
$this->drush('site-install', ['testing', 'install_configure_form.enable_update_status_emails=NULL'], $options);
$this->drush('site:install', ['testing', 'install_configure_form.enable_update_status_emails=NULL'], $options);
// Give us our write perms back.
chmod($site, 0777);
} else {
Expand Down