]> source.dussan.org Git - nextcloud-server.git/commitdiff
adding unit tests
authorThomas Müller <thomas.mueller@tmit.eu>
Thu, 26 Mar 2015 09:49:26 +0000 (10:49 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Thu, 26 Mar 2015 09:49:26 +0000 (10:49 +0100)
lib/private/connector/sabre/filesplugin.php
tests/lib/connector/sabre/filesplugin.php

index e03cac9c537772fa6033a6ce13b8ef982d8175b4..1b4b0674a578010a20e9f07b37f3a44a1a72ff79 100644 (file)
@@ -184,11 +184,8 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
        /**
         * @param \OC\Connector\Sabre\Node $node
         */
-       private function getETag($node) {
-               if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
-                       if (isset($_SERVER['X-CHUNKING_COMPLETE'])) {
-                               return $node->getETag();
-                       }
+       public function getETag($node) {
+               if (isset($_SERVER['HTTP_OC_CHUNKED']) && !isset($_SERVER['X-CHUNKING_COMPLETE'])) {
                        return null;
                }
                return $node->getETag();
index 54d43d66dda4a6055c961c1ee3bbe3571f01f1a6..e10d67a3255016de5fa25c27b1046b3b7bb64939 100644 (file)
@@ -171,4 +171,35 @@ class FilesPlugin extends \Test\TestCase {
                $this->assertEquals(200, $result[self::GETETAG_PROPERTYNAME]);
        }
 
+       /**
+        * @dataProvider providesETagTestData
+        * @param $expectedETag
+        * @param $isChunked
+        * @param $isChunkComplete
+        */
+       public function testETag($expectedETag, $isChunked, $isChunkComplete) {
+               if (!is_null($isChunked)) {
+                       $_SERVER['HTTP_OC_CHUNKED'] = $isChunked;
+               }
+               if (!is_null($isChunkComplete)) {
+                       $_SERVER['X-CHUNKING_COMPLETE'] = $isChunkComplete;
+               }
+               $node = $this->createTestNode('\OC\Connector\Sabre\File');
+
+               $etag = $this->plugin->getETag($node);
+
+               $this->assertEquals($expectedETag, $etag);
+       }
+
+       public function providesETagTestData() {
+               return [
+                       // non-chunked tests
+                       ['"abc"', null, null],
+                       ['"abc"', null, false],
+
+                       // chunked tests
+                       [null, true, null],
+                       ['"abc"', true, true],
+               ];
+       }
 }