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 22, 2019
1 parent 74ead9c commit e712d32
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tests/acceptance/features/bootstrap/OccContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,95 @@ public function getLastJobIdForJob($job) {
return false;
}

/**
* @Then the system config key :key from the last command output should contain value :value of type :type
*
* @param string $key
* @param string $value
* @param string $type
*
* @return void
*/
public function theSystemConfigKeyFromLastCommandOutputShouldContainValue(
$key, $value, $type
) {
// 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;
}
$configList = \json_decode(
$this->featureContext->getStdOutOfOccCommand(), true
);
$system_config = $configList['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 the last command output should contain following:
*
* @param string $key
* @param TableNode $table table of key value pair with heading 'key', 'value' and 'type' where type is the type of value
*
* @return void
*/
public function theSystemConfigKeyFromLastOutputShouldContainFollowing($key, TableNode $table) {
$configList = \json_decode(
$this->featureContext->getStdOutOfOccCommand(), true
);
$systemConfig = $configList['system'];
// get the value for the given key
$configArray = $systemConfig[$key];

// there can be array of configs inside the given key
// so, we loop inside them
foreach ($configArray as $innerConfigArray) {
$foundCount = 0;
// loop inside the key value pair given in the tableNode
foreach ($table as $value) {
// convert the value to it's respective type based on type given in the type column
if ($value['type'] === 'boolean') {
$value['value'] = $value['value'] === 'true' ? true : false;
} elseif ($value['type'] === 'integer') {
$value['value'] = (int) $value['value'];
}

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

/* if the one of the value in the given table node is found in the config list
increment the foundCount value
Note: all the values from the tableNode should be present inside the same
config array that's why foundCount is used */
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 the last command output should contain following:
| key | value | type |
| url | /apps | string |
| writable | false | boolean |

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 contain following:
| key | value | type |
| url | /apps-external | string |
| writable | true | boolean |

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 contain value "UTC" of type "string"

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 the last command output should contain value "true" of type "boolean"

0 comments on commit e712d32

Please sign in to comment.