mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-06 19:40:42 -05:00
[tests-only][full-ci] refactor profind response (#7327)
* 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:
@@ -133,36 +133,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'] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4866,16 +4866,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,
|
||||
@@ -5045,7 +5046,7 @@ trait WebDav {
|
||||
},
|
||||
$elementRows
|
||||
);
|
||||
$resultEntries = $this->findEntryFromPropfindResponse(null, $user, "REPORT");
|
||||
$resultEntries = $this->findEntryFromSearchResponse();
|
||||
foreach ($resultEntries as $resultEntry) {
|
||||
Assert::assertContains($resultEntry, $expectedEntries);
|
||||
}
|
||||
@@ -5121,7 +5122,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");
|
||||
}
|
||||
}
|
||||
@@ -5140,7 +5141,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");
|
||||
}
|
||||
}
|
||||
@@ -5261,7 +5262,6 @@ trait WebDav {
|
||||
*
|
||||
* @param string|null $entryNameToSearch
|
||||
* @param string|null $user
|
||||
* @param string|null $method
|
||||
* @param string $type
|
||||
* @param string $folderPath
|
||||
*
|
||||
@@ -5276,7 +5276,6 @@ trait WebDav {
|
||||
public function findEntryFromPropfindResponse(
|
||||
?string $entryNameToSearch = null,
|
||||
?string $user = null,
|
||||
?string $method = null,
|
||||
string $type = "files",
|
||||
string $folderPath = ''
|
||||
) {
|
||||
@@ -5305,19 +5304,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, "/");
|
||||
@@ -5369,12 +5355,25 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 |
|
||||
|
||||
Reference in New Issue
Block a user