Skip to content

Commit

Permalink
[tests-only] removing the setresponse in given/when/then step in webd…
Browse files Browse the repository at this point in the history
…avproperties context (#7368)

* refactor given and when steps in webdavproperties context

* change the status code in tests as the when step sets the response now

* correct the status code check

* only save response

* use getResponseXml to get xml response object

* fix isEtagValid method

* rename step def methods

* make stricter checks

---------

Co-authored-by: Saw-jan <[email protected]>
  • Loading branch information
KarunAtreya and saw-jan committed Oct 5, 2023
1 parent f2f3f54 commit 9cee6bc
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 270 deletions.
20 changes: 10 additions & 10 deletions tests/acceptance/features/apiSpacesShares/shareOperations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: sharing
When user "Brian" gets the following properties of file "/tmp.txt" inside space "Shares" using the WebDAV API
| propertyName |
| ocs:share-permissions |
Then the HTTP status code should be "200"
Then the HTTP status code should be "207"
And the single response should contain a property "ocs:share-permissions" with value "19"


Expand All @@ -36,7 +36,7 @@ Feature: sharing
When user "Brian" gets the following properties of file "/tmp.txt" inside space "Shares" using the WebDAV API
| propertyName |
| ocs:share-permissions |
Then the HTTP status code should be "200"
Then the HTTP status code should be "207"
And the single response should contain a property "ocs:share-permissions" with value "19"


Expand All @@ -63,7 +63,7 @@ Feature: sharing
When user "Brian" gets the following properties of file "/tmp.txt" inside space "Shares" using the WebDAV API
| propertyName |
| ocs:share-permissions |
Then the HTTP status code should be "200"
Then the HTTP status code should be "207"
And the single response should contain a property "ocs:share-permissions" with value "3"


Expand All @@ -90,7 +90,7 @@ Feature: sharing
When user "Brian" gets the following properties of file "/tmp.txt" inside space "Shares" using the WebDAV API
| propertyName |
| ocs:share-permissions |
Then the HTTP status code should be "200"
Then the HTTP status code should be "207"
And the single response should contain a property "ocs:share-permissions" with value "17"


Expand All @@ -101,7 +101,7 @@ Feature: sharing
When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API
| propertyName |
| ocs:share-permissions |
Then the HTTP status code should be "200"
Then the HTTP status code should be "207"
And the single response should contain a property "ocs:share-permissions" with value "31"


Expand All @@ -117,7 +117,7 @@ Feature: sharing
When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API
| propertyName |
| ocs:share-permissions |
Then the HTTP status code should be "200"
Then the HTTP status code should be "207"
And the single response should contain a property "ocs:share-permissions" with value "31"


Expand All @@ -144,7 +144,7 @@ Feature: sharing
When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API
| propertyName |
| ocs:share-permissions |
Then the HTTP status code should be "200"
Then the HTTP status code should be "207"
And the single response should contain a property "ocs:share-permissions" with value "29"


Expand All @@ -171,7 +171,7 @@ Feature: sharing
When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API
| propertyName |
| ocs:share-permissions |
Then the HTTP status code should be "200"
Then the HTTP status code should be "207"
And the single response should contain a property "ocs:share-permissions" with value "27"


Expand All @@ -198,7 +198,7 @@ Feature: sharing
When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API
| propertyName |
| ocs:share-permissions |
Then the HTTP status code should be "200"
Then the HTTP status code should be "207"
And the single response should contain a property "ocs:share-permissions" with value "23"


Expand All @@ -225,7 +225,7 @@ Feature: sharing
When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API
| propertyName |
| ocs:share-permissions |
Then the HTTP status code should be "200"
Then the HTTP status code should be "207"
And the single response should contain a property "ocs:share-permissions" with value "15"


Expand Down
7 changes: 4 additions & 3 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2740,8 +2740,8 @@ public function userTriesToDownloadFileVersions(string $user, string $file, stri
*/
public function userGetsEtagOfElementInASpace(string $user, string $space, string $path) {
$this->setSpaceIDByName($user, $space);
$this->webDavPropertiesContext->storeEtagOfElement($user, $path);
return $this->featureContext->getEtagFromResponseXmlObject();
$xmlObject = $this->webDavPropertiesContext->storeEtagOfElement($user, $path);
return $this->featureContext->getEtagFromResponseXmlObject($xmlObject);
}

/**
Expand Down Expand Up @@ -3019,7 +3019,8 @@ public function userGetsTheFollowingPropertiesOfFileInsideSpaceUsingTheWebdavApi
TableNode $propertiesTable
):void {
$this->setSpaceIDByName($user, $spaceName);
$this->webDavPropertiesContext->userGetsPropertiesOfFolder($user, $resourceName, $propertiesTable);
$response = $this->webDavPropertiesContext->getPropertiesOfFolder($user, $resourceName, $propertiesTable);
$this->featureContext->setResponse($response);
}

/**
Expand Down
29 changes: 13 additions & 16 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ public function clearResponseXmlObject():void {
}

/**
* @param SimpleXMLElement|null $xmlObject
*
* @return string the etag or an empty string if the getetag property does not exist
*/
public function getEtagFromResponseXmlObject():string {
$xmlObject = $this->getResponseXmlObject();
public function getEtagFromResponseXmlObject(?SimpleXMLElement $xmlObject = null): string {
$xmlObject = $xmlObject ?? $this->getResponseXml();
$xmlPart = $xmlObject->xpath("//d:prop/d:getetag");
if (!\is_array($xmlPart) || (\count($xmlPart) === 0)) {
return '';
Expand All @@ -162,14 +163,11 @@ public function getEtagFromResponseXmlObject():string {

/**
*
* @param string|null $eTag if null then get eTag from response XML object
* @param string $eTag
*
* @return boolean
*/
public function isEtagValid(?string $eTag = null):bool {
if ($eTag === null) {
$eTag = $this->getEtagFromResponseXmlObject();
}
public function isEtagValid(string $eTag): bool {
if (\preg_match("/^\"[a-f0-9:\.]{1,32}\"$/", $eTag)
) {
return true;
Expand Down Expand Up @@ -1688,7 +1686,7 @@ public function asFileOrFolderShouldNotExist(
$statusCode = $response->getStatusCode();
if ($statusCode < 401 || $statusCode > 404) {
try {
$this->responseXmlObject = HttpRequestHelper::getResponseXml(
$responseXml = $this->featureContext->getResponseXml(
$response,
__METHOD__
);
Expand All @@ -1698,10 +1696,10 @@ public function asFileOrFolderShouldNotExist(
);
}
Assert::assertTrue(
$this->isEtagValid(),
$this->isEtagValid($this->getEtagFromResponseXmlObject($responseXml)),
"$entry '$path' should not exist. But API returned $statusCode without an etag in the body"
);
$isCollection = $this->getResponseXmlObject()->xpath("//d:prop/d:resourcetype/d:collection");
$isCollection = $responseXml->xpath("//d:prop/d:resourcetype/d:collection");
if (\count($isCollection) === 0) {
$actualResourceType = "file";
} else {
Expand Down Expand Up @@ -1757,24 +1755,23 @@ public function asFileOrFolderShouldExist(
):void {
$user = $this->getActualUsername($user);
$path = $this->substituteInLineCodes($path);
$this->responseXmlObject = $this->listFolderAndReturnResponseXml(
$responseXml = $this->listFolderAndReturnResponseXml(
$user,
$path,
'0',
null,
$type
);
Assert::assertTrue(
$this->isEtagValid(),
$this->isEtagValid($this->getEtagFromResponseXmlObject($responseXml)),
"$entry '$path' expected to exist for user $user but not found"
);
$isCollection = $this->getResponseXmlObject()->xpath("//d:prop/d:resourcetype/d:collection");
$isCollection = $responseXml->xpath("//d:prop/d:resourcetype/d:collection");
if ($entry === "folder") {
Assert::assertEquals(\count($isCollection), 1, "Unexpectedly, `$path` is not a folder");
} elseif ($entry === "file") {
Assert::assertEquals(\count($isCollection), 0, "Unexpectedly, `$path` is not a file");
}
$this->emptyLastHTTPStatusCodesArray();
}

/**
Expand Down Expand Up @@ -1838,12 +1835,12 @@ public function asExactlyOneOfTheseFilesOrFoldersShouldExist(string $user, strin
$numEntriesThatExist = 0;
foreach ($table->getTable() as $row) {
$path = $this->substituteInLineCodes($row[0]);
$this->responseXmlObject = $this->listFolderAndReturnResponseXml(
$responseXml = $this->listFolderAndReturnResponseXml(
$user,
$path,
'0'
);
if ($this->isEtagValid()) {
if ($this->isEtagValid($this->getEtagFromResponseXmlObject($responseXml))) {
$numEntriesThatExist = $numEntriesThatExist + 1;
}
}
Expand Down
Loading

0 comments on commit 9cee6bc

Please sign in to comment.