]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add test 32701/head
authorCarl Schwan <carl@carlschwan.eu>
Tue, 7 Jun 2022 12:14:14 +0000 (14:14 +0200)
committerCarl Schwan <carl@carlschwan.eu>
Thu, 23 Jun 2022 10:47:58 +0000 (12:47 +0200)
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
build/integration/features/bootstrap/WebDav.php
build/integration/features/dav-v2.feature

index ae0659d5ddaa1c1521288f74d15758e69e8ee8f6..680db01a260c00a384f48919b8975bdc022b3176 100644 (file)
@@ -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;
 
@@ -220,6 +220,14 @@ trait WebDav {
                Assert::assertEquals($property, $value);
        }
 
+       /**
+        * @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
@@ -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
index 9ecce4c6bf90e7061a102618d00e916ee6a840d1..5b5c835e0dd689b5289bbaee0a793c77bc436f37 100644 (file)
@@ -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