summaryrefslogtreecommitdiffstats
path: root/build/integration
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-06-07 14:14:14 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-06-23 12:47:58 +0200
commit09c6cd77ecb7c4ead4d68226a693e7588df80d09 (patch)
treec113c01e22daaecc0ac77ee4a37f6ab08e37ccab /build/integration
parent046357ec7559363664b624a29c96390efb750565 (diff)
downloadnextcloud-server-09c6cd77ecb7c4ead4d68226a693e7588df80d09.tar.gz
nextcloud-server-09c6cd77ecb7c4ead4d68226a693e7588df80d09.zip
Add test
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'build/integration')
-rw-r--r--build/integration/features/bootstrap/WebDav.php115
-rw-r--r--build/integration/features/dav-v2.feature6
2 files changed, 116 insertions, 5 deletions
diff --git a/build/integration/features/bootstrap/WebDav.php b/build/integration/features/bootstrap/WebDav.php
index ae0659d5dda..680db01a260 100644
--- a/build/integration/features/bootstrap/WebDav.php
+++ b/build/integration/features/bootstrap/WebDav.php
@@ -32,8 +32,8 @@
*
*/
use GuzzleHttp\Client as GClient;
+use GuzzleHttp\Message\ResponseInterface;
use PHPUnit\Framework\Assert;
-use Psr\Http\Message\ResponseInterface;
use Sabre\DAV\Client as SClient;
use Sabre\DAV\Xml\Property\ResourceType;
@@ -221,6 +221,14 @@ trait WebDav {
}
/**
+ * @Then /^Image search should work$/
+ */
+ public function search(): void {
+ $this->searchFile($this->currentUser);
+ Assert::assertEquals(207, $this->response->getStatusCode());
+ }
+
+ /**
* @Then /^Downloaded content when downloading file "([^"]*)" with range "([^"]*)" should be "([^"]*)"$/
* @param string $fileSource
* @param string $range
@@ -393,13 +401,12 @@ trait WebDav {
return $response;
}
- /* Returns the elements of a report command
- * @param string $user
- * @param string $path
+ /**
+ * Returns the elements of a profind command
* @param string $properties properties which needs to be included in the report
* @param string $filterRules filter-rules to choose what needs to appear in the report
*/
- public function propfindFile($user, $path, $properties = '') {
+ public function propfindFile(string $user, string $path, string $properties = '') {
$client = $this->getSabreClient($user);
$body = '<?xml version="1.0" encoding="utf-8" ?>
@@ -417,6 +424,104 @@ trait WebDav {
return $parsedResponse;
}
+ /**
+ * Returns the elements of a searc command
+ * @param string $properties properties which needs to be included in the report
+ * @param string $filterRules filter-rules to choose what needs to appear in the report
+ */
+ public function searchFile(string $user, ?string $properties = null, ?string $scope = null, ?string $condition = null) {
+ $client = $this->getSabreClient($user);
+
+ if ($properties === null) {
+ $properties = '<oc:fileid /> <d:getlastmodified /> <d:getetag /> <d:getcontenttype /> <d:getcontentlength /> <nc:has-preview /> <oc:favorite /> <d:resourcetype />';
+ }
+
+ if ($condition === null) {
+ $condition = '<d:and>
+ <d:or>
+ <d:eq>
+ <d:prop>
+ <d:getcontenttype/>
+ </d:prop>
+ <d:literal>image/png</d:literal>
+ </d:eq>
+
+ <d:eq>
+ <d:prop>
+ <d:getcontenttype/>
+ </d:prop>
+ <d:literal>image/jpeg</d:literal>
+ </d:eq>
+
+ <d:eq>
+ <d:prop>
+ <d:getcontenttype/>
+ </d:prop>
+ <d:literal>image/heic</d:literal>
+ </d:eq>
+
+ <d:eq>
+ <d:prop>
+ <d:getcontenttype/>
+ </d:prop>
+ <d:literal>video/mp4</d:literal>
+ </d:eq>
+
+ <d:eq>
+ <d:prop>
+ <d:getcontenttype/>
+ </d:prop>
+ <d:literal>video/quicktime</d:literal>
+ </d:eq>
+ </d:or>
+ <d:eq>
+ <d:prop>
+ <oc:owner-id/>
+ </d:prop>
+ <d:literal>' . $user . '</d:literal>
+ </d:eq>
+</d:and>';
+ }
+
+ if ($scope === null) {
+ $scope = '<d:href>/files/' . $user . '</d:href><d:depth>infinity</d:depth>';
+ }
+
+ $body = '<?xml version="1.0" encoding="UTF-8"?>
+<d:searchrequest xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns" xmlns:ns="https://github.com/icewind1991/SearchDAV/ns" xmlns:ocs="http://open-collaboration-services.org/ns">
+ <d:basicsearch>
+ <d:select>
+ <d:prop>' . $properties . '</d:prop>
+ </d:select>
+ <d:from><d:scope>' . $scope . '</d:scope></d:from>
+ <d:where>' . $condition . '</d:where>
+ <d:orderby>
+ <d:order>
+ <d:prop><d:getlastmodified/></d:prop>
+ <d:descending/>
+ </d:order>
+ </d:orderby>
+ <d:limit>
+ <d:nresults>35</d:nresults>
+ <ns:firstresult>0</ns:firstresult>
+ </d:limit>
+ </d:basicsearch>
+</d:searchrequest>';
+
+ try {
+ $this->response = $this->makeDavRequest($user, "SEARCH", '', [
+ 'Content-Type' => 'text/xml'
+ ], $body, '');
+ var_dump((string)$this->response->getBody());
+ } catch (\GuzzleHttp\Exception\ServerException $e) {
+ // 5xx responses cause a server exception
+ $this->response = $e->getResponse();
+ } catch (\GuzzleHttp\Exception\ClientException $e) {
+ // 4xx responses cause a client exception
+ $this->response = $e->getResponse();
+ }
+ }
+
/* Returns the elements of a report command
* @param string $user
* @param string $path
diff --git a/build/integration/features/dav-v2.feature b/build/integration/features/dav-v2.feature
index 9ecce4c6bf9..5b5c835e0dd 100644
--- a/build/integration/features/dav-v2.feature
+++ b/build/integration/features/dav-v2.feature
@@ -80,3 +80,9 @@ Feature: dav-v2
And As an "user0"
When User "user0" uploads file "data/textfile.txt" to "/testquota/asdf.txt"
Then the HTTP status code should be "201"
+
+ Scenario: Create a search query
+ Given using new dav path
+ And As an "admin"
+ When User "user0" uploads file "data/green-square-256.png" to "/image.png"
+ When Image search should work