Skip to content

Commit

Permalink
Add cli tests for config file values
Browse files Browse the repository at this point in the history
  • Loading branch information
paurakhsharma committed May 20, 2019
1 parent c0dc3cd commit 9201414
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/acceptance/features/bootstrap/OccContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,79 @@ public function theAdministratorHasClearedTheVersionsForAllUsers() {
);
}

/**
* @Then the system config key :key should contain value :value
*
* @param string $key
* @param string $value
*
* @return void
*/
public function theSystemConfigKeyShouldContainValue($key, $value) {
// if expected value if 'true' or 'false' convert them to boolean
if ($value === "true" || $value === "false") {
$value = $value === "true";
}
$config_list = \json_decode(
$this->featureContext->getStdOutOfOccCommand(), true
);
$system_config = $config_list['system'];

if (!\array_key_exists($key, $system_config)) {
PHPUnit\Framework\Assert::fail(
"system config doesn't contain key: " . $key
);
}

if ($system_config[$key] === $value) {
return;
}

PHPUnit\Framework\Assert::fail("config: $key doesn't contain value: $value");
}

/**
* @Then the system config key :key should contain following:
*
* @param string $key
* @param TableNode $table
*
* @return void
*/
public function theSystemConfigKeyShouldContainFollowing($key, TableNode $table) {
$foundCount = 0;
$config_list = \json_decode(
$this->featureContext->getStdOutOfOccCommand(), true
);
$system_config = $config_list['system'];
$configArray = $system_config[$key];

foreach ($configArray as $innerConfigArray) {
foreach ($table as $value) {
if ($value['value'] === "true" || $value['value'] === "false") {
$value['value'] = $value['value'] === "true";
}

if (!\array_key_exists($value['key'], $innerConfigArray)) {
PHPUnit\Framework\Assert::fail(
"$key config doesn't contain key: " . $value['key']
);
}

if ($innerConfigArray[$value['key']] === $value['value']) {
$foundCount++;
}
}

if ($foundCount === (\count($table->getRows()) - 1)) {
return;
}
}
PHPUnit\Framework\Assert::fail(
"Config key: $key doesn't contain given key value pair"
);
}

/**
* This will run before EVERY scenario.
* It will set the properties for this object.
Expand Down
25 changes: 25 additions & 0 deletions tests/acceptance/features/cliMain/configKey.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,28 @@ 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" should contain following:
| key | value |
| url | /apps |
| writable | false |

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" should contain following:
| key | value |
| url | /apps-external|
| writable | true |

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" should contain value "UTC"

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 "installed" should contain value "true"

0 comments on commit 9201414

Please sign in to comment.