diff --git a/src/Commands/core/SiteInstallCommands.php b/src/Commands/core/SiteInstallCommands.php index ba1f9b6f38..b64bf7e471 100644 --- a/src/Commands/core/SiteInstallCommands.php +++ b/src/Commands/core/SiteInstallCommands.php @@ -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, diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 84f42d0882..a7cc16f9c2 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -2,6 +2,8 @@ namespace Unish; +use Composer\Semver\Comparator; + /** * Tests for Configuration Management commands for D8+. * @group commands @@ -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'); @@ -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']); @@ -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); @@ -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.'); + } } } diff --git a/tests/UnishTestCase.php b/tests/UnishTestCase.php index 9a30848598..593cfe3cbe 100644 --- a/tests/UnishTestCase.php +++ b/tests/UnishTestCase.php @@ -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'; } } @@ -537,7 +538,7 @@ 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); @@ -545,7 +546,7 @@ public function setUpDrupal($num_sites = 1, $install = false) // 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+. @@ -590,7 +591,7 @@ 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; @@ -598,14 +599,14 @@ public function installDrupal($env = 'dev', $install = false) // 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 {