[tests-only][full-ci] refactor profind response (#7327) (#7450)

* refactor profind response for path checking strictly

* refactor searchResponse also for xpath checking

---------

Co-authored-by: nabim777 <“nabinalemagar019@gmail.com”>
This commit is contained in:
Nalem7
2023-10-10 17:27:39 +05:45
committed by GitHub
parent 6aa19c8f6e
commit 3da78b2919
3 changed files with 63 additions and 66 deletions

View File

@@ -128,36 +128,27 @@ class SearchContext implements Context {
$user = $this->featureContext->getActualUsername($user);
$this->featureContext->verifyTableNodeColumns($properties, ['name', 'value']);
$properties = $properties->getHash();
$fileResult = $this->featureContext->findEntryFromPropfindResponse(
$path,
$user,
"REPORT",
$fileResult = $this->featureContext->findEntryFromSearchResponse(
$path
);
Assert::assertNotFalse(
$fileResult,
"could not find file/folder '$path'"
);
$fileProperties = $fileResult['value'][1]['value'][0]['value'];
foreach ($properties as $property) {
$foundProperty = false;
$property['value'] = $this->featureContext->substituteInLineCodes(
$property['value'],
$user
);
foreach ($fileProperties as $fileProperty) {
if ($fileProperty['name'] === $property['name']) {
Assert::assertMatchesRegularExpression(
"/" . $property['value'] . "/",
$fileProperty['value']
);
$foundProperty = true;
break;
}
$fileResultProperty = $fileResult->xpath("d:propstat//" . $property['name']);
if ($fileResultProperty) {
Assert::assertMatchesRegularExpression(
"/" . $property['value'] . "/",
\trim((string)$fileResultProperty[0])
);
continue;
}
Assert::assertTrue(
$foundProperty,
"could not find property '" . $property['name'] . "'"
);
throw new Error("Could not find property '" . $property['name'] . "'");
}
}

View File

@@ -4865,16 +4865,17 @@ trait WebDav {
$fileFound = $this->findEntryFromSearchResponse(
$resource
);
if (\is_object($fileFound)) {
$fileFound = $fileFound->xpath("d:propstat//oc:name");
}
} else {
$fileFound = $this->findEntryFromPropfindResponse(
$resource,
$user,
$method,
"files",
$folderpath
);
}
if ($should) {
Assert::assertNotEmpty(
$fileFound,
@@ -5044,7 +5045,7 @@ trait WebDav {
},
$elementRows
);
$resultEntries = $this->findEntryFromPropfindResponse(null, $user, "REPORT");
$resultEntries = $this->findEntryFromSearchResponse();
foreach ($resultEntries as $resultEntry) {
Assert::assertContains($resultEntry, $expectedEntries);
}
@@ -5120,7 +5121,7 @@ trait WebDav {
$type = $this->usingOldDavPath ? "public-files" : "public-files-new";
foreach ($table->getHash() as $row) {
$path = $this->substituteInLineCodes($row['name']);
$res = $this->findEntryFromPropfindResponse($path, $user, null, $type);
$res = $this->findEntryFromPropfindResponse($path, $user, $type);
Assert::assertNotFalse($res, "expected $path to be in DAV response but was not found");
}
}
@@ -5139,7 +5140,7 @@ trait WebDav {
$type = $this->usingOldDavPath ? "public-files" : "public-files-new";
foreach ($table->getHash() as $row) {
$path = $this->substituteInLineCodes($row['name']);
$res = $this->findEntryFromPropfindResponse($path, $user, null, $type);
$res = $this->findEntryFromPropfindResponse($path, $user, $type);
Assert::assertFalse($res, "expected $path to not be in DAV response but was found");
}
}
@@ -5260,7 +5261,6 @@ trait WebDav {
*
* @param string|null $entryNameToSearch
* @param string|null $user
* @param string|null $method
* @param string $type
* @param string $folderPath
*
@@ -5275,7 +5275,6 @@ trait WebDav {
public function findEntryFromPropfindResponse(
?string $entryNameToSearch = null,
?string $user = null,
?string $method = null,
string $type = "files",
string $folderPath = ''
) {
@@ -5304,19 +5303,6 @@ trait WebDav {
$results = [];
foreach ($multistatusResults as $multistatusResult) {
$entryPath = $multistatusResult['value'][0]['value'];
if ($method === "REPORT") {
if ($entryNameToSearch !== null && str_ends_with($entryPath, $entryNameToSearch)) {
return $multistatusResult;
} else {
$spaceId = (WebDavHelper::$SPACE_ID_FROM_OCIS) ?: WebDavHelper::getPersonalSpaceIdForUser(
$this->getBaseUrl(),
$user,
$this->getPasswordForUser($user),
$this->getStepLineRef()
);
$topWebDavPath = "/remote.php/dav/spaces/" . $spaceId . "/" . $folderPath;
}
}
$entryName = \str_replace($topWebDavPath, "", $entryPath);
$entryName = \rawurldecode($entryName);
$entryName = \trim($entryName, "/");
@@ -5336,6 +5322,7 @@ trait WebDav {
* and returns found search results if found else returns false
*
* @param string|null $entryNameToSearch
* @param bool|null $searchForHighlightString
*
* @return string|array|boolean
*
@@ -5343,10 +5330,11 @@ trait WebDav {
* array if $entryNameToSearch is not given
* boolean false if $entryNameToSearch is given and is not found
*
* @throws GuzzleException
* @throws Exception
*/
public function findEntryFromSearchResponse(
?string $entryNameToSearch = null
?string $entryNameToSearch = null,
?bool $searchForHighlightString = false
) {
// trim any leading "/" passed by the caller, we can just match the "raw" name
if ($entryNameToSearch !== null) {
@@ -5366,9 +5354,27 @@ trait WebDav {
}
$resourcePath = \rawurldecode($resourcePath);
if ($entryNameToSearch === $resourcePath) {
return $resourcePath;
// If searching for single entry,
// we return an SimpleXmlElement of found item
return $item;
}
if ($searchForHighlightString) {
// If searching for highlighted string,
// we return an array of entries with highlighted content as value
// Example:
// [
// "<entryName1>" => "<highlighted-content>"
// "<entryName2>" => "<highlighted-content>"
// ]
$actualHighlightString = $item->xpath("d:propstat//oc:highlights");
$results[$resourcePath] = (string)$actualHighlightString[0];
} else {
// If list all the entries i.e. $entryNameToSearch=null,
// we return an array of entries in the response
// Example:
// ["<entry1>", "<entry2>"]
$results[] = $resourcePath;
}
$results[] = $resourcePath;
}
if ($entryNameToSearch === null) {
return $results;

View File

@@ -186,23 +186,23 @@ Feature: Search
When user "Alice" searches for "upload" using the WebDAV API requesting these properties:
| oc:fileid |
| oc:permissions |
| a:getlastmodified |
| a:getetag |
| a:getcontenttype |
| d:getlastmodified |
| d:getetag |
| d:getcontenttype |
| oc:size |
| oc:owner-id |
| oc:owner-display-name |
Then the HTTP status code should be "207"
And file "/upload.txt" in the search result of user "Alice" should contain these properties:
| name | value |
| {http://owncloud.org/ns}fileid | \d* |
| {http://owncloud.org/ns}permissions | ^(RDNVW\|RMDNVW)$ |
| {DAV:}getlastmodified | ^[MTWFS][uedhfriatno]{2},\s(\d){2}\s[JFMAJSOND][anebrpyulgctov]{2}\s\d{4}\s\d{2}:\d{2}:\d{2} GMT$ |
| {DAV:}getetag | ^\"[a-f0-9:\.]{1,32}\"$ |
| {DAV:}getcontenttype | text\/plain |
| {http://owncloud.org/ns}size | 15 |
| {http://owncloud.org/ns}owner-id | %username% |
| {http://owncloud.org/ns}owner-display-name | %displayname% |
| name | value |
| oc:fileid | \d* |
| oc:permissions | ^(RDNVW\|RMDNVW)$ |
| d:getlastmodified | ^[MTWFS][uedhfriatno]{2},\s(\d){2}\s[JFMAJSOND][anebrpyulgctov]{2}\s\d{4}\s\d{2}:\d{2}:\d{2} GMT$ |
| d:getetag | ^\"[a-f0-9:\.]{1,32}\"$ |
| d:getcontenttype | text\/plain |
| oc:size | 15 |
| oc:owner-id | %username% |
| oc:owner-display-name | %displayname% |
Examples:
| dav-path-version |
| old |
@@ -219,22 +219,22 @@ Feature: Search
When user "Alice" searches for "upload" using the WebDAV API requesting these properties:
| oc:fileid |
| oc:permissions |
| a:getlastmodified |
| a:getetag |
| a:getcontenttype |
| d:getlastmodified |
| d:getetag |
| d:getcontenttype |
| oc:size |
| oc:owner-id |
| oc:owner-display-name |
Then the HTTP status code should be "207"
And folder "/upload folder" in the search result of user "Alice" should contain these properties:
| name | value |
| {http://owncloud.org/ns}fileid | \d* |
| {http://owncloud.org/ns}permissions | ^(RDNVCK\|RMDNVCK)$ |
| {DAV:}getlastmodified | ^[MTWFS][uedhfriatno]{2},\s(\d){2}\s[JFMAJSOND][anebrpyulgctov]{2}\s\d{4}\s\d{2}:\d{2}:\d{2} GMT$ |
| {DAV:}getetag | ^\"[a-f0-9:\.]{1,32}\"$ |
| {http://owncloud.org/ns}size | 0 |
| {http://owncloud.org/ns}owner-id | %username% |
| {http://owncloud.org/ns}owner-display-name | %displayname% |
| name | value |
| oc:fileid | \d* |
| oc:permissions | ^(RDNVCK\|RMDNVCK)$ |
| d:getlastmodified | ^[MTWFS][uedhfriatno]{2},\s(\d){2}\s[JFMAJSOND][anebrpyulgctov]{2}\s\d{4}\s\d{2}:\d{2}:\d{2} GMT$ |
| d:getetag | ^\"[a-f0-9:\.]{1,32}\"$ |
| oc:size | 0 |
| oc:owner-id | %username% |
| oc:owner-display-name | %displayname% |
Examples:
| dav-path-version |
| old |