From 19e1d63dab9dc114d8697ae58d7cd7d1965f20fd Mon Sep 17 00:00:00 2001 From: Roshan Lamichhane Date: Tue, 7 Feb 2023 16:55:26 +0545 Subject: [PATCH] forward-port of relative quota amount of personal space tests from stable-2.0 (#5524) --- .../features/apiSpaces/quota.feature | 17 ++++++++++++++ .../features/bootstrap/OCSContext.php | 18 +++++++++++++++ .../features/bootstrap/SpacesContext.php | 23 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/tests/acceptance/features/apiSpaces/quota.feature b/tests/acceptance/features/apiSpaces/quota.feature index 72f29d5bf..3ba1bc5d8 100644 --- a/tests/acceptance/features/apiSpaces/quota.feature +++ b/tests/acceptance/features/apiSpaces/quota.feature @@ -65,3 +65,20 @@ Feature: State of the quota And user "Alice" has uploaded a file inside space "Project Delta" with content "7 bytes" to "test.txt" When user "Alice" uploads a file inside space "Project Delta" with content "00011 bytes" to "test.txt" using the WebDAV API Then the HTTP status code should be "507" + + + Scenario Outline: Check the relative amount of quota of personal space + Given user "Admin" has changed the quota of the personal space of "Alice Hansen" space to "10000" + And user "Alice" has uploaded file "" to "/demo.txt" + When the user "Alice" requests these endpoints with "GET" with basic auth + | endpoint | + | | + Then the HTTP status code should be "200" + And the OCS status code should be "" + And the relative quota amount should be "" + Examples: + | 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 | diff --git a/tests/acceptance/features/bootstrap/OCSContext.php b/tests/acceptance/features/bootstrap/OCSContext.php index 75f7ea6a8..afe400ab0 100644 --- a/tests/acceptance/features/bootstrap/OCSContext.php +++ b/tests/acceptance/features/bootstrap/OCSContext.php @@ -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. diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 189588d7a..938b3f761 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3226,4 +3226,27 @@ class SpacesContext implements Context { ) ); } + + /** + * @Then the relative quota amount should be :quota_amount + * + * @param string $quotaAmount + * + * @return void + * @throws Exception + */ + 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" + ); + } + } }