diff --git a/tests/acceptance/features/apiSearch/contentSearch.feature b/tests/acceptance/features/apiSearch/contentSearch.feature
index 3f50f5fab2f..9cdbe27df26 100644
--- a/tests/acceptance/features/apiSearch/contentSearch.feature
+++ b/tests/acceptance/features/apiSearch/contentSearch.feature
@@ -188,7 +188,7 @@ Feature: content search
And user "Alice" has uploaded a file inside space "project-space" with content "this is a simple odt file" to "test-odt-file.odt"
When user "Alice" searches for "Content:simple" using the WebDAV API
Then the HTTP status code should be "207"
- And the search result of user "Alice" should contain these entries with highlight on keyword "simple"
+ And the search result should contain these entries with highlight on keyword "simple"
| test-text-file.txt |
| test-pdf-file.pdf |
| test-cpp-file.cpp |
diff --git a/tests/acceptance/features/bootstrap/SearchContext.php b/tests/acceptance/features/bootstrap/SearchContext.php
index 1aecc2c3282..925dcf23cdb 100644
--- a/tests/acceptance/features/bootstrap/SearchContext.php
+++ b/tests/acceptance/features/bootstrap/SearchContext.php
@@ -31,212 +31,204 @@
/**
* context containing search related API steps
*/
-class SearchContext implements Context
-{
- private FeatureContext $featureContext;
+class SearchContext implements Context {
+ private FeatureContext $featureContext;
- /**
- * @When user :user searches for :pattern using the WebDAV API
- * @When user :user searches for :pattern and limits the results to :limit items using the WebDAV API
- * @When user :user searches for :pattern using the WebDAV API requesting these properties:
- * @When user :user searches for :pattern and limits the results to :limit items using the WebDAV API requesting these properties:
- * @When user :user searches for :pattern inside folder :scope using the WebDAV API
- * @When user :user searches for :pattern inside folder :scope in space :spaceName using the WebDAV API
- *
- * @param string $user
- * @param string $pattern
- * @param string|null $limit
- * @param string|null $scope
- * @param string|null $spaceName
- * @param TableNode|null $properties
- *
- * @return void
- */
- public function userSearchesUsingWebDavAPI(
- string $user,
- string $pattern,
- ?string $limit = null,
- ?string $scope = null,
- ?string $spaceName = null,
- TableNode $properties = null
- ): void
- {
- // Because indexing of newly uploaded files or directories with ocis is decoupled and occurs asynchronously, a short wait is necessary before searching files or folders.
- sleep(4);
- $user = $this->featureContext->getActualUsername($user);
- $baseUrl = $this->featureContext->getBaseUrl();
- $password = $this->featureContext->getPasswordForUser($user);
- $body
- = "\n" .
- " \n" .
- " \n";
- if ($scope !== null) {
- $scope = \trim($scope, "/");
- $resourceID = $this->featureContext->spacesContext->getResourceId($user, $spaceName ?? "Personal", $scope);
- $pattern .= " scope:$resourceID";
- }
- $body .= "$pattern\n";
- if ($limit !== null) {
- $body .= " $limit\n";
- }
+ /**
+ * @When user :user searches for :pattern using the WebDAV API
+ * @When user :user searches for :pattern and limits the results to :limit items using the WebDAV API
+ * @When user :user searches for :pattern using the WebDAV API requesting these properties:
+ * @When user :user searches for :pattern and limits the results to :limit items using the WebDAV API requesting these properties:
+ * @When user :user searches for :pattern inside folder :scope using the WebDAV API
+ * @When user :user searches for :pattern inside folder :scope in space :spaceName using the WebDAV API
+ *
+ * @param string $user
+ * @param string $pattern
+ * @param string|null $limit
+ * @param string|null $scope
+ * @param string|null $spaceName
+ * @param TableNode|null $properties
+ *
+ * @return void
+ */
+ public function userSearchesUsingWebDavAPI(
+ string $user,
+ string $pattern,
+ ?string $limit = null,
+ ?string $scope = null,
+ ?string $spaceName = null,
+ TableNode $properties = null
+ ): void {
+ // Because indexing of newly uploaded files or directories with ocis is decoupled and occurs asynchronously, a short wait is necessary before searching files or folders.
+ sleep(4);
+ $user = $this->featureContext->getActualUsername($user);
+ $baseUrl = $this->featureContext->getBaseUrl();
+ $password = $this->featureContext->getPasswordForUser($user);
+ $body
+ = "\n" .
+ " \n" .
+ " \n";
+ if ($scope !== null) {
+ $scope = \trim($scope, "/");
+ $resourceID = $this->featureContext->spacesContext->getResourceId($user, $spaceName ?? "Personal", $scope);
+ $pattern .= " scope:$resourceID";
+ }
+ $body .= "$pattern\n";
+ if ($limit !== null) {
+ $body .= " $limit\n";
+ }
- $body .= " \n";
- if ($properties !== null) {
- $propertiesRows = $properties->getRows();
- $body .= " ";
- foreach ($propertiesRows as $property) {
- $body .= "<$property[0]/>";
- }
- $body .= " ";
- }
- $body .= " ";
- $response = WebDavHelper::makeDavRequest(
- $baseUrl,
- $user,
- $password,
- "REPORT",
- "/",
- null,
- $this->featureContext->getStepLineRef(),
- $body,
- $this->featureContext->getDavPathVersion()
- );
- $this->featureContext->setResponse($response);
- }
+ $body .= " \n";
+ if ($properties !== null) {
+ $propertiesRows = $properties->getRows();
+ $body .= " ";
+ foreach ($propertiesRows as $property) {
+ $body .= "<$property[0]/>";
+ }
+ $body .= " ";
+ }
+ $body .= " ";
+ $response = WebDavHelper::makeDavRequest(
+ $baseUrl,
+ $user,
+ $password,
+ "REPORT",
+ "/",
+ null,
+ $this->featureContext->getStepLineRef(),
+ $body,
+ $this->featureContext->getDavPathVersion()
+ );
+ $this->featureContext->setResponse($response);
+ }
- /**
- * @Then file/folder :path in the search result of user :user should contain these properties:
- *
- * @param string $path
- * @param string $user
- * @param TableNode $properties
- *
- * @return void
- * @throws Exception
- */
- public function fileOrFolderInTheSearchResultShouldContainProperties(
- string $path,
- string $user,
- TableNode $properties
- ): void
- {
- $user = $this->featureContext->getActualUsername($user);
- $this->featureContext->verifyTableNodeColumns($properties, ['name', 'value']);
- $properties = $properties->getHash();
- $fileResult = $this->featureContext->findEntryFromPropfindResponse(
- $path,
- $user,
- "REPORT",
- );
- 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;
- }
- }
- Assert::assertTrue(
- $foundProperty,
- "could not find property '" . $property['name'] . "'"
- );
- }
- }
+ /**
+ * @Then file/folder :path in the search result of user :user should contain these properties:
+ *
+ * @param string $path
+ * @param string $user
+ * @param TableNode $properties
+ *
+ * @return void
+ * @throws Exception
+ */
+ public function fileOrFolderInTheSearchResultShouldContainProperties(
+ string $path,
+ string $user,
+ TableNode $properties
+ ): void {
+ $user = $this->featureContext->getActualUsername($user);
+ $this->featureContext->verifyTableNodeColumns($properties, ['name', 'value']);
+ $properties = $properties->getHash();
+ $fileResult = $this->featureContext->findEntryFromPropfindResponse(
+ $path,
+ $user,
+ "REPORT",
+ );
+ 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;
+ }
+ }
+ Assert::assertTrue(
+ $foundProperty,
+ "could not find property '" . $property['name'] . "'"
+ );
+ }
+ }
- /**
- * This will run before EVERY scenario.
- * It will set the properties for this object.
- *
- * @BeforeScenario
- *
- * @param BeforeScenarioScope $scope
- *
- * @return void
- */
- public function before(BeforeScenarioScope $scope): void
- {
- // Get the environment
- $environment = $scope->getEnvironment();
- // Get all the contexts you need in this context
- $this->featureContext = $environment->getContext('FeatureContext');
- }
+ /**
+ * This will run before EVERY scenario.
+ * It will set the properties for this object.
+ *
+ * @BeforeScenario
+ *
+ * @param BeforeScenarioScope $scope
+ *
+ * @return void
+ */
+ public function before(BeforeScenarioScope $scope): void {
+ // Get the environment
+ $environment = $scope->getEnvironment();
+ // Get all the contexts you need in this context
+ $this->featureContext = $environment->getContext('FeatureContext');
+ }
- /**
- * @Then the search result by tags for user :user should contain these entries:
- *
- * @param string|null $user
- * @param TableNode $expectedEntries
- *
- * @return void
- * @throws Exception
- */
- public function theSearchResultByTagsForUserShouldContainTheseEntries(
- ?string $user,
- TableNode $expectedEntries
- ): void
- {
- $user = $this->featureContext->getActualUsername($user);
- $this->featureContext->verifyTableNodeColumnsCount($expectedEntries, 1);
- $expectedEntries = $expectedEntries->getRows();
- $expectedEntriesArray = [];
- $responseResourcesArray = $this->featureContext->findEntryFromReportResponse($user);
- foreach ($expectedEntries as $item) {
- $expectedEntriesArray[] = $item[0];
- }
- Assert::assertEqualsCanonicalizing($expectedEntriesArray, $responseResourcesArray);
- }
+ /**
+ * @Then the search result by tags for user :user should contain these entries:
+ *
+ * @param string|null $user
+ * @param TableNode $expectedEntries
+ *
+ * @return void
+ * @throws Exception
+ */
+ public function theSearchResultByTagsForUserShouldContainTheseEntries(
+ ?string $user,
+ TableNode $expectedEntries
+ ): void {
+ $user = $this->featureContext->getActualUsername($user);
+ $this->featureContext->verifyTableNodeColumnsCount($expectedEntries, 1);
+ $expectedEntries = $expectedEntries->getRows();
+ $expectedEntriesArray = [];
+ $responseResourcesArray = $this->featureContext->findEntryFromReportResponse($user);
+ foreach ($expectedEntries as $item) {
+ $expectedEntriesArray[] = $item[0];
+ }
+ Assert::assertEqualsCanonicalizing($expectedEntriesArray, $responseResourcesArray);
+ }
+ /**
+ * @Then /^the search result should contain these (?:files|entries) with highlight on keyword "([^"]*)"/
+ *
+ * @param TableNode $expectedFiles
+ * @param string $expectedContent
+ *
+ * @return void
+ *
+ * @throws Exception
+ */
+ public function theSearchResultShouldContainEntriesWithHighlight(
+ TableNode $expectedFiles,
+ string $expectedContent
+ ): void {
+ $this->featureContext->verifyTableNodeColumnsCount($expectedFiles, 1);
+ $elementRows = $expectedFiles->getRows();
+ $foundEntries = $this->featureContext->findEntryFromSearchResponse(
+ null,
+ true
+ );
+ foreach ($elementRows as $index => $expectedFile) {
+ $filename = $expectedFile[0];
+ $content = $foundEntries[$filename];
+ // Extract the content between the tags
+ preg_match('/(.*?)<\/mark>/s', $content, $matches);
+ $actualContent = isset($matches[1]) ? $matches[1] : '';
- /**
- * @Then /^the search result of user "([^"]*)" should contain these (?:files|entries) with highlight on keyword "([^"]*)"/
- *
- * @param string $user
- * @param TableNode $expectedFiles
- * @param string $keyword
- *
- * @return void
- * @throws Exception
- */
- public function theSearchResultShouldContainEntriesWithHighlight(
- string $user,
- TableNode $expectedFiles,
- string $expectedContent
- ): void
- {
- $this->featureContext->verifyTableNodeColumnsCount($expectedFiles, 1);
- $elementRows = $expectedFiles->getRows();
- $foundEntries = $this->featureContext->findEntryFromSearchResponse(
- null,
- true
- );
- foreach ($elementRows as $index => $expectedFile) {
- $filename = $expectedFile[0];
- $content = $foundEntries[$filename];
- // Extract the content between the tags
- preg_match('/(.*?)<\/mark>/s', $content, $matches);
- $actualContent = isset($matches[1]) ? $matches[1] : '';
-
- // Remove any leading/trailing whitespace for comparison
- $actualContent = trim($actualContent);
- var_dump($actualContent);
- Assert::assertEquals(
- $expectedContent,
- $actualContent,
- "Expected text highlight to be $expectedContent but found $actualContent"
- );
- }
- }
+ // Remove any leading/trailing whitespace for comparison
+ $actualContent = trim($actualContent);
+ var_dump($actualContent);
+ Assert::assertEquals(
+ $expectedContent,
+ $actualContent,
+ "Expected text highlight to be $expectedContent but found $actualContent"
+ );
+ }
+ }
}
diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php
index 2f746a26ae0..cc9b09e44b6 100644
--- a/tests/acceptance/features/bootstrap/WebDav.php
+++ b/tests/acceptance/features/bootstrap/WebDav.php
@@ -4870,8 +4870,7 @@ public function propfindResultShouldContainEntries(
TableNode $expectedFiles,
?string $user = null,
?string $method = 'REPORT',
- ?string $folderpath = '',
- ?string $highlightKeyword = null
+ ?string $folderpath = ''
):void {
$this->verifyTableNodeColumnsCount($expectedFiles, 1);
$elementRows = $expectedFiles->getRows();
@@ -5190,27 +5189,19 @@ public function thePublicListsTheResourcesInTheLastCreatedPublicLinkWithDepthUsi
*
* @return array
*/
- public function findEntryFromReportResponse(?string $user, ?string $highlightKeyword=null):array {
- $this->setResponseXml(HttpRequestHelper::parseResponseAsXml($this->response));
+ public function findEntryFromReportResponse(?string $user):array {
$responseXmlObj = $this->getResponseXmlObject();
$responseResources = [];
- var_dump('here');
$hrefs = $responseXmlObj->xpath('//d:href');
- var_dump($hrefs);
-// if($highlightKeyword) {
-// $keywords = $responseXmlObj->xpath('//d:response/d:propstat/d:prop/oc:highlights');
-// var_dump($keywords);
-// }
-// foreach ($hrefs as $href) {
-// $hrefParts = \explode("/", (string)$href[0]);
-// if (\in_array($user, $hrefParts)) {
-// $entry = \urldecode(\end($hrefParts));
-// $responseResources[] = $entry;
-// } else {
-// throw new Error("Expected user: $hrefParts[5] but found: $user");
-// }
-// }
-// var_dump($responseResources);
+ foreach ($hrefs as $href) {
+ $hrefParts = \explode("/", (string)$href[0]);
+ if (\in_array($user, $hrefParts)) {
+ $entry = \urldecode(\end($hrefParts));
+ $responseResources[] = $entry;
+ } else {
+ throw new Error("Expected user: $hrefParts[5] but found: $user");
+ }
+ }
return $responseResources;
}
@@ -5305,8 +5296,7 @@ public function findEntryFromPropfindResponse(
?string $user = null,
?string $method = null,
string $type = "files",
- string $folderPath = '',
- ?string $highlightKeyword = null
+ string $folderPath = ''
) {
$trimmedEntryNameToSearch = '';
// trim any leading "/" passed by the caller, we can just match the "raw" name
@@ -5353,9 +5343,6 @@ public function findEntryFromPropfindResponse(
return $multistatusResult;
}
$results[] = $entryName;
- if($highlightKeyword){
- $this->getKeyWordHighlightFromSearchRequest($multistatusResult);
- }
}
if ($entryNameToSearch === null) {
return $results;
@@ -5363,23 +5350,24 @@ public function findEntryFromPropfindResponse(
return false;
}
- /**
- * parses a REPORT response from $this->response into xml
- * and returns found search results if found else returns false
- *
- * @param string|null $entryNameToSearch
- * @param bool $highlightString
- * @return string|array|boolean
- *
- * string if $entryNameToSearch is given and is found
- * array if $entryNameToSearch is not given
- * boolean false if $entryNameToSearch is given and is not found
- *
- * @throws Exception
- */
+ /**
+ * parses a REPORT response from $this->response into xml
+ * and returns found search results if found else returns false
+ *
+ * @param string|null $entryNameToSearch
+ * @param bool $highlightString
+ *
+ * @return string|array|boolean
+ *
+ * string if $entryNameToSearch is given and is found
+ * array if $entryNameToSearch is not given
+ * boolean false if $entryNameToSearch is given and is not found
+ *
+ * @throws Exception
+ */
public function findEntryFromSearchResponse(
?string $entryNameToSearch = null,
- ?bool $highlightString = false
+ ?bool $highlightString = false
) {
// trim any leading "/" passed by the caller, we can just match the "raw" name
if ($entryNameToSearch !== null) {
@@ -5401,13 +5389,12 @@ public function findEntryFromSearchResponse(
if ($entryNameToSearch === $resourcePath) {
return $resourcePath;
}
- if ($highlightString){
- $actualHighlightString = $item->xpath("d:propstat//oc:highlights");
- $results[$resourcePath] = (string)$actualHighlightString[0][0];
- } else{
- $results[] = $resourcePath;
- }
-
+ if ($highlightString) {
+ $actualHighlightString = $item->xpath("d:propstat//oc:highlights");
+ $results[$resourcePath] = (string)$actualHighlightString[0][0];
+ } else {
+ $results[] = $resourcePath;
+ }
}
if ($entryNameToSearch === null) {
return $results;