From 3da78b2919db0f78e2bc9c128ad5fdd898699091 Mon Sep 17 00:00:00 2001 From: Nalem7 <61624650+nabim777@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:27:39 +0545 Subject: [PATCH] [tests-only][full-ci] refactor profind response (#7327) (#7450) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor profind response for path checking strictly * refactor searchResponse also for xpath checking --------- Co-authored-by: nabim777 <“nabinalemagar019@gmail.com”> --- .../features/bootstrap/SearchContext.php | 29 ++++------ .../acceptance/features/bootstrap/WebDav.php | 54 ++++++++++--------- .../coreApiWebdavOperations/search.feature | 46 ++++++++-------- 3 files changed, 63 insertions(+), 66 deletions(-) diff --git a/tests/acceptance/features/bootstrap/SearchContext.php b/tests/acceptance/features/bootstrap/SearchContext.php index ceed909c36..90591cd92c 100644 --- a/tests/acceptance/features/bootstrap/SearchContext.php +++ b/tests/acceptance/features/bootstrap/SearchContext.php @@ -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'] . "'"); } } diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index e663cf62b4..9b55f096d6 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -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: + // [ + // "" => "" + // "" => "" + // ] + $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: + // ["", ""] + $results[] = $resourcePath; } - $results[] = $resourcePath; } if ($entryNameToSearch === null) { return $results; diff --git a/tests/acceptance/features/coreApiWebdavOperations/search.feature b/tests/acceptance/features/coreApiWebdavOperations/search.feature index 3329cfc208..5ed7737c61 100644 --- a/tests/acceptance/features/coreApiWebdavOperations/search.feature +++ b/tests/acceptance/features/coreApiWebdavOperations/search.feature @@ -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 |