Skip to content

Commit

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

/**
* @Then the system config key :key from previous command output should contain value :value
*
* @param string $key
* @param string $value
*
* @return void
*/
public function theSystemConfigKeyFromPreviousCommandOutputShouldContainValue(
$key, $value
) {
// convert value to boolean if it's 'true' or 'false'
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
);
}

PHPUnit\Framework\Assert::assertEquals(
$value,
$system_config[$key],
"config: $key doesn't contain value: $value"
);
}

/**
* @Then the system config key :key from previous command output should contain following:
*
* @param string $key
* @param TableNode $table
*
* @return void
*/
public function theSystemConfigKeyFromPreviousOutputShouldContainFollowing($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" from previous command output 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" from previous command output 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" from previous command output 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" from previous command output should contain value "true"

0 comments on commit 6e9e1cc

Please sign in to comment.