Skip to content

Commit

Permalink
Merge pull request #37902 from owncloud/issue-ocis-reva-471
Browse files Browse the repository at this point in the history
[Tests-Only] Make PROPFIND response href test checks more flexible
  • Loading branch information
phil-davis authored Sep 11, 2020
2 parents 65ee49a + b96ed20 commit e9850b4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Feature: get file properties
And user "Alice" has uploaded file with content "uploaded content" to "<folder_name>/file1.txt"
And user "Alice" has uploaded file with content "uploaded content" to "<folder_name>/file2.txt"
When user "Alice" gets the properties of folder "<folder_name>" with depth 1 using the WebDAV API
Then the value of the item "//d:response[1]/d:href" in the response to user "Alice" should match "/remote\.php\/<expected_href>\//"
And the value of the item "//d:response[2]/d:href" in the response to user "Alice" should match "/remote\.php\/<expected_href>\/file1.txt/"
And the value of the item "//d:response[3]/d:href" in the response to user "Alice" should match "/remote\.php\/<expected_href>\/file2.txt/"
Then there should be an entry with href matching "/remote\.php\/<expected_href>\//" in the response to user "Alice"
And there should be an entry with href matching "/remote\.php\/<expected_href>\/file1.txt/" in the response to user "Alice"
And there should be an entry with href matching "/remote\.php\/<expected_href>\/file2.txt/" in the response to user "Alice"
Examples:
| dav_version | folder_name | expected_href |
| old | /upload | webdav\/upload |
Expand Down
39 changes: 39 additions & 0 deletions tests/acceptance/features/bootstrap/WebDavPropertiesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,45 @@ public function assertValueOfItemInResponseRegExp($xpath, $pattern) {
);
}

/**
* @Then there should be an entry with href matching :pattern in the response to user :user
*
* @param string $pattern
* @param string $user
*
* @return void
* @throws \Exception
*/
public function assertEntryWithHrefMatchingRegExpInResponseToUser($pattern, $user) {
$resXml = $this->featureContext->getResponseXmlObject();
if ($resXml === null) {
$resXml = HttpRequestHelper::getResponseXml(
$this->featureContext->getResponse(),
__METHOD__
);
}

$user = $this->featureContext->getActualUsername($user);
$pattern = $this->featureContext->substituteInLineCodes(
$pattern, $user, ['preg_quote' => ['/']]
);

$index = 0;
while (true) {
$index++;
$xpath = "//d:response[$index]/d:href";
$xmlPart = $resXml->xpath($xpath);
// If we have run out of entries in the response, then fail the test
Assert::assertTrue(
isset($xmlPart[0]), "Cannot find any entry with href matching $pattern in response to $user"
);
$value = $xmlPart[0]->__toString();
if (\preg_match($pattern, $value) === 1) {
break;
}
}
}

/**
* @Then the value of the item :xpath in the response to user :user should match :value
*
Expand Down

0 comments on commit e9850b4

Please sign in to comment.