Skip to content

Commit 123aab9

Browse files
authored
Merge pull request #10247 from owncloud/tests/test-coverage-7815-parent-id
[tests-only][full-ci] check parent-id of shares
2 parents 749074e + 669a5eb commit 123aab9

File tree

3 files changed

+86
-15
lines changed

3 files changed

+86
-15
lines changed

tests/acceptance/bootstrap/SpacesContext.php

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4000,12 +4000,50 @@ public function asUsertheXMLResponseShouldContainMountpointWithTheseKeyAndValueP
40004000
}
40014001

40024002
/**
4003-
* @param string $resource // can be resource name, space id or file id
4004-
* @param array $properties // ["key" => "value"]
4003+
* @param SimpleXMLElement $responseXmlObject
4004+
* @param array $xpaths
4005+
* @param string $message
4006+
*
4007+
* @return string
4008+
*/
4009+
public function buildXpathErrorMessage(SimpleXMLElement $responseXmlObject, array $xpaths, string $message): string {
4010+
return "Using xpaths:\n\t- " . \join("\n\t- ", $xpaths)
4011+
. "\n"
4012+
. $message
4013+
. "\n\t"
4014+
. "'" . \trim($responseXmlObject->asXML()) . "'";
4015+
}
4016+
4017+
/**
4018+
* @param SimpleXMLElement $responseXmlObject
4019+
* @param string $siblingXpath
4020+
* @param string $siblingToFind
4021+
*
4022+
* @return string
4023+
* @throws Exception
4024+
*/
4025+
public function getXpathSiblingValue(SimpleXMLElement $responseXmlObject, string $siblingXpath, string $siblingToFind): string {
4026+
$xpaths[] = $siblingXpath . "/preceding-sibling::$siblingToFind";
4027+
$xpaths[] = $siblingXpath . "/following-sibling::$siblingToFind";
4028+
4029+
foreach ($xpaths as $key => $xpath) {
4030+
$foundSibling = $responseXmlObject->xpath($xpath);
4031+
if (\count($foundSibling)) {
4032+
break;
4033+
}
4034+
}
4035+
$errorMessage = $this->buildXpathErrorMessage($responseXmlObject, $xpaths, "Could not find sibling '<$siblingToFind>' element in the XML response");
4036+
Assert::assertNotEmpty($foundSibling, $errorMessage);
4037+
return \preg_quote($foundSibling[0]->__toString(), "/");
4038+
}
4039+
4040+
/**
4041+
* @param string $resource // can be resource name, space id or file id
4042+
* @param array $properties // ["key" => "value"]
40054043
*
40064044
* @return void
40074045
* @throws GuzzleException
4008-
* @throws JsonException
4046+
* @throws Exception
40094047
*/
40104048
public function theXMLResponseShouldContain(string $resource, array $properties): void {
40114049
$responseXmlObject = HttpRequestHelper::getResponseXml($this->featureContext->getResponse(), __METHOD__);
@@ -4056,17 +4094,39 @@ public function theXMLResponseShouldContain(string $resource, array $properties)
40564094
$xpaths[] = $xpath;
40574095
}
40584096

4097+
Assert::assertCount(
4098+
1,
4099+
$foundXmlItem,
4100+
$this->buildXpathErrorMessage($responseXmlObject, $xpaths, "Found multiple elements for '<$itemToFind>' in the XML response")
4101+
);
40594102
Assert::assertNotEmpty(
40604103
$foundXmlItem,
4061-
// all these for the sake of a nice error message
4062-
"Using xpaths:\n\t- " . \join("\n\t- ", $xpaths)
4063-
. "\n"
4064-
. "Could not find '<$itemToFind>' element in the XML response\n\t"
4065-
. "'" . \trim($responseXmlObject->asXML()) . "'"
4104+
$this->buildXpathErrorMessage($responseXmlObject, $xpaths, "Could not find '<$itemToFind>' element in the XML response")
40664105
);
40674106

40684107
$actualValue = $foundXmlItem[0]->__toString();
4069-
$expectedValue = $this->featureContext->substituteInLineCodes($property['value']);
4108+
$expectedValue = $property['value'];
4109+
\preg_match_all("/%self::[a-z0-9-:]+?%/", $expectedValue, $selfMatches);
4110+
$substituteFunctions = [];
4111+
if (!empty($selfMatches[0])) {
4112+
$siblingXpath = $xpaths[\count($xpaths) - 1];
4113+
foreach ($selfMatches[0] as $match) {
4114+
$siblingToFind = \ltrim($match, "/%self::/");
4115+
$siblingToFind = \rtrim($siblingToFind, "/%/");
4116+
$substituteFunctions[] = [
4117+
"code" => $match,
4118+
"function" =>
4119+
[$this, "getXpathSiblingValue"],
4120+
"parameter" => [$responseXmlObject, $siblingXpath, $siblingToFind]
4121+
];
4122+
}
4123+
}
4124+
$expectedValue = $this->featureContext->substituteInLineCodes(
4125+
$property['value'],
4126+
null,
4127+
[],
4128+
$substituteFunctions,
4129+
);
40704130

40714131
switch ($itemToFind) {
40724132
case "oc:fileid":

tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,5 +318,9 @@ The expected failures in this file are from features in the owncloud/ocis repo.
318318
- [apiSearchContent/contentSearch.feature:266](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSearchContent/contentSearch.feature#L266)
319319
- [apiSearchContent/contentSearch.feature:267](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSearchContent/contentSearch.feature#L267)
320320

321+
#### [Shares Jail PROPFIND returns different File IDs for the same item](https://github.com/owncloud/ocis/issues/9933)
322+
323+
- [apiSharingNg1/propfindShares.feature:149](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSharingNg1/propfindShares.feature#L149)
324+
321325
Note: always have an empty line at the end of this file.
322326
The bash script that processes this file requires that the last line has a newline on the end.

tests/acceptance/features/apiSharingNg1/propfindShares.feature

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,25 @@ Feature: propfind a shares
123123
When user "Brian" sends PROPFIND request from the space "Shares" to the resource "/" using the WebDAV API
124124
Then the HTTP status code should be "207"
125125
And as user "Brian" the PROPFIND response should contain a resource "folderToShare" with these key and value pairs:
126-
| key | value |
127-
| oc:fileid | <pattern> |
126+
| key | value |
127+
| oc:fileid | <pattern> |
128+
| oc:file-parent | %self::oc:spaceid%!%uuidv4_pattern% |
128129
When user "Brian" sends PROPFIND request from the space "Shares" to the resource "folderToShare" using the WebDAV API
129130
Then the HTTP status code should be "207"
130131
And as user "Brian" the PROPFIND response should contain a resource "folderToShare" with these key and value pairs:
131-
| key | value |
132-
| oc:fileid | <pattern> |
132+
| key | value |
133+
| oc:fileid | <pattern> |
134+
| oc:file-parent | %self::oc:spaceid%!%uuidv4_pattern% |
135+
And as user "Brian" the PROPFIND response should contain a resource "folderToShare/textfile.txt" with these key and value pairs:
136+
| key | value |
137+
| oc:fileid | %file_id_pattern% |
138+
| oc:file-parent | %self::oc:spaceid%!%uuidv4_pattern% |
133139
When user "Brian" sends PROPFIND request from the space "Shares" to the resource "folderToShare/textfile.txt" using the WebDAV API
134140
Then the HTTP status code should be "207"
135141
And as user "Brian" the PROPFIND response should contain a resource "folderToShare/textfile.txt" with these key and value pairs:
136-
| key | value |
137-
| oc:fileid | %file_id_pattern% |
142+
| key | value |
143+
| oc:fileid | %file_id_pattern% |
144+
| oc:file-parent | %self::oc:spaceid%!%uuidv4_pattern% |
138145
Examples:
139146
| dav-path-version | pattern |
140147
| old | %file_id_pattern% |

0 commit comments

Comments
 (0)