Merge pull request #10119 from owncloud/extend-search-test-scenarios
[tests-only][full-ci] test: extend test coverage for searching a file
This commit is contained in:
@@ -23,7 +23,9 @@
|
|||||||
use Behat\Behat\Context\Context;
|
use Behat\Behat\Context\Context;
|
||||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
||||||
use Behat\Gherkin\Node\TableNode;
|
use Behat\Gherkin\Node\TableNode;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use TestHelpers\WebDavHelper;
|
use TestHelpers\WebDavHelper;
|
||||||
use TestHelpers\HttpRequestHelper;
|
use TestHelpers\HttpRequestHelper;
|
||||||
use TestHelpers\BehatHelper;
|
use TestHelpers\BehatHelper;
|
||||||
@@ -37,33 +39,26 @@ class SearchContext implements Context {
|
|||||||
private FeatureContext $featureContext;
|
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 $user
|
||||||
* @param string $pattern
|
* @param string $pattern
|
||||||
* @param string|null $limit
|
* @param string|null $limit
|
||||||
|
* @param string|null $scopeType
|
||||||
* @param string|null $scope
|
* @param string|null $scope
|
||||||
* @param string|null $spaceName
|
* @param string|null $spaceName
|
||||||
* @param TableNode|null $properties
|
* @param TableNode|null $properties
|
||||||
*
|
*
|
||||||
* @return void
|
* @return ResponseInterface
|
||||||
|
* @throws GuzzleException|JsonException
|
||||||
*/
|
*/
|
||||||
public function userSearchesUsingWebDavAPI(
|
private function searchFiles(
|
||||||
string $user,
|
string $user,
|
||||||
string $pattern,
|
string $pattern,
|
||||||
?string $limit = null,
|
?string $limit = null,
|
||||||
?string $scope = null,
|
?string $scopeType = null,
|
||||||
?string $spaceName = null,
|
?string $scope = null,
|
||||||
TableNode $properties = null
|
?string $spaceName = null,
|
||||||
): void {
|
?TableNode $properties = null
|
||||||
// NOTE: because indexing of newly uploaded files or directories with ocis is decoupled and occurs asynchronously
|
): ResponseInterface {
|
||||||
// short wait is necessary before searching
|
|
||||||
sleep(5);
|
|
||||||
$user = $this->featureContext->getActualUsername($user);
|
$user = $this->featureContext->getActualUsername($user);
|
||||||
$baseUrl = $this->featureContext->getBaseUrl();
|
$baseUrl = $this->featureContext->getBaseUrl();
|
||||||
$password = $this->featureContext->getPasswordForUser($user);
|
$password = $this->featureContext->getPasswordForUser($user);
|
||||||
@@ -85,9 +80,13 @@ class SearchContext implements Context {
|
|||||||
" <oc:search-files xmlns:a='DAV:' xmlns:oc='http://owncloud.org/ns' >\n" .
|
" <oc:search-files xmlns:a='DAV:' xmlns:oc='http://owncloud.org/ns' >\n" .
|
||||||
" <oc:search>\n";
|
" <oc:search>\n";
|
||||||
if ($scope !== null) {
|
if ($scope !== null) {
|
||||||
$scope = \trim($scope, "/");
|
if ($scopeType === "space") {
|
||||||
$resourceID = $this->featureContext->spacesContext->getResourceId($user, $spaceName ?? "Personal", $scope);
|
$spaceId = $this->featureContext->spacesContext->getSpaceIdByName($user, $scope);
|
||||||
$pattern .= " scope:$resourceID";
|
$pattern .= " scope:$spaceId";
|
||||||
|
} else {
|
||||||
|
$resourceID = $this->featureContext->spacesContext->getResourceId($user, $spaceName ?? "Personal", $scope);
|
||||||
|
$pattern .= " scope:$resourceID";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$body .= "<oc:pattern>$pattern</oc:pattern>\n";
|
$body .= "<oc:pattern>$pattern</oc:pattern>\n";
|
||||||
if ($limit !== null) {
|
if ($limit !== null) {
|
||||||
@@ -114,7 +113,7 @@ class SearchContext implements Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$fullUrl = WebDavHelper::sanitizeUrl("$baseUrl/$davPath");
|
$fullUrl = WebDavHelper::sanitizeUrl("$baseUrl/$davPath");
|
||||||
$response = HttpRequestHelper::sendRequest(
|
return HttpRequestHelper::sendRequest(
|
||||||
$fullUrl,
|
$fullUrl,
|
||||||
$this->featureContext->getStepLineRef(),
|
$this->featureContext->getStepLineRef(),
|
||||||
'REPORT',
|
'REPORT',
|
||||||
@@ -123,6 +122,32 @@ class SearchContext implements Context {
|
|||||||
null,
|
null,
|
||||||
$body
|
$body
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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:
|
||||||
|
*
|
||||||
|
* @param string $user
|
||||||
|
* @param string $pattern
|
||||||
|
* @param string|null $limit
|
||||||
|
* @param TableNode|null $properties
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws Exception|GuzzleException
|
||||||
|
*/
|
||||||
|
public function userSearchesUsingWebDavAPI(
|
||||||
|
string $user,
|
||||||
|
string $pattern,
|
||||||
|
?string $limit = null,
|
||||||
|
?TableNode $properties = null
|
||||||
|
): void {
|
||||||
|
// NOTE: because indexing of newly uploaded files or directories with ocis is decoupled and occurs asynchronously
|
||||||
|
// short wait is necessary before searching
|
||||||
|
sleep(5);
|
||||||
|
$response = $this->searchFiles($user, $pattern, $limit, null, null, null, $properties);
|
||||||
$this->featureContext->setResponse($response);
|
$this->featureContext->setResponse($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,4 +246,31 @@ class SearchContext implements Context {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When /^user "([^"]*)" searches for "([^"]*)" inside (folder|space) "([^"]*)" using the WebDAV API$/
|
||||||
|
* @When /^user "([^"]*)" searches for "([^"]*)" inside (folder) "([^"]*)" in space "([^"]*)" using the WebDAV API$/
|
||||||
|
*
|
||||||
|
* @param string $user
|
||||||
|
* @param string $pattern
|
||||||
|
* @param string $scopeType
|
||||||
|
* @param string $scope
|
||||||
|
* @param string|null $spaceName
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws Exception|GuzzleException
|
||||||
|
*/
|
||||||
|
public function userSearchesInsideFolderOrSpaceUsingWebDavAPI(
|
||||||
|
string $user,
|
||||||
|
string $pattern,
|
||||||
|
string $scopeType,
|
||||||
|
string $scope,
|
||||||
|
?string $spaceName = null,
|
||||||
|
): void {
|
||||||
|
// NOTE: since indexing of newly uploaded files or directories with ocis is decoupled and occurs asynchronously,
|
||||||
|
// a short wait is necessary before searching
|
||||||
|
sleep(5);
|
||||||
|
$response = $this-> searchFiles($user, $pattern, null, $scopeType, $scope, $spaceName);
|
||||||
|
$this->featureContext->setResponse($response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,17 +15,27 @@ Feature: Search
|
|||||||
And user "Alice" has uploaded a file inside space "project101" with content "some content" to "folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt"
|
And user "Alice" has uploaded a file inside space "project101" with content "some content" to "folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt"
|
||||||
|
|
||||||
|
|
||||||
Scenario Outline: user can search items from the project space
|
Scenario Outline: user can search items inside project space
|
||||||
Given using <dav-path-version> DAV path
|
Given using <dav-path-version> DAV path
|
||||||
When user "Alice" searches for "*SUB*" using the WebDAV API
|
And user "Alice" has created a folder "AlicePersonal" in space "Personal"
|
||||||
|
And user "Alice" has uploaded a file inside space "Personal" with content "inside Alice personal space" to "AlicePersonal/insideAlicePersonal.txt"
|
||||||
|
And user "Brian" has created a folder "BrianPersonal" in space "Personal"
|
||||||
|
And user "Brian" has uploaded file with content "inside Brian personal space" to "BrianPersonal/insideBrianPersonal.txt"
|
||||||
|
And user "Brian" has sent the following resource share invitation:
|
||||||
|
| resource | BrianPersonal |
|
||||||
|
| space | Personal |
|
||||||
|
| sharee | Alice |
|
||||||
|
| shareType | user |
|
||||||
|
| permissionsRole | Viewer |
|
||||||
|
And user "Alice" has a share "BrianPersonal" synced
|
||||||
|
When user "Alice" searches for "*inside*" inside space "project101" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result should contain "2" entries
|
And the search result should contain "1" entries
|
||||||
And the search result of user "Alice" should contain these entries:
|
And the search result of user "Alice" should contain these entries:
|
||||||
| /folderMain/SubFolder1 |
|
| folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt |
|
||||||
| /folderMain/SubFolder1/subFOLDER2 |
|
|
||||||
But the search result of user "Alice" should not contain these entries:
|
But the search result of user "Alice" should not contain these entries:
|
||||||
| /folderMain |
|
| /AlicePersonal/insideAlicePersonal.txt |
|
||||||
| /folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt |
|
| /BrianPersonal/insideBrianPersonal.txt |
|
||||||
Examples:
|
Examples:
|
||||||
| dav-path-version |
|
| dav-path-version |
|
||||||
| old |
|
| old |
|
||||||
@@ -33,23 +43,54 @@ Feature: Search
|
|||||||
| spaces |
|
| spaces |
|
||||||
|
|
||||||
|
|
||||||
Scenario Outline: user can search items from the shares
|
Scenario Outline: user can search items inside personal space
|
||||||
Given using <dav-path-version> DAV path
|
Given using <dav-path-version> DAV path
|
||||||
And user "Alice" has sent the following resource share invitation:
|
And user "Alice" has created a folder "AlicePersonal" in space "Personal"
|
||||||
| resource | folderMain |
|
And user "Alice" has uploaded a file inside space "Personal" with content "inside Alice personal space" to "AlicePersonal/insideAlicePersonal.txt"
|
||||||
| space | project101 |
|
And user "Brian" has created a folder "BrianPersonal" in space "Personal"
|
||||||
| sharee | Brian |
|
And user "Brian" has uploaded file with content "inside Brian personal space" to "BrianPersonal/insideBrianPersonal.txt"
|
||||||
| shareType | user |
|
And user "Brian" has sent the following resource share invitation:
|
||||||
| permissionsRole | Viewer |
|
| resource | BrianPersonal |
|
||||||
And user "Brian" has a share "folderMain" synced
|
| space | Personal |
|
||||||
When user "Brian" searches for "*folder*" using the WebDAV API
|
| sharee | Alice |
|
||||||
|
| shareType | user |
|
||||||
|
| permissionsRole | Viewer |
|
||||||
|
And user "Alice" has a share "BrianPersonal" synced
|
||||||
|
When user "Alice" searches for "*inside*" inside space "Personal" using the WebDAV API
|
||||||
Then the HTTP status code should be "207"
|
Then the HTTP status code should be "207"
|
||||||
And the search result should contain "4" entries
|
And the search result should contain "1" entries
|
||||||
And the search result of user "Brian" should contain these entries:
|
And the search result of user "Alice" should contain only these entries:
|
||||||
| folderMain/SubFolder1 |
|
| AlicePersonal/insideAlicePersonal.txt |
|
||||||
| folderMain/SubFolder1/subFOLDER2 |
|
But the search result of user "Alice" should not contain these entries:
|
||||||
|
| BrianPersonal/insideBrianPersonal.txt |
|
||||||
|
| folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt |
|
||||||
|
Examples:
|
||||||
|
| dav-path-version |
|
||||||
|
| old |
|
||||||
|
| new |
|
||||||
|
| spaces |
|
||||||
|
|
||||||
|
|
||||||
|
Scenario Outline: user cannot search items inside shares space
|
||||||
|
Given using <dav-path-version> DAV path
|
||||||
|
And user "Alice" has created a folder "AlicePersonal" in space "Personal"
|
||||||
|
And user "Alice" has uploaded a file inside space "Personal" with content "inside Alice personal space" to "AlicePersonal/insideAlicePersonal.txt"
|
||||||
|
And user "Brian" has created a folder "BrianPersonal" in space "Personal"
|
||||||
|
And user "Brian" has uploaded file with content "inside Brian personal space" to "BrianPersonal/insideBrianPersonal.txt"
|
||||||
|
And user "Brian" has sent the following resource share invitation:
|
||||||
|
| resource | BrianPersonal |
|
||||||
|
| space | Personal |
|
||||||
|
| sharee | Alice |
|
||||||
|
| shareType | user |
|
||||||
|
| permissionsRole | Viewer |
|
||||||
|
And user "Alice" has a share "BrianPersonal" synced
|
||||||
|
When user "Alice" searches for "*inside*" inside space "Shares" using the WebDAV API
|
||||||
|
Then the HTTP status code should be "207"
|
||||||
|
And the search result should contain "0" entries
|
||||||
|
And the search result of user "Alice" should not contain these entries:
|
||||||
|
| BrianPersonal/insideBrianPersonal.txt |
|
||||||
|
| AlicePersonal/insideAlicePersonal.txt |
|
||||||
| folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt |
|
| folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt |
|
||||||
And for user "Brian" the search result should contain space "mountpoint/folderMain"
|
|
||||||
Examples:
|
Examples:
|
||||||
| dav-path-version |
|
| dav-path-version |
|
||||||
| old |
|
| old |
|
||||||
@@ -291,3 +332,30 @@ Feature: Search
|
|||||||
When user "Alice" searches for 'AND mediatype:document' using the WebDAV API
|
When user "Alice" searches for 'AND mediatype:document' using the WebDAV API
|
||||||
Then the HTTP status code should be "400"
|
Then the HTTP status code should be "400"
|
||||||
And the value of the item "/d:error/s:message" in the response should be "error: bad request: the expression can't begin from a binary operator: 'AND'"
|
And the value of the item "/d:error/s:message" in the response should be "error: bad request: the expression can't begin from a binary operator: 'AND'"
|
||||||
|
|
||||||
|
|
||||||
|
Scenario Outline: search a file globally (in all spaces)
|
||||||
|
Given using <dav-path-version> DAV path
|
||||||
|
And user "Alice" has created a folder "AlicePersonal" in space "Personal"
|
||||||
|
And user "Alice" has uploaded a file inside space "Personal" with content "inside Alice personal space" to "AlicePersonal/insideAlicePersonal.txt"
|
||||||
|
And user "Brian" has created a folder "BrianPersonal" in space "Personal"
|
||||||
|
And user "Brian" has uploaded file with content "inside Brian personal space" to "BrianPersonal/insideBrianPersonal.txt"
|
||||||
|
And user "Brian" has sent the following resource share invitation:
|
||||||
|
| resource | BrianPersonal |
|
||||||
|
| space | Personal |
|
||||||
|
| sharee | Alice |
|
||||||
|
| shareType | user |
|
||||||
|
| permissionsRole | Viewer |
|
||||||
|
And user "Alice" has a share "BrianPersonal" synced
|
||||||
|
When user "Alice" searches for "*inside*" using the WebDAV API
|
||||||
|
Then the HTTP status code should be "207"
|
||||||
|
And the search result should contain "3" entries
|
||||||
|
And the search result of user "Alice" should contain these entries:
|
||||||
|
| AlicePersonal/insideAlicePersonal.txt |
|
||||||
|
| folderMain/SubFolder1/subFOLDER2/insideTheFolder.txt |
|
||||||
|
| BrianPersonal/insideBrianPersonal.txt |
|
||||||
|
Examples:
|
||||||
|
| dav-path-version |
|
||||||
|
| old |
|
||||||
|
| new |
|
||||||
|
| spaces |
|
||||||
|
|||||||
Reference in New Issue
Block a user