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 23, 2019
1 parent 6db604e commit 314609a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/acceptance/features/bootstrap/OccContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions tests/acceptance/features/cliMain/configKey.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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 match value "true" of type "boolean"

0 comments on commit 314609a

Please sign in to comment.