Add test for searching content across files with different format with search text highlight (#7236)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
@tikaServiceNeeded
|
||||||
Feature: content search
|
Feature: content search
|
||||||
As a user
|
As a user
|
||||||
I want to do search resources by content
|
I want to do search resources by content
|
||||||
@@ -172,3 +173,32 @@ Feature: content search
|
|||||||
| content:hel* | 2 | /technical task.txt | /task comments.txt |
|
| content:hel* | 2 | /technical task.txt | /task comments.txt |
|
||||||
| content:hel* AND tag:test | 1 | /technical task.txt | |
|
| content:hel* AND tag:test | 1 | /technical task.txt | |
|
||||||
| (name:*task* AND content:hel*) NOT tag:test | 1 | /task comments.txt | |
|
| (name:*task* AND content:hel*) NOT tag:test | 1 | /task comments.txt | |
|
||||||
|
|
||||||
|
|
||||||
|
Scenario Outline: search across files with different format with search text highlight
|
||||||
|
Given using <dav-path-version> DAV path
|
||||||
|
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
|
||||||
|
And user "Alice" has created a space "project-space" with the default quota using the GraphApi
|
||||||
|
And user "Alice" has uploaded file with content "this is a simple text file" to "test-text-file.txt"
|
||||||
|
And user "Alice" has uploaded file with content "this is a simple pdf file" to "test-pdf-file.pdf"
|
||||||
|
And user "Alice" has uploaded file with content "this is a simple cpp file" to "test-cpp-file.cpp"
|
||||||
|
And user "Alice" has uploaded file with content "this is another text file" to "testfile.txt"
|
||||||
|
And user "Alice" has uploaded file "filesForUpload/testavatar.png" to "/testavatar.png"
|
||||||
|
And user "Alice" has uploaded a file inside space "project-space" with content "this is a simple markdown file" to "test-md-file.md"
|
||||||
|
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 should contain these entries with highlight on keyword "simple"
|
||||||
|
| test-text-file.txt |
|
||||||
|
| test-pdf-file.pdf |
|
||||||
|
| test-cpp-file.cpp |
|
||||||
|
| test-md-file.md |
|
||||||
|
| test-odt-file.odt |
|
||||||
|
But the search result of user "Alice" should not contain these entries:
|
||||||
|
| testavatar.png |
|
||||||
|
| testfile.txt |
|
||||||
|
Examples:
|
||||||
|
| dav-path-version |
|
||||||
|
| old |
|
||||||
|
| new |
|
||||||
|
| spaces |
|
||||||
|
|||||||
@@ -52,13 +52,13 @@ class SearchContext implements Context {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function userSearchesUsingWebDavAPI(
|
public function userSearchesUsingWebDavAPI(
|
||||||
string $user,
|
string $user,
|
||||||
string $pattern,
|
string $pattern,
|
||||||
?string $limit = null,
|
?string $limit = null,
|
||||||
?string $scope = null,
|
?string $scope = null,
|
||||||
?string $spaceName = null,
|
?string $spaceName = null,
|
||||||
TableNode $properties = null
|
TableNode $properties = null
|
||||||
):void {
|
): 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.
|
// 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);
|
sleep(4);
|
||||||
$user = $this->featureContext->getActualUsername($user);
|
$user = $this->featureContext->getActualUsername($user);
|
||||||
@@ -113,10 +113,10 @@ class SearchContext implements Context {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function fileOrFolderInTheSearchResultShouldContainProperties(
|
public function fileOrFolderInTheSearchResultShouldContainProperties(
|
||||||
string $path,
|
string $path,
|
||||||
string $user,
|
string $user,
|
||||||
TableNode $properties
|
TableNode $properties
|
||||||
):void {
|
): void {
|
||||||
$user = $this->featureContext->getActualUsername($user);
|
$user = $this->featureContext->getActualUsername($user);
|
||||||
$this->featureContext->verifyTableNodeColumns($properties, ['name', 'value']);
|
$this->featureContext->verifyTableNodeColumns($properties, ['name', 'value']);
|
||||||
$properties = $properties->getHash();
|
$properties = $properties->getHash();
|
||||||
@@ -163,10 +163,47 @@ class SearchContext implements Context {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function before(BeforeScenarioScope $scope):void {
|
public function before(BeforeScenarioScope $scope): void {
|
||||||
// Get the environment
|
// Get the environment
|
||||||
$environment = $scope->getEnvironment();
|
$environment = $scope->getEnvironment();
|
||||||
// Get all the contexts you need in this context
|
// Get all the contexts you need in this context
|
||||||
$this->featureContext = $environment->getContext('FeatureContext');
|
$this->featureContext = $environment->getContext('FeatureContext');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 <mark> tags
|
||||||
|
preg_match('/<mark>(.*?)<\/mark>/s', $content, $matches);
|
||||||
|
$actualContent = isset($matches[1]) ? $matches[1] : '';
|
||||||
|
|
||||||
|
// Remove any leading/trailing whitespace for comparison
|
||||||
|
$actualContent = trim($actualContent);
|
||||||
|
Assert::assertEquals(
|
||||||
|
$expectedContent,
|
||||||
|
$actualContent,
|
||||||
|
"Expected text highlight to be '$expectedContent' but found '$actualContent'"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5355,6 +5355,7 @@ trait WebDav {
|
|||||||
* and returns found search results if found else returns false
|
* and returns found search results if found else returns false
|
||||||
*
|
*
|
||||||
* @param string|null $entryNameToSearch
|
* @param string|null $entryNameToSearch
|
||||||
|
* @param bool|null $searchForHighlightString
|
||||||
*
|
*
|
||||||
* @return string|array|boolean
|
* @return string|array|boolean
|
||||||
*
|
*
|
||||||
@@ -5362,10 +5363,11 @@ trait WebDav {
|
|||||||
* array if $entryNameToSearch is not given
|
* array if $entryNameToSearch is not given
|
||||||
* boolean false if $entryNameToSearch is given and is not found
|
* boolean false if $entryNameToSearch is given and is not found
|
||||||
*
|
*
|
||||||
* @throws GuzzleException
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function findEntryFromSearchResponse(
|
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
|
// trim any leading "/" passed by the caller, we can just match the "raw" name
|
||||||
if ($entryNameToSearch !== null) {
|
if ($entryNameToSearch !== null) {
|
||||||
@@ -5387,7 +5389,12 @@ trait WebDav {
|
|||||||
if ($entryNameToSearch === $resourcePath) {
|
if ($entryNameToSearch === $resourcePath) {
|
||||||
return $resourcePath;
|
return $resourcePath;
|
||||||
}
|
}
|
||||||
$results[] = $resourcePath;
|
if ($searchForHighlightString) {
|
||||||
|
$actualHighlightString = $item->xpath("d:propstat//oc:highlights");
|
||||||
|
$results[$resourcePath] = (string)$actualHighlightString[0];
|
||||||
|
} else {
|
||||||
|
$results[] = $resourcePath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($entryNameToSearch === null) {
|
if ($entryNameToSearch === null) {
|
||||||
return $results;
|
return $results;
|
||||||
|
|||||||
Reference in New Issue
Block a user