From 0ff3482eb5b7882db185d36dd149a78dba7fc2a3 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 1 Oct 2018 14:30:17 +0200 Subject: [PATCH] OPENEUROPA-1149: Update the tests to make sure that the settings override file is properly included. --- tests/AbstractTest.php | 13 +++++ tests/CommandsTest.php | 50 ++++++++++++++++++- .../commands/drupal-settings-setup-force.yml | 2 +- .../commands/drupal-settings-setup.yml | 6 +-- 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index fcbc5220..6810a7a0 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -79,4 +79,17 @@ protected function getSandboxRoot() { return __DIR__."/sandbox"; } + + /** + * Generate a random string. + * + * @param int $length + * The desired length. + * + * @return string + * The random string. + */ + protected function generateRandomString($length = 10) { + return substr(str_shuffle(str_repeat($x = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)))), 1, $length); + } } diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index d3948abb..09a5d152 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -146,7 +146,7 @@ public function testSettingsSetup(array $config, array $expected) file_put_contents($configFile, Yaml::dump($config)); - $sites_subdir = isset($config['drupal']['site']['sites_subdir']) ? $config['drupal']['site']['sites_subdir'] : 'default'; + $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', ''); @@ -158,6 +158,29 @@ public function testSettingsSetup(array $config, array $expected) $content = file_get_contents($this->getSandboxFilepath($row['file'])); $this->assertContainsNotContains($content, $row); } + + // 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)); } /** @@ -171,7 +194,7 @@ public function testSettingsSetupForce(array $config, 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'; + $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.'); @@ -184,6 +207,29 @@ public function testSettingsSetupForce(array $config, array $expected) $content = file_get_contents($this->getSandboxFilepath($row['file'])); $this->assertContainsNotContains($content, $row); } + + // 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)); } /** diff --git a/tests/fixtures/commands/drupal-settings-setup-force.yml b/tests/fixtures/commands/drupal-settings-setup-force.yml index ae080c86..31587d65 100644 --- a/tests/fixtures/commands/drupal-settings-setup-force.yml +++ b/tests/fixtures/commands/drupal-settings-setup-force.yml @@ -13,5 +13,5 @@ force: true expected: - file: "build/sites/default/settings.php" - contains: "include $app_root . '/' . $site_path . '/settings.override.php';" + contains: "include $app_root . '/' . $site_path . '/' . settings.override.php;" not_contains: "# Already existing file." diff --git a/tests/fixtures/commands/drupal-settings-setup.yml b/tests/fixtures/commands/drupal-settings-setup.yml index 53938b35..d7d74731 100644 --- a/tests/fixtures/commands/drupal-settings-setup.yml +++ b/tests/fixtures/commands/drupal-settings-setup.yml @@ -12,7 +12,7 @@ contains: "$conf[\"file_scan_ignore_directories\"] = array(0 => 'node_modules',1 => 'bower_components',2 => 'vendor',3 => 'build');" not_contains: ~ - file: "build/sites/default/settings.php" - contains: "include $app_root . '/' . $site_path . '/settings.override.php';" + contains: "include $app_root . '/' . $site_path . '/' . settings.override.php;" not_contains: ~ - configuration: @@ -47,7 +47,7 @@ contains: "$settings[\"file_scan_ignore_directories\"] = array(0 => 'build');" not_contains: ~ - file: "build/sites/default/settings.php" - contains: "include $app_root . '/' . $site_path . '/settings.overridemeplease.php';" + contains: "include $app_root . '/' . $site_path . '/' . settings.overridemeplease.php;" not_contains: ~ - configuration: @@ -64,5 +64,5 @@ contains: "$settings[\"file_scan_ignore_directories\"] = array(0 => 'build');" not_contains: ~ - file: "build/sites/inea/settings.php" - contains: "include $app_root . '/' . $site_path . '/settings.overridemeplease.php';" + contains: "include $app_root . '/' . $site_path . '/' . settings.overridemeplease.php;" not_contains: ~