Skip to content

Commit

Permalink
test: check file-parent id in shares propfind
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Oct 22, 2024
1 parent f54979f commit 0d35ce6
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 13 deletions.
74 changes: 67 additions & 7 deletions tests/acceptance/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3821,13 +3821,51 @@ public function asUsertheXMLResponseShouldContainMountpointWithTheseKeyAndValueP
$this->theXMLResponseShouldContain($resource, $table->getHash());
}

/**
* @param SimpleXMLElement $xmlResponse
* @param array $xpaths
* @param string $message
*
* @return string
*/
public function buildXpathErrorMessage(SimpleXMLElement $xmlResponse, array $xpaths, string $message): string {
return "Using xpaths:\n\t- " . \join("\n\t- ", $xpaths)
. "\n"
. $message
. "\n\t"
. "'" . \trim($xmlResponse->asXML()) . "'";
}

/**
* @param SimpleXMLElement $xmlResponse
* @param string $siblingXpath
* @param string $siblingToFind
*
* @return string
* @throws Exception
*/
public function getXpathSiblingValue(SimpleXMLElement $xmlResponse, string $siblingXpath, string $siblingToFind): string {
$xpaths[] = $siblingXpath . "/preceding-sibling::$siblingToFind";
$xpaths[] = $siblingXpath . "/following-sibling::$siblingToFind";

foreach ($xpaths as $key => $xpath) {
$foundSibling = $xmlResponse->xpath($xpath);
if (\count($foundSibling)) {
break;
}
}
$errorMessage = $this->buildXpathErrorMessage($xmlResponse, $xpaths, "Could not find sibling '<$siblingToFind>' element in the XML response");
Assert::assertNotEmpty($foundSibling, $errorMessage);
return \preg_quote($foundSibling[0]->__toString(), "/");
}

/**
* @param string $resource // can be resource name, space id or file id
* @param array $properties // ["key" => "value"]
*
* @return void
* @throws GuzzleException
* @throws JsonException
* @throws Exception
*/
public function theXMLResponseShouldContain(string $resource, array $properties): void {
$xmlResponse = $this->featureContext->getResponseXml();
Expand Down Expand Up @@ -3878,17 +3916,39 @@ public function theXMLResponseShouldContain(string $resource, array $properties)
$xpaths[] = $xpath;
}

Assert::assertCount(
1,
$foundXmlItem,
$this->buildXpathErrorMessage($xmlResponse, $xpaths, "Found multiple elements for '<$itemToFind>' in the XML response")
);
Assert::assertNotEmpty(
$foundXmlItem,
// all these for the sake of a nice error message
"Using xpaths:\n\t- " . \join("\n\t- ", $xpaths)
. "\n"
. "Could not find '<$itemToFind>' element in the XML response\n\t"
. "'" . \trim($xmlResponse->asXML()) . "'"
$this->buildXpathErrorMessage($xmlResponse, $xpaths, "Could not find '<$itemToFind>' element in the XML response")
);

$actualValue = $foundXmlItem[0]->__toString();
$expectedValue = $this->featureContext->substituteInLineCodes($property['value']);
$expectedValue = $property['value'];
\preg_match_all("/%self::[a-z0-9-:]+?%/", $expectedValue, $selfMatches);
$substituteFunctions = [];
if (!empty($selfMatches[0])) {
$siblingXpath = $xpaths[\count($xpaths) - 1];
foreach ($selfMatches[0] as $match) {
$siblingToFind = \ltrim($match, "/%self::/");
$siblingToFind = \rtrim($siblingToFind, "/%/");
$substituteFunctions[] = [
"code" => $match,
"function" =>
[$this, "getXpathSiblingValue"],
"parameter" => [$xmlResponse, $siblingXpath, $siblingToFind]
];
}
}
$expectedValue = $this->featureContext->substituteInLineCodes(
$property['value'],
null,
[],
$substituteFunctions,
);

switch ($itemToFind) {
case "oc:fileid":
Expand Down
19 changes: 13 additions & 6 deletions tests/acceptance/features/apiSharingNg1/propfindShares.feature
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,25 @@ Feature: propfind a shares
When user "Brian" sends PROPFIND request from the space "Shares" to the resource "/" using the WebDAV API
Then the HTTP status code should be "207"
And as user "Brian" the PROPFIND response should contain a resource "folderToShare" with these key and value pairs:
| key | value |
| oc:fileid | <pattern> |
| key | value |
| oc:fileid | <pattern> |
| oc:file-parent | %self::oc:spaceid%!%uuidv4_pattern% |
When user "Brian" sends PROPFIND request from the space "Shares" to the resource "folderToShare" using the WebDAV API
Then the HTTP status code should be "207"
And as user "Brian" the PROPFIND response should contain a resource "folderToShare" with these key and value pairs:
| key | value |
| oc:fileid | <pattern> |
| key | value |
| oc:fileid | <pattern> |
| oc:file-parent | %self::oc:spaceid%!%uuidv4_pattern% |
And as user "Brian" the PROPFIND response should contain a resource "folderToShare/textfile.txt" with these key and value pairs:
| key | value |
| oc:fileid | %file_id_pattern% |
| oc:file-parent | %self::oc:spaceid%!%uuidv4_pattern% |
When user "Brian" sends PROPFIND request from the space "Shares" to the resource "folderToShare/textfile.txt" using the WebDAV API
Then the HTTP status code should be "207"
And as user "Brian" the PROPFIND response should contain a resource "folderToShare/textfile.txt" with these key and value pairs:
| key | value |
| oc:fileid | %file_id_pattern% |
| key | value |
| oc:fileid | %file_id_pattern% |
| oc:file-parent | %self::oc:spaceid%!%uuidv4_pattern% |
Examples:
| dav-path-version | pattern |
| old | %file_id_pattern% |
Expand Down

0 comments on commit 0d35ce6

Please sign in to comment.