Added necessary helper function
This commit is contained in:
1 parent
4e69478625
commit
15c152bd62
3 files changed
+39
-31
No files matched your search
@@ -74,15 +74,11 @@ Feature: State of the quota
|
||||
| endpoint |
|
||||
| <end_point> |
|
||||
Then the HTTP status code should be "200"
|
||||
And the json responded should contain these key and value pairs:
|
||||
| key | value |
|
||||
| quota@@@free | <quota_free> |
|
||||
| quota@@@used | <quota_used> |
|
||||
| quota@@@total | <quota_total> |
|
||||
| quota@@@relative | <quota_relative> |
|
||||
And the OCS status code should be "<ocs_code>"
|
||||
And the relative quota amount should be "<quota_relative>"
|
||||
Examples:
|
||||
| file_upload | end_point | quota_free | quota_used | quota_total | quota_relative |
|
||||
| /filesForUpload/lorem.txt | /ocs/v1.php/cloud/users/Alice?format=json | 9301 | 699 | 10000 | 6.99 |
|
||||
| /filesForUpload/lorem-big.txt | /ocs/v1.php/cloud/users/Alice?format=json | 883 | 9117 | 10000 | 91.17 |
|
||||
| /filesForUpload/lorem.txt | /ocs/v2.php/cloud/users/Alice?format=json | 9301 | 699 | 10000 | 6.99 |
|
||||
| /filesForUpload/lorem-big.txt | /ocs/v2.php/cloud/users/Alice?format=json | 883 | 9117 | 10000 | 91.17 |
|
||||
| file_upload | end_point | ocs_code | quota_relative |
|
||||
| /filesForUpload/lorem.txt | /ocs/v1.php/cloud/users/%username% | 100 | 6.99 |
|
||||
| /filesForUpload/lorem-big.txt | /ocs/v1.php/cloud/users/%username% | 100 | 91.17 |
|
||||
| /filesForUpload/lorem.txt | /ocs/v2.php/cloud/users/%username% | 200 | 6.99 |
|
||||
| /filesForUpload/lorem-big.txt | /ocs/v2.php/cloud/users/%username% | 200 | 91.17 |
|
||||
@@ -940,6 +940,24 @@ class OCSContext implements Context {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the xml answer to return data items from ocs response
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getOCSResponseData(ResponseInterface $response): SimpleXMLElement {
|
||||
$responseXml = $this->featureContext->getResponseXml($response, __METHOD__);
|
||||
if (isset($responseXml->data)) {
|
||||
return $responseXml->data;
|
||||
}
|
||||
throw new Exception(
|
||||
"No OCS data items found in responseXml"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the xml answer to get ocs response message which doesn't match with
|
||||
* http one in v1 of the api.
|
||||
|
||||
@@ -3136,31 +3136,25 @@ class SpacesContext implements Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the json responded should contain these key and value pairs:$/
|
||||
* @Then the relative quota amount should be :quota_amount
|
||||
*
|
||||
* Loops through data items in response to find given key and value pairs
|
||||
* It does not support field value replacing
|
||||
*
|
||||
* @param TableNode $table
|
||||
* @param string $quotaAmount
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function theJsonRespondedShouldContainTheseKeyAndValuePairs(TableNode $table):void {
|
||||
$this->featureContext->verifyTableNodeColumns($table, ['key', 'value']);
|
||||
$response = json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = $response["ocs"]["data"];
|
||||
foreach ($table->getHash() as $row) {
|
||||
$key = $row['key'];
|
||||
$expectedValue = $row['value'];
|
||||
$segments = explode('@@@', $key);
|
||||
$actualValue = $data;
|
||||
foreach ($segments as $segment) {
|
||||
$arrayKeyExists = \array_key_exists($segment, $actualValue);
|
||||
Assert::assertTrue($arrayKeyExists, "The key $segment does not exist on the response");
|
||||
$actualValue = $actualValue[$segment];
|
||||
}
|
||||
Assert::assertEquals($expectedValue, $actualValue, "Expected $expectedValue but received $actualValue");
|
||||
public function theRelativeQuotaAmountShouldBe(string $quotaAmount): void {
|
||||
$data = $this->ocsContext->getOCSResponseData($this->featureContext->getResponse());
|
||||
if (isset($data->quota, $data->quota->relative)) {
|
||||
Assert::assertEquals(
|
||||
$data->quota->relative,
|
||||
$quotaAmount,
|
||||
"Expected relative quota amount to be $quotaAmount but found to be $data->quota->relative"
|
||||
);
|
||||
} else {
|
||||
throw new Exception(
|
||||
"No relative quota amount found in responseXml"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user