From ed87f1d7d6c6a8a684c36acf1081203e97b70acf Mon Sep 17 00:00:00 2001 From: D Vargas Date: Tue, 3 Sep 2019 16:05:29 +0200 Subject: [PATCH 01/15] OPENEUROPA-2155: Add dev option to settings setup command. --- src/Commands/AbstractDrupalCommands.php | 6 ++++-- src/Commands/Drupal8Commands.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 28e1592d..ae80187f 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -341,8 +341,9 @@ public function drushSetup(array $options = [ * @option root Drupal root. * @option sites-subdir Drupal site subdirectory. * @option settings-override-file Drupal site settings override filename. - * @option force Drupal force generation of a new settings.php. - * @option skip-permissions-setup Drupal skip permissions setup. + * @option force Force generation of a new settings.php. + * @option skip-permissions-setup Skip permissions setup. + * @option dev Development settings setup. * * @param array $options * @@ -354,6 +355,7 @@ public function settingsSetup(array $options = [ 'settings-override-file' => InputOption::VALUE_REQUIRED, 'force' => false, 'skip-permissions-setup' => false, + 'dev' => false ]) { $settings_default_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/default.settings.php'; diff --git a/src/Commands/Drupal8Commands.php b/src/Commands/Drupal8Commands.php index 48e04681..4a5ef0df 100644 --- a/src/Commands/Drupal8Commands.php +++ b/src/Commands/Drupal8Commands.php @@ -26,6 +26,21 @@ protected function getSettingsSetupAddendum($settings_override_filename) if (file_exists(\$app_root . '/' . \$site_path . '/$settings_override_filename')) { include \$app_root . '/' . \$site_path . '/$settings_override_filename'; } +EOF; + } + + /** + * @return string + */ + protected function getSettingsLocalSetupAddendum() + { + return <<< EOF +/** + * Load local development override configuration, if available. + */ +if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) { + include $app_root . '/' . $site_path . '/settings.local.php'; +} EOF; } } From 72ba184175744f8fb83d4c0dfa627b2125ad092e Mon Sep 17 00:00:00 2001 From: D Vargas Date: Wed, 4 Sep 2019 19:08:20 +0200 Subject: [PATCH 02/15] OPENEUROPA-2155: Add dev option to settings setup command. --- src/Commands/AbstractDrupalCommands.php | 8 ++++++++ src/Commands/Drupal7Commands.php | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index ae80187f..2a9099e3 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -370,6 +370,14 @@ public function settingsSetup(array $options = [ $collection = []; + if ((bool) $options['dev']) { + $local_settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.local.php'; + if (true === (bool) $options['force'] || !file_exists($local_settings_path)) { + $custom_config .= $this->getDrupal()->getSettingsLocalSetupAddendum($settings_override_filename); + $local_settings_default_path = $options['root'] . '/sites/example.settings.local.php'; + $collection[] = $this->taskFilesystemStack()->copy($local_settings_default_path, $local_settings_path, true); + } + } if (true === (bool) $options['force'] || !file_exists($settings_path)) { $collection[] = $this->taskWriteToFile($settings_default_path)->append()->lines([$custom_config]); $collection[] = $this->taskFilesystemStack()->copy($settings_default_path, $settings_path, true); diff --git a/src/Commands/Drupal7Commands.php b/src/Commands/Drupal7Commands.php index f1cfd38c..84ffefeb 100644 --- a/src/Commands/Drupal7Commands.php +++ b/src/Commands/Drupal7Commands.php @@ -29,4 +29,13 @@ protected function getSettingsSetupAddendum($settings_override_filename) } EOF; } + + /** + * @return string + */ + protected function getSettingsLocalSetupAddendum() + { + // There are no default local settings in Drupal 7, return empty. + return ''; + } } From 645d166efa72a08234c5e3a0d4a657f7244a3f0c Mon Sep 17 00:00:00 2001 From: D Vargas Date: Thu, 5 Sep 2019 10:45:50 +0200 Subject: [PATCH 03/15] OPENEUROPA-2155: Add simulation tests for settings setup --dev. --- src/Commands/AbstractDrupalCommands.php | 8 +++++--- src/Commands/Drupal8Commands.php | 4 ++-- tests/fixtures/simulation.yml | 7 +++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 2a9099e3..88184ed4 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -361,6 +361,7 @@ public function settingsSetup(array $options = [ $settings_default_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/default.settings.php'; $settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.php'; $settings_override_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/' . $options['settings-override-file']; + $local_settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.local.php'; // Save the filename of the override file in a single variable to use it // in the heredoc variable $custom_config hereunder. @@ -371,12 +372,13 @@ public function settingsSetup(array $options = [ $collection = []; if ((bool) $options['dev']) { - $local_settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.local.php'; if (true === (bool) $options['force'] || !file_exists($local_settings_path)) { $custom_config .= $this->getDrupal()->getSettingsLocalSetupAddendum($settings_override_filename); - $local_settings_default_path = $options['root'] . '/sites/example.settings.local.php'; - $collection[] = $this->taskFilesystemStack()->copy($local_settings_default_path, $local_settings_path, true); + $examples_settings_path = $options['root'] . '/sites/example.settings.local.php'; + $collection[] = $this->taskFilesystemStack()->copy($examples_settings_path, $local_settings_path, true); } + } else { + $collection[] = $this->taskFilesystemStack()->remove($local_settings_path); } if (true === (bool) $options['force'] || !file_exists($settings_path)) { $collection[] = $this->taskWriteToFile($settings_default_path)->append()->lines([$custom_config]); diff --git a/src/Commands/Drupal8Commands.php b/src/Commands/Drupal8Commands.php index 4a5ef0df..68e7bed7 100644 --- a/src/Commands/Drupal8Commands.php +++ b/src/Commands/Drupal8Commands.php @@ -38,8 +38,8 @@ protected function getSettingsLocalSetupAddendum() /** * Load local development override configuration, if available. */ -if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) { - include $app_root . '/' . $site_path . '/settings.local.php'; +if (file_exists(\$app_root . '/' . \$site_path . '/settings.local.php')) { + include \$app_root . '/' . \$site_path . '/settings.local.php'; } EOF; } diff --git a/tests/fixtures/simulation.yml b/tests/fixtures/simulation.yml index 0d60fb4a..b836298e 100644 --- a/tests/fixtures/simulation.yml +++ b/tests/fixtures/simulation.yml @@ -265,6 +265,7 @@ composer: '' contains: - "WriteConfiguration('build/sites/default/settings.override.php'" + - "->remove('build/sites/default/settings.local.php')" - command: 'drupal:settings-setup --root=web' configuration: [] @@ -272,6 +273,12 @@ contains: - "WriteConfiguration('web/sites/default/settings.override.php'" +- command: 'drupal:settings-setup --dev' + configuration: [] + composer: '' + contains: + - "->copy('build/sites/example.settings.local.php', 'build/sites/default/settings.local.php'" + - command: 'drupal:site-setup' configuration: drupal: From a4dfeb9160884fd7fc0dd1f159e362dfe92507c8 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Thu, 5 Sep 2019 11:58:44 +0200 Subject: [PATCH 04/15] OPENEUROPA-2155: Refactor before implementing settings setup tests. --- src/Commands/AbstractDrupalCommands.php | 29 ++++++++++++------- tests/CommandsTest.php | 15 ++++------ ...l => drupal-settings-setup-parameters.yml} | 10 +++---- 3 files changed, 29 insertions(+), 25 deletions(-) rename tests/fixtures/commands/{drupal-settings-setup-force.yml => drupal-settings-setup-parameters.yml} (82%) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 88184ed4..b33c47a2 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -27,9 +27,15 @@ abstract class AbstractDrupalCommands extends AbstractCommands implements Filesy */ public function getDrupal() { - return $this->getConfig()->get('drupal.core') === 7 ? - new Drupal7Commands() : - new Drupal8Commands(); + return $this->getConfig()->get('drupal.core') === 7 ? new Drupal7Commands() : new Drupal8Commands(); + } + + /** + * @return int + */ + public function getDrupalVersion() + { + return $this->getConfig()->get('drupal.core'); } /** @@ -371,15 +377,18 @@ public function settingsSetup(array $options = [ $collection = []; - if ((bool) $options['dev']) { - if (true === (bool) $options['force'] || !file_exists($local_settings_path)) { - $custom_config .= $this->getDrupal()->getSettingsLocalSetupAddendum($settings_override_filename); - $examples_settings_path = $options['root'] . '/sites/example.settings.local.php'; - $collection[] = $this->taskFilesystemStack()->copy($examples_settings_path, $local_settings_path, true); + if ($this->getDrupalVersion() === 8) { + if ((bool) $options['dev']) { + if (true === (bool) $options['force'] || !file_exists($local_settings_path)) { + $custom_config .= $this->getDrupal()->getSettingsLocalSetupAddendum($settings_override_filename); + $examples_settings_path = $options['root'] . '/sites/example.settings.local.php'; + $collection[] = $this->taskFilesystemStack()->copy($examples_settings_path, $local_settings_path, true); + } + } else { + $collection[] = $this->taskFilesystemStack()->remove($local_settings_path); } - } else { - $collection[] = $this->taskFilesystemStack()->remove($local_settings_path); } + if (true === (bool) $options['force'] || !file_exists($settings_path)) { $collection[] = $this->taskWriteToFile($settings_default_path)->append()->lines([$custom_config]); $collection[] = $this->taskFilesystemStack()->copy($settings_default_path, $settings_path, true); diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 8408fee0..68f57a5a 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -265,16 +265,13 @@ function $fct() {} } /** - * @param array $config + * @param array $configs * @param array $expected * - * @dataProvider settingsSetupForceDataProvider + * @dataProvider settingsSetupParametersDataProvider */ - public function testSettingsSetupForce(array $config, array $expected) + public function testSettingsSetupParameters(array $configs, array $expected) { - $configFile = $this->getSandboxFilepath('runner.yml'); - file_put_contents($configFile, Yaml::dump($config)); - $sites_subdir = isset($config['drupal']['site']['sites_subdir']) ? $config['drupal']['site']['sites_subdir'] : 'default'; mkdir($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/', 0777, true); file_put_contents($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/default.settings.php', ''); @@ -282,7 +279,7 @@ public function testSettingsSetupForce(array $config, array $expected) $input = new StringInput('drupal:settings-setup --working-dir=' . $this->getSandboxRoot()); - if (true === $config['drupal']['site']['force']) { + if (isset($configs['parameters']['force']) && true === $configs['parameters']['force']) { $input = new StringInput('drupal:settings-setup --working-dir=' . $this->getSandboxRoot() . ' --force'); } $runner = new TaskRunner($input, new BufferedOutput(), $this->getClassLoader()); @@ -404,9 +401,9 @@ public function drupal8SettingsSetupDataProvider() /** * @return array */ - public function settingsSetupForceDataProvider() + public function settingsSetupParametersDataProvider() { - return $this->getFixtureContent('commands/drupal-settings-setup-force.yml'); + return $this->getFixtureContent('commands/drupal-settings-setup-parameters.yml'); } /** diff --git a/tests/fixtures/commands/drupal-settings-setup-force.yml b/tests/fixtures/commands/drupal-settings-setup-parameters.yml similarity index 82% rename from tests/fixtures/commands/drupal-settings-setup-force.yml rename to tests/fixtures/commands/drupal-settings-setup-parameters.yml index be04d9d7..db168c8a 100644 --- a/tests/fixtures/commands/drupal-settings-setup-force.yml +++ b/tests/fixtures/commands/drupal-settings-setup-parameters.yml @@ -1,16 +1,14 @@ - configuration: - drupal: - site: - force: false + parameters: + force: false expected: - file: "build/sites/default/settings.php" contains: "# Already existing file." not_contains: "include $app_root . '/' . $site_path . '/settings.override.php';" - configuration: - drupal: - site: - force: true + parameters: + force: true expected: - file: "build/sites/default/settings.php" contains: "include $app_root . '/' . $site_path . '/settings.override.php';" From b49bb2e9b50f4ca99f9c48b02f615189b2370209 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Thu, 5 Sep 2019 16:23:59 +0200 Subject: [PATCH 05/15] OPENEUROPA-2155: Add settings setup tests --dev. --- src/Commands/AbstractDrupalCommands.php | 8 ++- src/Commands/Drupal8Commands.php | 1 + tests/CommandsTest.php | 64 ++++++++----------- .../drupal-settings-setup-parameters.yml | 32 +++++++++- 4 files changed, 64 insertions(+), 41 deletions(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index b33c47a2..23b4a8e7 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -379,17 +379,19 @@ public function settingsSetup(array $options = [ if ($this->getDrupalVersion() === 8) { if ((bool) $options['dev']) { - if (true === (bool) $options['force'] || !file_exists($local_settings_path)) { + if ((bool) $options['force'] || !file_exists($local_settings_path)) { $custom_config .= $this->getDrupal()->getSettingsLocalSetupAddendum($settings_override_filename); $examples_settings_path = $options['root'] . '/sites/example.settings.local.php'; - $collection[] = $this->taskFilesystemStack()->copy($examples_settings_path, $local_settings_path, true); + if (file_exists($examples_settings_path)) { + $collection[] = $this->taskFilesystemStack()->copy($examples_settings_path, $local_settings_path, true); + } } } else { $collection[] = $this->taskFilesystemStack()->remove($local_settings_path); } } - if (true === (bool) $options['force'] || !file_exists($settings_path)) { + if ((bool) $options['force'] || !file_exists($settings_path)) { $collection[] = $this->taskWriteToFile($settings_default_path)->append()->lines([$custom_config]); $collection[] = $this->taskFilesystemStack()->copy($settings_default_path, $settings_path, true); } diff --git a/src/Commands/Drupal8Commands.php b/src/Commands/Drupal8Commands.php index 68e7bed7..3e23219e 100644 --- a/src/Commands/Drupal8Commands.php +++ b/src/Commands/Drupal8Commands.php @@ -35,6 +35,7 @@ protected function getSettingsSetupAddendum($settings_override_filename) protected function getSettingsLocalSetupAddendum() { return <<< EOF + /** * Load local development override configuration, if available. */ diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 68f57a5a..9d0c9b02 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -276,44 +276,28 @@ public function testSettingsSetupParameters(array $configs, array $expected) mkdir($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/', 0777, true); file_put_contents($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/default.settings.php', ''); file_put_contents($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/settings.php', '# Already existing file.'); + file_put_contents($this->getSandboxRoot() . '/build/sites/example.settings.local.php', '// Local development override configuration.'); - $input = new StringInput('drupal:settings-setup --working-dir=' . $this->getSandboxRoot()); - - if (isset($configs['parameters']['force']) && true === $configs['parameters']['force']) { - $input = new StringInput('drupal:settings-setup --working-dir=' . $this->getSandboxRoot() . ' --force'); + $input = 'drupal:settings-setup --working-dir=' . $this->getSandboxRoot(); + if (isset($configs['parameters']['force']) && $configs['parameters']['force']) { + $input .= ' --force'; } - $runner = new TaskRunner($input, new BufferedOutput(), $this->getClassLoader()); - $runner->run(); + if (isset($configs['parameters']['dev']) && $configs['parameters']['dev']) { + $input .= ' --dev'; + } + $runner = new TaskRunner(new StringInput($input), new BufferedOutput(), $this->getClassLoader()); + $exit_code = $runner->run(); + $this->assertEquals(0, $exit_code, 'Command run returned an error.'); foreach ($expected as $row) { - $content = file_get_contents($this->getSandboxFilepath($row['file'])); - $this->assertContainsNotContains($content, $row); + if (isset($row['file'])) { + $content = file_get_contents($this->getSandboxFilepath($row['file'])); + $this->assertContainsNotContains($content, $row); + } + if (isset($row['no_file'])) { + $this->assertFileNotExists($row['no_file']); + } } - - // Generate a random function name. - $fct = $this->generateRandomString(20); - - // Generate a dummy PHP code. - $config_override_dummy_script = <<< EOF -getSandboxRoot() . '/build/sites/' . $sites_subdir . '/' . $config_override_filename, - $config_override_dummy_script - ); - - // Include the config override file. - include_once $this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/' . $config_override_filename; - - // Test if the dummy PHP code has been properly included. - $this->assertTrue(\function_exists($fct)); } /** @@ -424,13 +408,19 @@ public function changelogDataProvider() /** * @param string $content - * @param array $expected + * @param array $expectations */ - protected function assertContainsNotContains($content, array $expected) + protected function assertContainsNotContains($content, array $expectations) { - $this->assertContains($expected['contains'], $content); + if (!empty($expectations['contains'])) { + foreach ((array) $expectations['contains'] as $expected) { + $this->assertContains($expected, $content); + } + } if (!empty($expected['not_contains'])) { - $this->assertNotContains($expected['not_contains'], $content); + foreach ((array) $expectations['not_contains'] as $expected) { + $this->assertNotContains($expected, $content); + } } } } diff --git a/tests/fixtures/commands/drupal-settings-setup-parameters.yml b/tests/fixtures/commands/drupal-settings-setup-parameters.yml index db168c8a..fb775f36 100644 --- a/tests/fixtures/commands/drupal-settings-setup-parameters.yml +++ b/tests/fixtures/commands/drupal-settings-setup-parameters.yml @@ -4,7 +4,10 @@ expected: - file: "build/sites/default/settings.php" contains: "# Already existing file." - not_contains: "include $app_root . '/' . $site_path . '/settings.override.php';" + not_contains: + - "include $app_root . '/' . $site_path . '/settings.override.php';" + - "include $app_root . '/' . $site_path . '/settings.local.php';" + - no_file: "build/sites/default/settings.local.php" - configuration: parameters: @@ -12,4 +15,31 @@ expected: - file: "build/sites/default/settings.php" contains: "include $app_root . '/' . $site_path . '/settings.override.php';" + not_contains: + - "# Already existing file." + - "include $app_root . '/' . $site_path . '/settings.local.php';" + - no_file: "build/sites/default/settings.local.php" + +- configuration: + parameters: + force: false + dev: true + expected: + - file: "build/sites/default/settings.php" + contains: "# Already existing file." + not_contains: + - "include $app_root . '/' . $site_path . '/settings.override.php';" + - "include $app_root . '/' . $site_path . '/settings.local.php';" + +- configuration: + parameters: + force: true + dev: true + expected: + - file: "build/sites/default/settings.php" + contains: + - "include $app_root . '/' . $site_path . '/settings.override.php';" + - "include $app_root . '/' . $site_path . '/settings.local.php';" not_contains: "# Already existing file." + - file: "build/sites/default/settings.local.php" + contains: "// Local development override configuration." From b4e439a63fc1b0acbdb9f97754ebb05a14c9cde9 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Thu, 5 Sep 2019 18:09:36 +0200 Subject: [PATCH 06/15] OPENEUROPA-2155: Add settings setup tests --dev when files do/dont exist. --- src/Commands/AbstractDrupalCommands.php | 2 +- tests/CommandsTest.php | 7 +++- .../drupal-settings-setup-parameters.yml | 37 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 23b4a8e7..91799970 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -386,7 +386,7 @@ public function settingsSetup(array $options = [ $collection[] = $this->taskFilesystemStack()->copy($examples_settings_path, $local_settings_path, true); } } - } else { + } else if ((bool) $options['force']) { $collection[] = $this->taskFilesystemStack()->remove($local_settings_path); } } diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 9d0c9b02..032daa50 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -275,9 +275,14 @@ public function testSettingsSetupParameters(array $configs, array $expected) $sites_subdir = isset($config['drupal']['site']['sites_subdir']) ? $config['drupal']['site']['sites_subdir'] : 'default'; mkdir($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/', 0777, true); file_put_contents($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/default.settings.php', ''); - file_put_contents($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/settings.php', '# Already existing file.'); file_put_contents($this->getSandboxRoot() . '/build/sites/example.settings.local.php', '// Local development override configuration.'); + if (!empty($configs['files'])) { + foreach ($configs['files'] as $file) { + file_put_contents($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/' . $file['name'], $file['content']); + } + } + $input = 'drupal:settings-setup --working-dir=' . $this->getSandboxRoot(); if (isset($configs['parameters']['force']) && $configs['parameters']['force']) { $input .= ' --force'; diff --git a/tests/fixtures/commands/drupal-settings-setup-parameters.yml b/tests/fixtures/commands/drupal-settings-setup-parameters.yml index fb775f36..201a3601 100644 --- a/tests/fixtures/commands/drupal-settings-setup-parameters.yml +++ b/tests/fixtures/commands/drupal-settings-setup-parameters.yml @@ -1,4 +1,7 @@ - configuration: + files: + - name: 'settings.php' + content: '# Already existing file.' parameters: force: false expected: @@ -10,6 +13,9 @@ - no_file: "build/sites/default/settings.local.php" - configuration: + files: + - name: 'settings.php' + content: '# Already existing file.' parameters: force: true expected: @@ -21,6 +27,9 @@ - no_file: "build/sites/default/settings.local.php" - configuration: + files: + - name: 'settings.php' + content: '# Already existing file.' parameters: force: false dev: true @@ -32,6 +41,9 @@ - "include $app_root . '/' . $site_path . '/settings.local.php';" - configuration: + files: + - name: 'settings.php' + content: '# Already existing file.' parameters: force: true dev: true @@ -43,3 +55,28 @@ not_contains: "# Already existing file." - file: "build/sites/default/settings.local.php" contains: "// Local development override configuration." + +- configuration: + files: + - name: 'settings.local.php' + content: '// Initial config.' + parameters: + force: false + expected: + - file: "build/sites/default/settings.php" + not_contains: "include $app_root . '/' . $site_path . '/settings.local.php';" + contains: "include $app_root . '/' . $site_path . '/settings.override.php';" + - file: "build/sites/default/settings.local.php" + contains: "// Initial config." + +- configuration: + files: + - name: 'settings.local.php' + content: '// Initial config.' + parameters: + force: true + expected: + - file: "build/sites/default/settings.php" + contains: "include $app_root . '/' . $site_path . '/settings.override.php';" + not_contains: "include $app_root . '/' . $site_path . '/settings.local.php';" + - no_file: "build/sites/default/settings.local.php" From aeea7e67fe30cb0079d80a287fb13a03801f7d4c Mon Sep 17 00:00:00 2001 From: D Vargas Date: Fri, 6 Sep 2019 12:13:40 +0200 Subject: [PATCH 07/15] OPENEUROPA-2155: Final refactoring. --- src/Commands/AbstractDrupalCommands.php | 7 ++++--- src/Commands/Drupal7Commands.php | 10 ++++++++++ src/Commands/Drupal8Commands.php | 10 ++++++++++ tests/CommandsTest.php | 26 ++++++++++++++++--------- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 91799970..e4da8d93 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -354,6 +354,8 @@ public function drushSetup(array $options = [ * @param array $options * * @return \Robo\Collection\CollectionBuilder + * + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function settingsSetup(array $options = [ 'root' => InputOption::VALUE_REQUIRED, @@ -367,17 +369,16 @@ public function settingsSetup(array $options = [ $settings_default_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/default.settings.php'; $settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.php'; $settings_override_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/' . $options['settings-override-file']; - $local_settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.local.php'; + $local_settings_path = $this->getDrupal()->getLocalSettingsPath($options); // Save the filename of the override file in a single variable to use it // in the heredoc variable $custom_config hereunder. $settings_override_filename = $options['settings-override-file']; - $custom_config = $this->getDrupal()->getSettingsSetupAddendum($settings_override_filename); $collection = []; - if ($this->getDrupalVersion() === 8) { + if ($local_settings_path) { if ((bool) $options['dev']) { if ((bool) $options['force'] || !file_exists($local_settings_path)) { $custom_config .= $this->getDrupal()->getSettingsLocalSetupAddendum($settings_override_filename); diff --git a/src/Commands/Drupal7Commands.php b/src/Commands/Drupal7Commands.php index 84ffefeb..046a2019 100644 --- a/src/Commands/Drupal7Commands.php +++ b/src/Commands/Drupal7Commands.php @@ -38,4 +38,14 @@ protected function getSettingsLocalSetupAddendum() // There are no default local settings in Drupal 7, return empty. return ''; } + + /** + * @param array $options + * + * @return string|false The default path for local settings or false if it doesn't exist. + */ + protected function getLocalSettingsPath(array $options) + { + return ''; + } } diff --git a/src/Commands/Drupal8Commands.php b/src/Commands/Drupal8Commands.php index 3e23219e..74ec9aff 100644 --- a/src/Commands/Drupal8Commands.php +++ b/src/Commands/Drupal8Commands.php @@ -44,4 +44,14 @@ protected function getSettingsLocalSetupAddendum() } EOF; } + + /** + * @param array $options + * + * @return string|false The default path for local settings or false if it doesn't exist. + */ + protected function getLocalSettingsPath(array $options) + { + return $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.local.php'; + } } diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 032daa50..833d1691 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -294,15 +294,7 @@ public function testSettingsSetupParameters(array $configs, array $expected) $exit_code = $runner->run(); $this->assertEquals(0, $exit_code, 'Command run returned an error.'); - foreach ($expected as $row) { - if (isset($row['file'])) { - $content = file_get_contents($this->getSandboxFilepath($row['file'])); - $this->assertContainsNotContains($content, $row); - } - if (isset($row['no_file'])) { - $this->assertFileNotExists($row['no_file']); - } - } + $this->processSettingsAssertions($expected); } /** @@ -428,4 +420,20 @@ protected function assertContainsNotContains($content, array $expectations) } } } + + /** + * @param array $expected + */ + protected function processSettingsAssertions(array $expected) + { + foreach ($expected as $row) { + if (isset($row['file'])) { + $content = file_get_contents($this->getSandboxFilepath($row['file'])); + $this->assertContainsNotContains($content, $row); + } + if (isset($row['no_file'])) { + $this->assertFileNotExists($row['no_file']); + } + } + } } From 17ee9746ebb756d01c1f8f996b1fdc5908182122 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Mon, 9 Sep 2019 09:32:24 +0200 Subject: [PATCH 08/15] OPENEUROPA-2155: Skip simulation tests. --- tests/fixtures/simulation.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/fixtures/simulation.yml b/tests/fixtures/simulation.yml index b836298e..0d60fb4a 100644 --- a/tests/fixtures/simulation.yml +++ b/tests/fixtures/simulation.yml @@ -265,7 +265,6 @@ composer: '' contains: - "WriteConfiguration('build/sites/default/settings.override.php'" - - "->remove('build/sites/default/settings.local.php')" - command: 'drupal:settings-setup --root=web' configuration: [] @@ -273,12 +272,6 @@ contains: - "WriteConfiguration('web/sites/default/settings.override.php'" -- command: 'drupal:settings-setup --dev' - configuration: [] - composer: '' - contains: - - "->copy('build/sites/example.settings.local.php', 'build/sites/default/settings.local.php'" - - command: 'drupal:site-setup' configuration: drupal: From b300573f170697424c4c75e84df964b12dbc69cf Mon Sep 17 00:00:00 2001 From: D Vargas Date: Mon, 16 Sep 2019 17:47:13 +0200 Subject: [PATCH 09/15] OPENEUROPA-2155: Fixes after review. --- src/Commands/AbstractDrupalCommands.php | 8 -------- tests/CommandsTest.php | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index e4da8d93..d8590365 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -30,14 +30,6 @@ public function getDrupal() return $this->getConfig()->get('drupal.core') === 7 ? new Drupal7Commands() : new Drupal8Commands(); } - /** - * @return int - */ - public function getDrupalVersion() - { - return $this->getConfig()->get('drupal.core'); - } - /** * {@inheritdoc} */ diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 833d1691..a329328d 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -272,7 +272,7 @@ function $fct() {} */ public function testSettingsSetupParameters(array $configs, array $expected) { - $sites_subdir = isset($config['drupal']['site']['sites_subdir']) ? $config['drupal']['site']['sites_subdir'] : 'default'; + $sites_subdir = isset($configs['drupal']['site']['sites_subdir']) ? $configs['drupal']['site']['sites_subdir'] : 'default'; mkdir($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/', 0777, true); file_put_contents($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/default.settings.php', ''); file_put_contents($this->getSandboxRoot() . '/build/sites/example.settings.local.php', '// Local development override configuration.'); From 0c528934a234d7a674d3eaceade3a50aa93e4238 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Mon, 27 Jan 2020 16:25:22 +0100 Subject: [PATCH 10/15] OPENEUROPA-2155: Refactor dev mode to provide it for both Drupal 7 and Drupal 8. --- config/runner.yml | 6 ++++ src/Commands/AbstractDrupalCommands.php | 28 +++++++++---------- src/Commands/Drupal7Commands.php | 19 ++++++------- src/Commands/Drupal8Commands.php | 10 ------- .../drupal-settings-setup-parameters.yml | 24 +++++++++++----- 5 files changed, 44 insertions(+), 43 deletions(-) diff --git a/config/runner.yml b/config/runner.yml index 9d380200..f96431ae 100644 --- a/config/runner.yml +++ b/config/runner.yml @@ -37,6 +37,12 @@ drupal: config_dir: ~ existing_config: false settings_override_file: "settings.override.php" + # Local development settings override. + # Add development settings that you want to share with your team and commit this file. + # If found this file will be copied in `/sites/{sites-subdir}` and renamed into 'settings.local.php' + # which should be, instead, git-ignored. This will give the possibility to locally + # tweak development settings. + settings_local_file: "example.settings.local.php" # Setting this to "false" will run "site-install" without the "--db-url" parameter. # This is useful if the database settings are already set in your settings.php file. generate_db_url: true diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index d8590365..9f6072dc 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -361,7 +361,6 @@ public function settingsSetup(array $options = [ $settings_default_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/default.settings.php'; $settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.php'; $settings_override_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/' . $options['settings-override-file']; - $local_settings_path = $this->getDrupal()->getLocalSettingsPath($options); // Save the filename of the override file in a single variable to use it // in the heredoc variable $custom_config hereunder. @@ -370,20 +369,6 @@ public function settingsSetup(array $options = [ $collection = []; - if ($local_settings_path) { - if ((bool) $options['dev']) { - if ((bool) $options['force'] || !file_exists($local_settings_path)) { - $custom_config .= $this->getDrupal()->getSettingsLocalSetupAddendum($settings_override_filename); - $examples_settings_path = $options['root'] . '/sites/example.settings.local.php'; - if (file_exists($examples_settings_path)) { - $collection[] = $this->taskFilesystemStack()->copy($examples_settings_path, $local_settings_path, true); - } - } - } else if ((bool) $options['force']) { - $collection[] = $this->taskFilesystemStack()->remove($local_settings_path); - } - } - if ((bool) $options['force'] || !file_exists($settings_path)) { $collection[] = $this->taskWriteToFile($settings_default_path)->append()->lines([$custom_config]); $collection[] = $this->taskFilesystemStack()->copy($settings_default_path, $settings_path, true); @@ -394,6 +379,19 @@ public function settingsSetup(array $options = [ $this->getConfig() )->setConfigKey('drupal.settings'); + // If ran in dev mode copy local settings file to 'settings.local.php'. + // Such file will be conditionally included in 'settings-override-file'. + if ($options['dev']) { + $examples_settings_path = $options['root'] . '/sites/' . $this->getConfig()->get('drupal.site.settings_local_file'); + if (file_exists($examples_settings_path)) { + $local_settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.local.php'; + $collection[] = $this->taskFilesystemStack()->copy($examples_settings_path, $local_settings_path, $options['force']); + } + $collection[] = $this->taskWriteToFile($settings_override_path) + ->append() + ->text($this->getDrupal()->getSettingsLocalSetupAddendum()); + } + if (!$options['skip-permissions-setup']) { $collection[] = $this->permissionsSetup($options); } diff --git a/src/Commands/Drupal7Commands.php b/src/Commands/Drupal7Commands.php index 046a2019..eb3daaa7 100644 --- a/src/Commands/Drupal7Commands.php +++ b/src/Commands/Drupal7Commands.php @@ -35,17 +35,14 @@ protected function getSettingsSetupAddendum($settings_override_filename) */ protected function getSettingsLocalSetupAddendum() { - // There are no default local settings in Drupal 7, return empty. - return ''; - } + return <<< EOF - /** - * @param array $options - * - * @return string|false The default path for local settings or false if it doesn't exist. - */ - protected function getLocalSettingsPath(array $options) - { - return ''; +/** + * Load local development override configuration, if available. + */ +if (file_exists(DRUPAL_ROOT . '/' . \$conf_path . '/settings.local.php')) { + include DRUPAL_ROOT . '/' . \$conf_path . '/settings.local.php'; +} +EOF; } } diff --git a/src/Commands/Drupal8Commands.php b/src/Commands/Drupal8Commands.php index 74ec9aff..3e23219e 100644 --- a/src/Commands/Drupal8Commands.php +++ b/src/Commands/Drupal8Commands.php @@ -44,14 +44,4 @@ protected function getSettingsLocalSetupAddendum() } EOF; } - - /** - * @param array $options - * - * @return string|false The default path for local settings or false if it doesn't exist. - */ - protected function getLocalSettingsPath(array $options) - { - return $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.local.php'; - } } diff --git a/tests/fixtures/commands/drupal-settings-setup-parameters.yml b/tests/fixtures/commands/drupal-settings-setup-parameters.yml index 201a3601..5aa8a411 100644 --- a/tests/fixtures/commands/drupal-settings-setup-parameters.yml +++ b/tests/fixtures/commands/drupal-settings-setup-parameters.yml @@ -30,6 +30,8 @@ files: - name: 'settings.php' content: '# Already existing file.' + - name: 'settings.local.php' + content: '# Already existing file.' parameters: force: false dev: true @@ -39,18 +41,21 @@ not_contains: - "include $app_root . '/' . $site_path . '/settings.override.php';" - "include $app_root . '/' . $site_path . '/settings.local.php';" + - file: "build/sites/default/settings.local.php" + contains: "# Already existing file." - configuration: files: - name: 'settings.php' content: '# Already existing file.' + - name: 'settings.local.php' + content: '# Already existing file.' parameters: force: true dev: true expected: - - file: "build/sites/default/settings.php" + - file: "build/sites/default/settings.override.php" contains: - - "include $app_root . '/' . $site_path . '/settings.override.php';" - "include $app_root . '/' . $site_path . '/settings.local.php';" not_contains: "# Already existing file." - file: "build/sites/default/settings.local.php" @@ -71,12 +76,17 @@ - configuration: files: + - name: 'settings.php' + content: '# Already existing file.' - name: 'settings.local.php' - content: '// Initial config.' + content: '# Already existing file.' parameters: force: true + dev: true expected: - - file: "build/sites/default/settings.php" - contains: "include $app_root . '/' . $site_path . '/settings.override.php';" - not_contains: "include $app_root . '/' . $site_path . '/settings.local.php';" - - no_file: "build/sites/default/settings.local.php" + - file: "build/sites/default/settings.override.php" + contains: + - "include $app_root . '/' . $site_path . '/settings.local.php';" + not_contains: "# Already existing file." + - file: "build/sites/default/settings.local.php" + contains: "// Local development override configuration." From 4668be0fb303cfa766d1a335873474ddb4738b06 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Mon, 27 Jan 2020 16:30:10 +0100 Subject: [PATCH 11/15] OPENEUROPA-2155: Fix wrong location of default.settings.php, this fixes MULTISITE-22694 too. --- src/Commands/AbstractDrupalCommands.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 9f6072dc..58231c67 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -358,7 +358,7 @@ public function settingsSetup(array $options = [ 'dev' => false ]) { - $settings_default_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/default.settings.php'; + $settings_default_path = $options['root'] . '/sites/default/default.settings.php'; $settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.php'; $settings_override_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/' . $options['settings-override-file']; From c3da9cd5f4f04930109186e310406434278506ba Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Mon, 27 Jan 2020 16:51:05 +0100 Subject: [PATCH 12/15] OPENEUROPA-2155: Make settings_local_file fully configurable. --- config/runner.yml | 4 ++-- src/Commands/AbstractDrupalCommands.php | 22 ++++++++++++++++++- src/Commands/Drupal7Commands.php | 16 -------------- src/Commands/Drupal8Commands.php | 16 -------------- .../drupal-settings-setup-parameters.yml | 4 ++-- 5 files changed, 25 insertions(+), 37 deletions(-) diff --git a/config/runner.yml b/config/runner.yml index f96431ae..793aaf00 100644 --- a/config/runner.yml +++ b/config/runner.yml @@ -39,10 +39,10 @@ drupal: settings_override_file: "settings.override.php" # Local development settings override. # Add development settings that you want to share with your team and commit this file. - # If found this file will be copied in `/sites/{sites-subdir}` and renamed into 'settings.local.php' + # If found this file will be copied in `/sites/{sites-subdir}/settings.local.php`, # which should be, instead, git-ignored. This will give the possibility to locally # tweak development settings. - settings_local_file: "example.settings.local.php" + settings_local_file: "${drupal.root}/sites/example.settings.local.php" # Setting this to "false" will run "site-install" without the "--db-url" parameter. # This is useful if the database settings are already set in your settings.php file. generate_db_url: true diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 58231c67..8ca84a70 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -382,7 +382,7 @@ public function settingsSetup(array $options = [ // If ran in dev mode copy local settings file to 'settings.local.php'. // Such file will be conditionally included in 'settings-override-file'. if ($options['dev']) { - $examples_settings_path = $options['root'] . '/sites/' . $this->getConfig()->get('drupal.site.settings_local_file'); + $examples_settings_path = $this->getConfig()->get('drupal.site.settings_local_file'); if (file_exists($examples_settings_path)) { $local_settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.local.php'; $collection[] = $this->taskFilesystemStack()->copy($examples_settings_path, $local_settings_path, $options['force']); @@ -451,4 +451,24 @@ protected function processPrePostInstallCommands(array &$commands, array $tokens } } } + + /** + * Get include portion for local development override configuration. + * + * This will be optionally appended to the settings override file. + * + * @return string + */ + protected function getSettingsLocalSetupAddendum() + { + return <<< EOF + +/** + * Load local development override configuration, if available. + */ +if (file_exists(__DIR__ . '/settings.local.php')) { + include __DIR__ . '/settings.local.php'; +} +EOF; + } } diff --git a/src/Commands/Drupal7Commands.php b/src/Commands/Drupal7Commands.php index eb3daaa7..f1cfd38c 100644 --- a/src/Commands/Drupal7Commands.php +++ b/src/Commands/Drupal7Commands.php @@ -27,22 +27,6 @@ protected function getSettingsSetupAddendum($settings_override_filename) if (file_exists(DRUPAL_ROOT . '/' . \$conf_path . '/$settings_override_filename')) { include DRUPAL_ROOT . '/' . \$conf_path . '/$settings_override_filename'; } -EOF; - } - - /** - * @return string - */ - protected function getSettingsLocalSetupAddendum() - { - return <<< EOF - -/** - * Load local development override configuration, if available. - */ -if (file_exists(DRUPAL_ROOT . '/' . \$conf_path . '/settings.local.php')) { - include DRUPAL_ROOT . '/' . \$conf_path . '/settings.local.php'; -} EOF; } } diff --git a/src/Commands/Drupal8Commands.php b/src/Commands/Drupal8Commands.php index 3e23219e..48e04681 100644 --- a/src/Commands/Drupal8Commands.php +++ b/src/Commands/Drupal8Commands.php @@ -26,22 +26,6 @@ protected function getSettingsSetupAddendum($settings_override_filename) if (file_exists(\$app_root . '/' . \$site_path . '/$settings_override_filename')) { include \$app_root . '/' . \$site_path . '/$settings_override_filename'; } -EOF; - } - - /** - * @return string - */ - protected function getSettingsLocalSetupAddendum() - { - return <<< EOF - -/** - * Load local development override configuration, if available. - */ -if (file_exists(\$app_root . '/' . \$site_path . '/settings.local.php')) { - include \$app_root . '/' . \$site_path . '/settings.local.php'; -} EOF; } } diff --git a/tests/fixtures/commands/drupal-settings-setup-parameters.yml b/tests/fixtures/commands/drupal-settings-setup-parameters.yml index 5aa8a411..982a386c 100644 --- a/tests/fixtures/commands/drupal-settings-setup-parameters.yml +++ b/tests/fixtures/commands/drupal-settings-setup-parameters.yml @@ -56,7 +56,7 @@ expected: - file: "build/sites/default/settings.override.php" contains: - - "include $app_root . '/' . $site_path . '/settings.local.php';" + - "include __DIR__ . '/settings.local.php';" not_contains: "# Already existing file." - file: "build/sites/default/settings.local.php" contains: "// Local development override configuration." @@ -86,7 +86,7 @@ expected: - file: "build/sites/default/settings.override.php" contains: - - "include $app_root . '/' . $site_path . '/settings.local.php';" + - "include __DIR__ . '/settings.local.php';" not_contains: "# Already existing file." - file: "build/sites/default/settings.local.php" contains: "// Local development override configuration." From 152046f991f6b54fee63f923b27cad9dded51a06 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Tue, 28 Jan 2020 16:12:11 +0100 Subject: [PATCH 13/15] OPENEUROPA-2155: Remove duplicated test. --- .../drupal-settings-setup-parameters.yml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/tests/fixtures/commands/drupal-settings-setup-parameters.yml b/tests/fixtures/commands/drupal-settings-setup-parameters.yml index 982a386c..1b148a8a 100644 --- a/tests/fixtures/commands/drupal-settings-setup-parameters.yml +++ b/tests/fixtures/commands/drupal-settings-setup-parameters.yml @@ -73,20 +73,3 @@ contains: "include $app_root . '/' . $site_path . '/settings.override.php';" - file: "build/sites/default/settings.local.php" contains: "// Initial config." - -- configuration: - files: - - name: 'settings.php' - content: '# Already existing file.' - - name: 'settings.local.php' - content: '# Already existing file.' - parameters: - force: true - dev: true - expected: - - file: "build/sites/default/settings.override.php" - contains: - - "include __DIR__ . '/settings.local.php';" - not_contains: "# Already existing file." - - file: "build/sites/default/settings.local.php" - contains: "// Local development override configuration." From cc86b9be173982930f6526acc08001564248a773 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Tue, 28 Jan 2020 16:14:43 +0100 Subject: [PATCH 14/15] OPENEUROPA-2155: Rename variable. --- src/Commands/AbstractDrupalCommands.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 8ca84a70..c1f2368e 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -382,10 +382,10 @@ public function settingsSetup(array $options = [ // If ran in dev mode copy local settings file to 'settings.local.php'. // Such file will be conditionally included in 'settings-override-file'. if ($options['dev']) { - $examples_settings_path = $this->getConfig()->get('drupal.site.settings_local_file'); - if (file_exists($examples_settings_path)) { + $local_settings_file = $this->getConfig()->get('drupal.site.settings_local_file'); + if (file_exists($local_settings_file)) { $local_settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.local.php'; - $collection[] = $this->taskFilesystemStack()->copy($examples_settings_path, $local_settings_path, $options['force']); + $collection[] = $this->taskFilesystemStack()->copy($local_settings_file, $local_settings_path, $options['force']); } $collection[] = $this->taskWriteToFile($settings_override_path) ->append() From 64e83981646b4535385e647399cddce87b5fc9e3 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Tue, 28 Jan 2020 16:29:35 +0100 Subject: [PATCH 15/15] OPENEUROPA-2155: Add sub-site test. --- tests/CommandsTest.php | 9 +++++--- .../drupal-settings-setup-parameters.yml | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index a329328d..7837e70c 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -273,8 +273,11 @@ function $fct() {} public function testSettingsSetupParameters(array $configs, array $expected) { $sites_subdir = isset($configs['drupal']['site']['sites_subdir']) ? $configs['drupal']['site']['sites_subdir'] : 'default'; - mkdir($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/', 0777, true); - file_put_contents($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/default.settings.php', ''); + mkdir($this->getSandboxRoot() . '/build/sites/default', 0755, true); + if ($sites_subdir !== 'default') { + mkdir($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/', 0755, true); + } + file_put_contents($this->getSandboxRoot() . '/build/sites/default/default.settings.php', ''); file_put_contents($this->getSandboxRoot() . '/build/sites/example.settings.local.php', '// Local development override configuration.'); if (!empty($configs['files'])) { @@ -283,7 +286,7 @@ public function testSettingsSetupParameters(array $configs, array $expected) } } - $input = 'drupal:settings-setup --working-dir=' . $this->getSandboxRoot(); + $input = 'drupal:settings-setup --working-dir=' . $this->getSandboxRoot() . ' --sites-subdir=' . $sites_subdir; if (isset($configs['parameters']['force']) && $configs['parameters']['force']) { $input .= ' --force'; } diff --git a/tests/fixtures/commands/drupal-settings-setup-parameters.yml b/tests/fixtures/commands/drupal-settings-setup-parameters.yml index 1b148a8a..f5acb6a4 100644 --- a/tests/fixtures/commands/drupal-settings-setup-parameters.yml +++ b/tests/fixtures/commands/drupal-settings-setup-parameters.yml @@ -44,6 +44,27 @@ - file: "build/sites/default/settings.local.php" contains: "# Already existing file." +- configuration: + files: + - name: 'settings.php' + content: '# Already existing file.' + - name: 'settings.local.php' + content: '# Already existing file.' + parameters: + force: false + dev: true + drupal: + site: + sites_subdir: 'foo' + expected: + - file: "build/sites/foo/settings.php" + contains: "# Already existing file." + not_contains: + - "include $app_root . '/' . $site_path . '/settings.override.php';" + - "include $app_root . '/' . $site_path . '/settings.local.php';" + - file: "build/sites/foo/settings.local.php" + contains: "# Already existing file." + - configuration: files: - name: 'settings.php'