From 20149a7a8c332d072563ba3024419c631ecbf95b Mon Sep 17 00:00:00 2001 From: paurakhsharma Date: Tue, 21 May 2019 13:33:32 +0545 Subject: [PATCH] Add cli tests for config.php default values --- .../features/bootstrap/OccContext.php | 49 +++++++++++++++++++ .../features/cliMain/configKey.feature | 19 +++++++ 2 files changed, 68 insertions(+) diff --git a/tests/acceptance/features/bootstrap/OccContext.php b/tests/acceptance/features/bootstrap/OccContext.php index f62e0de9c89c..7987eab2edbd 100644 --- a/tests/acceptance/features/bootstrap/OccContext.php +++ b/tests/acceptance/features/bootstrap/OccContext.php @@ -796,6 +796,55 @@ public function getLastJobIdForJob($job) { return false; } + /** + * @Then the system config key :key from the last command output should match value :value of type :type + * + * @param string $key + * @param string $value + * @param string $type + * + * @return void + */ + public function theSystemConfigKeyFromLastCommandOutputShouldContainValue( + $key, $value, $type + ) { + $configList = \json_decode( + $this->featureContext->getStdOutOfOccCommand(), true + ); + $systemConfig = $configList['system']; + + // convert the value to it's respective type based on type given in the type column + if ($type === 'boolean') { + $value = $value === 'true' ? true : false; + } elseif ($type === 'integer') { + $value = (int) $value; + } elseif ($type === 'json') { + // if the expected value of the key is a json + // match the value with the regular expression + $actualKeyValuePair = \json_encode( + $systemConfig[$key], JSON_UNESCAPED_SLASHES + ); + + PHPUnit\Framework\Assert::assertThat( + $actualKeyValuePair, + PHPUnit\Framework\Assert::matchesRegularExpression($value) + ); + return; + } + + if (!\array_key_exists($key, $systemConfig)) { + PHPUnit\Framework\Assert::fail( + "system config doesn't contain key: " . $key + ); + } + + PHPUnit\Framework\Assert::assertEquals( + $value, + $systemConfig[$key], + "config: $key doesn't contain value: $value" + ); + } + /** * This will run before EVERY scenario. * It will set the properties for this object. diff --git a/tests/acceptance/features/cliMain/configKey.feature b/tests/acceptance/features/cliMain/configKey.feature index 16d1ae08d9be..ffbc8555524b 100644 --- a/tests/acceptance/features/cliMain/configKey.feature +++ b/tests/acceptance/features/cliMain/configKey.feature @@ -35,3 +35,22 @@ Feature: add and delete app configs using occ command Then the command should have been successful And the command output should contain the apps configs + Scenario: app directory should be listed in the config file + When the administrator lists the config keys + Then the command should have been successful + And the system config key "apps_paths" from the last command output should match value '/\"url\":\"\/apps\",\"writable\":false/' of type "json" + + Scenario: app-external directory should be listed in the config + When the administrator lists the config keys + Then the command should have been successful + And the system config key "apps_paths" from the last command output should match value '/\"url\":\"\/apps-external\",\"writable\":true/' of type "json" + + Scenario: log time zone should be listed in the config file + When the administrator lists the config keys + Then the command should have been successful + And the system config key "logtimezone" from the last command output should match value "UTC" of type "string" + + Scenario: server installed should be listed in the config file + When the administrator lists the config keys + Then the command should have been successful + And the system config key "installed" from the last command output should match value "true" of type "boolean"