From 8d70e94ae4f9b7973ec3997c6b226a5e2cb8783e Mon Sep 17 00:00:00 2001 From: Dipak Acharya Date: Fri, 2 Nov 2018 10:32:43 +0545 Subject: [PATCH] Add cli test for adding, deleting and listing system and app configs --- .../features/bootstrap/OccContext.php | 127 ++++++++++++++++++ .../features/cliMain/configKey.feature | 35 +++++ 2 files changed, 162 insertions(+) create mode 100644 tests/acceptance/features/cliMain/configKey.feature diff --git a/tests/acceptance/features/bootstrap/OccContext.php b/tests/acceptance/features/bootstrap/OccContext.php index 8787bc65b696..969142e3ca38 100644 --- a/tests/acceptance/features/bootstrap/OccContext.php +++ b/tests/acceptance/features/bootstrap/OccContext.php @@ -715,6 +715,133 @@ public function theBackgroundJobsModeShouldBe($mode) { PHPUnit_Framework_Assert::assertEquals($mode, \trim($lastOutput)); } + /** + * @When the administrator adds a config key :key with value :value in app :app using the occ command + * + * @param string $key + * @param string $value + * @param string $app + * + * @return void + */ + public function theAdministratorAddsAConfigKeyWithValueInAppUsingTheOccCommand($key, $value, $app) { + $this->featureContext->invokingTheCommand( + "config:app:set --value ${value} ${app} ${key}" + ); + } + + /** + * @When the administrator deletes the config key :key of app :app using the occ command + * + * @param string $key + * @param string $app + * + * @return void + */ + public function theAdministratorDeletesTheConfigKeyOfAppUsingTheOccCommand($key, $app) { + $this->featureContext->invokingTheCommand( + "config:app:delete ${app} ${key}" + ); + } + + /** + * @When the administrator adds a system config key :key with value :value using the occ command + * + * @param string $key + * @param string $value + * + * @return void + */ + public function theAdministratorAddsASystemConfigKeyWithValueUsingTheOccCommand($key, $value) { + $this->featureContext->invokingTheCommand( + "config:system:set --value ${value} ${key}" + ); + } + + /** + * @When the administrator deletes a system config key :key using the occ command + * + * @param string $key + * + * @return void + */ + public function theAdministratorDeletesASystemConfigKeyUsingTheOccCommand($key) { + $this->featureContext->invokingTheCommand( + "config:system:delete ${key}" + ); + } + + /** + * @Then the system config key :key with value :value should exist + * + * @param string $key + * @param string $value + * + * @return void + */ + public function theSystemConfigKeyWithValueShouldExist($key, $value) { + $config = \trim($this->featureContext->getSystemConfigValue($key)); + PHPUnit_Framework_Assert::assertSame($value, $config); + } + + /** + * @Then the system config key :key should not exist + * + * @param string $key + * + * @return void + */ + public function theSystemConfigKeyShouldNotExist($key) { + PHPUnit_Framework_Assert::assertEmpty($this->featureContext->getSystemConfig($key)['stdOut']); + } + + /** + * @When the administrator lists the config keys + * + * @return void + */ + public function theAdministratorListsTheConfigKeys() { + $this->featureContext->invokingTheCommand( + "config:list" + ); + } + + /** + * @Then the command output should contain the apps configs + * + * @return void + */ + public function theCommandOutputShouldContainTheAppsConfigs() { + $config_list = \json_decode($this->featureContext->getStdOutOfOccCommand(), true); + PHPUnit_Framework_Assert::assertArrayHasKey( + 'apps', + $config_list, + "The occ output doesnot contain apps configs" + ); + PHPUnit_Framework_Assert::assertNotEmpty( + $config_list['apps'], + "The occ output doesnot contain apps configs" + ); + } + + /** + * @Then the command output should contain the system configs + * + * @return void + */ + public function theCommandOutputShouldContainTheSystemConfigs() { + $config_list = \json_decode($this->featureContext->getStdOutOfOccCommand(), true); + PHPUnit_Framework_Assert::assertArrayHasKey( + 'system', + $config_list, + "The occ output doesnot contain system configs" + ); + PHPUnit_Framework_Assert::assertNotEmpty( + $config_list['system'], + "The occ output doesnot contain system configs" + ); + } + /** * 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 new file mode 100644 index 000000000000..4c900d0eaf9f --- /dev/null +++ b/tests/acceptance/features/cliMain/configKey.feature @@ -0,0 +1,35 @@ +@cli +Feature: add and delete app configs using occ command + + As an administrator + I want to be able to add and delete app configs via the command line + + Scenario: admin adds and deletes a config for an app using the occ command + When the administrator adds a config key "con" with value "conkey" in app "core" using the occ command + Then the command should have been successful + And the command output should contain the text 'Config value con for app core set to conkey' + And the config key "con" of app "core" must have value "conkey" + When the administrator deletes the config key "con" of app "core" using the occ command + Then the command should have been successful + And the command output should contain the text 'Config value con of app core deleted' + And the app "core" should not have config key "con" + + Scenario: admin adds and deletes a system config + When the administrator adds a system config key "con" with value "conkey" using the occ command + Then the command should have been successful + And the command output should contain the text 'System config value con set to string conkey' + And the system config key "con" with value "conkey" should exist + When the administrator deletes a system config key "con" using the occ command + Then the command should have been successful + And the command output should contain the text 'System config value con deleted' + And the system config key "con" should not exist + + Scenario: admin can list system config + When the administrator lists the config keys + Then the command should have been successful + And the command output should contain the system configs + + Scenario: admin can list app config + When the administrator lists the config keys + Then the command should have been successful + And the command output should contain the apps configs \ No newline at end of file