[Pkg-owncloud-commits] [php-sabredav] 29/75: Update tests according to previous commits.

David Prévot taffit at moszumanska.debian.org
Thu Feb 26 18:51:51 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit bd158fbea01bb0fbd12c469b2fd18c0ae63a33bc
Author: Ivan Enderlin <ivan.enderlin at hoa-project.net>
Date:   Thu Jan 8 10:10:18 2015 +0100

    Update tests according to previous commits.
    
    And update to PHP5.4 CS.
---
 tests/Sabre/DAV/FSExt/FileTest.php   |  73 ++++++----
 tests/Sabre/DAV/FSExt/ServerTest.php |  18 +--
 tests/Sabre/DAV/Locks/PluginTest.php |   9 +-
 tests/Sabre/DAV/ServerRangeTest.php  | 137 ++++++++++---------
 tests/Sabre/DAV/ServerSimpleTest.php | 254 +++++++++++++++++++----------------
 tests/Sabre/DAV/SimpleFileTest.php   |   2 +-
 6 files changed, 273 insertions(+), 220 deletions(-)

diff --git a/tests/Sabre/DAV/FSExt/FileTest.php b/tests/Sabre/DAV/FSExt/FileTest.php
index 444e39d..3708594 100644
--- a/tests/Sabre/DAV/FSExt/FileTest.php
+++ b/tests/Sabre/DAV/FSExt/FileTest.php
@@ -22,73 +22,90 @@ class FileTest extends \PHPUnit_Framework_TestCase {
 
     function testPut() {
 
-       $file = new File(SABRE_TEMPDIR . '/file.txt');
-       $result = $file->put('New contents');
-
-       $this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
-       $this->assertEquals('"' . md5('New contents') . '"', $result);
+        $filename = SABRE_TEMPDIR . '/file.txt';
+        $file = new File($filename);
+        $result = $file->put('New contents');
+
+        $this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
+        $this->assertEquals(
+            '"' .
+            sha1(
+                fileinode($filename) .
+                filesize($filename ) .
+                filemtime($filename)
+            ) . '"',
+            $result
+        );
 
     }
 
     function testRange() {
 
-       $file = new File(SABRE_TEMPDIR . '/file.txt');
-       $file->put('0000000');
-       $file->patch('111', 2, 3);
+        $file = new File(SABRE_TEMPDIR . '/file.txt');
+        $file->put('0000000');
+        $file->patch('111', 2, 3);
 
-       $this->assertEquals('0001110',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
+        $this->assertEquals('0001110',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
 
     }
 
     function testRangeStream() {
 
-       $stream = fopen('php://memory','r+');
-       fwrite($stream, "222");
-       rewind($stream);
+        $stream = fopen('php://memory','r+');
+        fwrite($stream, "222");
+        rewind($stream);
 
-       $file = new File(SABRE_TEMPDIR . '/file.txt');
-       $file->put('0000000');
-       $file->patch($stream, 2, 3);
+        $file = new File(SABRE_TEMPDIR . '/file.txt');
+        $file->put('0000000');
+        $file->patch($stream, 2, 3);
 
-       $this->assertEquals('0002220',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
+        $this->assertEquals('0002220',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
 
     }
 
 
     function testGet() {
 
-       $file = new File(SABRE_TEMPDIR . '/file.txt');
-       $this->assertEquals('Contents',stream_get_contents($file->get()));
+        $file = new File(SABRE_TEMPDIR . '/file.txt');
+        $this->assertEquals('Contents',stream_get_contents($file->get()));
 
     }
 
     function testDelete() {
 
-       $file = new File(SABRE_TEMPDIR . '/file.txt');
-       $file->delete();
+        $file = new File(SABRE_TEMPDIR . '/file.txt');
+        $file->delete();
 
-       $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt'));
+        $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt'));
 
     }
 
     function testGetETag() {
 
-       $file = new File(SABRE_TEMPDIR . '/file.txt');
-       $this->assertEquals('"' . sha1(filemtime(SABRE_TEMPDIR . '/file.txt')) . '"',$file->getETag());
-
+        $filename = SABRE_TEMPDIR . '/file.txt';
+        $file = new File($filename);
+        $this->assertEquals(
+            '"' .
+            sha1(
+                fileinode($filename) .
+                filesize($filename ) .
+                filemtime($filename)
+            ) . '"',
+            $file->getETag()
+        );
     }
 
     function testGetContentType() {
 
-       $file = new File(SABRE_TEMPDIR . '/file.txt');
-       $this->assertNull($file->getContentType());
+        $file = new File(SABRE_TEMPDIR . '/file.txt');
+        $this->assertNull($file->getContentType());
 
     }
 
     function testGetSize() {
 
-       $file = new File(SABRE_TEMPDIR . '/file.txt');
-       $this->assertEquals(8,$file->getSize());
+        $file = new File(SABRE_TEMPDIR . '/file.txt');
+        $this->assertEquals(8,$file->getSize());
 
     }
 
diff --git a/tests/Sabre/DAV/FSExt/ServerTest.php b/tests/Sabre/DAV/FSExt/ServerTest.php
index 1206d9d..2daf63f 100644
--- a/tests/Sabre/DAV/FSExt/ServerTest.php
+++ b/tests/Sabre/DAV/FSExt/ServerTest.php
@@ -18,6 +18,7 @@ class ServerTest extends DAV\AbstractServer{
     function testGet() {
 
         $request = new HTTP\Request('GET', '/test.txt');
+        $filename = $this->tempDir . '/test.txt';
         $this->server->httpRequest = $request;
         $this->server->exec();
 
@@ -26,8 +27,8 @@ class ServerTest extends DAV\AbstractServer{
             'X-Sabre-Version' => [DAV\Version::VERSION],
             'Content-Type'    => ['application/octet-stream'],
             'Content-Length'  => [13],
-            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'            => ['"' . sha1(filemtime($this->tempDir . '/test.txt')) . '"'],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($filename)))],
+            'ETag'            => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'],
             ],
             $this->response->getHeaders()
          );
@@ -40,6 +41,7 @@ class ServerTest extends DAV\AbstractServer{
     function testHEAD() {
 
         $request = new HTTP\Request('HEAD', '/test.txt');
+        $filename = $this->tempDir . '/test.txt';
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
@@ -48,7 +50,7 @@ class ServerTest extends DAV\AbstractServer{
             'Content-Type'    => ['application/octet-stream'],
             'Content-Length'  => [13],
             'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'            => ['"' . sha1(filemtime($this->tempDir . '/test.txt')) . '"'],
+            'ETag'            => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'],
             ],
             $this->response->getHeaders()
          );
@@ -61,19 +63,20 @@ class ServerTest extends DAV\AbstractServer{
     function testPut() {
 
         $request = new HTTP\Request('PUT', '/testput.txt');
+        $filename = $this->tempDir . '/testput.txt';
         $request->setBody('Testing new file');
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
         $this->assertEquals([
             'X-Sabre-Version' => [DAV\Version::VERSION],
-            'Content-Length' => [0],
-            'ETag'           => ['"' . md5('Testing new file') . '"'],
+            'Content-Length'  => [0],
+            'ETag'            => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'],
         ], $this->response->getHeaders());
 
         $this->assertEquals(201, $this->response->status);
         $this->assertEquals('', $this->response->body);
-        $this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt'));
+        $this->assertEquals('Testing new file',file_get_contents($filename));
 
     }
 
@@ -220,10 +223,9 @@ class ServerTest extends DAV\AbstractServer{
         $tree = new DAV\Tree(new DAV\SimpleCollection('root', [
             new DAV\FS\Directory($this->tempDir . '/tree1'),
             new DAV\FSExt\Directory($this->tempDir . '/tree2'),
-            ]));
+        ]));
         $this->server->tree = $tree;
 
-
         $request = new HTTP\Request('MOVE', '/tree1', ['Destination' => '/tree2/tree1']);
         $this->server->httpRequest = ($request);
         $this->server->exec();
diff --git a/tests/Sabre/DAV/Locks/PluginTest.php b/tests/Sabre/DAV/Locks/PluginTest.php
index a2eabd0..4753610 100644
--- a/tests/Sabre/DAV/Locks/PluginTest.php
+++ b/tests/Sabre/DAV/Locks/PluginTest.php
@@ -898,11 +898,16 @@ class PluginTest extends DAV\AbstractServer {
      */
     function testPutWithCorrectETag() {
 
-        // We need an etag-enabled file node.
+        // We need an ETag-enabled file node.
         $tree = new DAV\Tree(new DAV\FSExt\Directory(SABRE_TEMPDIR));
         $this->server->tree = $tree;
 
-        $etag = sha1(filemtime(SABRE_TEMPDIR . '/test.txt'));
+        $filename = SABRE_TEMPDIR . '/test.txt';
+        $etag = sha1(
+            fileinode($filename) .
+            filesize($filename ) .
+            filemtime($filename)
+        );
         $serverVars = array(
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'PUT',
diff --git a/tests/Sabre/DAV/ServerRangeTest.php b/tests/Sabre/DAV/ServerRangeTest.php
index 9729b70..07a0d8a 100644
--- a/tests/Sabre/DAV/ServerRangeTest.php
+++ b/tests/Sabre/DAV/ServerRangeTest.php
@@ -15,24 +15,25 @@ class ServerRangeTest extends AbstractServer{
 
     function testRange() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'GET',
             'HTTP_RANGE'     => 'bytes=2-5',
-        );
+        ];
+        $filename = SABRE_TEMPDIR . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [4],
-            'Content-Range' => ['bytes 2-5/13'],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'          => ['"' . sha1(filemtime(SABRE_TEMPDIR . '/test.txt')) . '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [4],
+            'Content-Range'   => ['bytes 2-5/13'],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -46,24 +47,25 @@ class ServerRangeTest extends AbstractServer{
      */
     function testStartRange() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'GET',
             'HTTP_RANGE'     => 'bytes=2-',
-        );
+        ];
+        $filename = SABRE_TEMPDIR . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [11],
-            'Content-Range' => ['bytes 2-12/13'],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'          => ['"' . sha1(filemtime(SABRE_TEMPDIR . '/test.txt')) . '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [11],
+            'Content-Range'   => ['bytes 2-12/13'],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -77,24 +79,25 @@ class ServerRangeTest extends AbstractServer{
      */
     function testEndRange() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'GET',
             'HTTP_RANGE'     => 'bytes=-8',
-        );
+        ];
+        $filename = SABRE_TEMPDIR . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [8],
-            'Content-Range' => ['bytes 5-12/13'],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'          => ['"' . sha1(filemtime(SABRE_TEMPDIR . '/test.txt')). '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [8],
+            'Content-Range'   => ['bytes 5-12/13'],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -108,11 +111,11 @@ class ServerRangeTest extends AbstractServer{
      */
     function testTooHighRange() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'GET',
             'HTTP_RANGE'     => 'bytes=100-200',
-        );
+        ];
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
@@ -127,11 +130,11 @@ class ServerRangeTest extends AbstractServer{
      */
     function testCrazyRange() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'GET',
             'HTTP_RANGE'     => 'bytes=8-4',
-        );
+        ];
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
@@ -148,25 +151,26 @@ class ServerRangeTest extends AbstractServer{
 
         $node = $this->server->tree->getNodeForPath('test.txt');
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'GET',
             'HTTP_RANGE'     => 'bytes=2-5',
             'HTTP_IF_RANGE'  => $node->getETag(),
-        );
+        ];
+        $filename = SABRE_TEMPDIR . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [4],
-            'Content-Range' => ['bytes 2-5/13'],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'          => ['"' . sha1(filemtime(SABRE_TEMPDIR . '/test.txt')) . '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [4],
+            'Content-Range'   => ['bytes 2-5/13'],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -182,24 +186,25 @@ class ServerRangeTest extends AbstractServer{
 
         $node = $this->server->tree->getNodeForPath('test.txt');
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'GET',
             'HTTP_RANGE'     => 'bytes=2-5',
             'HTTP_IF_RANGE'  => $node->getETag() . 'blabla',
-        );
+        ];
+        $filename = SABRE_TEMPDIR . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [13],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'          => ['"' . sha1(filemtime(SABRE_TEMPDIR . '/test.txt')) . '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [13],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -215,25 +220,26 @@ class ServerRangeTest extends AbstractServer{
 
         $node = $this->server->tree->getNodeForPath('test.txt');
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'GET',
             'HTTP_RANGE'     => 'bytes=2-5',
             'HTTP_IF_RANGE'  => 'tomorrow',
-        );
+        ];
+        $filename = SABRE_TEMPDIR . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [4],
-            'Content-Range' => ['bytes 2-5/13'],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'          => ['"' . sha1(filemtime(SABRE_TEMPDIR . '/test.txt')) . '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [4],
+            'Content-Range'   => ['bytes 2-5/13'],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -249,24 +255,25 @@ class ServerRangeTest extends AbstractServer{
 
         $node = $this->server->tree->getNodeForPath('test.txt');
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'GET',
             'HTTP_RANGE'     => 'bytes=2-5',
             'HTTP_IF_RANGE'  => '-2 years',
-        );
+        ];
+        $filename = SABRE_TEMPDIR . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [13],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'          => ['"' . sha1(filemtime(SABRE_TEMPDIR . '/test.txt')) . '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [13],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
diff --git a/tests/Sabre/DAV/ServerSimpleTest.php b/tests/Sabre/DAV/ServerSimpleTest.php
index 809d61a..0053196 100644
--- a/tests/Sabre/DAV/ServerSimpleTest.php
+++ b/tests/Sabre/DAV/ServerSimpleTest.php
@@ -8,9 +8,9 @@ class ServerSimpleTest extends AbstractServer{
 
     function testConstructArray() {
 
-        $nodes = array(
+        $nodes = [
             new SimpleCollection('hello')
-        );
+        ];
 
         $server = new Server($nodes);
         $this->assertEquals($nodes[0], $server->tree->getNodeForPath('hello'));
@@ -22,10 +22,10 @@ class ServerSimpleTest extends AbstractServer{
      */
     function testConstructIncorrectObj() {
 
-        $nodes = array(
+        $nodes = [
             new SimpleCollection('hello'),
             new \STDClass(),
-        );
+        ];
 
         $server = new Server($nodes);
 
@@ -42,22 +42,23 @@ class ServerSimpleTest extends AbstractServer{
 
     function testGet() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'GET',
-        );
+        ];
+        $filename = $this->tempDir . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [13],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag' => ['"' . sha1(filemtime($this->tempDir . '/test.txt')) . '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [13],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -65,25 +66,27 @@ class ServerSimpleTest extends AbstractServer{
         $this->assertEquals('Test contents', stream_get_contents($this->response->body));
 
     }
+
     function testGetHttp10() {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/test.txt',
-            'REQUEST_METHOD' => 'GET',
+        $serverVars = [
+            'REQUEST_URI'     => '/test.txt',
+            'REQUEST_METHOD'  => 'GET',
             'SERVER_PROTOCOL' => 'HTTP/1.0',
-        );
+        ];
+        $filename = $this->tempDir . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [13],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag' => ['"' . sha1(filemtime($this->tempDir . '/test.txt')) . '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [13],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -95,10 +98,10 @@ class ServerSimpleTest extends AbstractServer{
 
     function testGetDoesntExist() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt_randomblbla',
             'REQUEST_METHOD' => 'GET',
-        );
+        ];
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
@@ -109,10 +112,10 @@ class ServerSimpleTest extends AbstractServer{
 
     function testGetDoesntExist2() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt/randomblbla',
             'REQUEST_METHOD' => 'GET',
-        );
+        ];
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
@@ -129,22 +132,23 @@ class ServerSimpleTest extends AbstractServer{
      */
     function testGetDoubleSlash() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '//test.txt',
             'REQUEST_METHOD' => 'GET',
-        );
+        ];
+        $filename = $this->tempDir . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [13],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag' => ['"' . sha1(filemtime($this->tempDir . '/test.txt')) . '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [13],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -156,22 +160,23 @@ class ServerSimpleTest extends AbstractServer{
 
     function testHEAD() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/test.txt',
             'REQUEST_METHOD' => 'HEAD',
-        );
+        ];
+        $filename = $this->tempDir . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [13],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' .  filemtime($this->tempDir . '/test.txt')))],
-            'ETag' => ['"' . sha1(filemtime($this->tempDir . '/test.txt')) . '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [13],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' .  filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -186,14 +191,14 @@ class ServerSimpleTest extends AbstractServer{
         $this->server->httpRequest = $request;
         $this->server->exec();
 
-        $this->assertEquals(array(
-            'DAV'            => ['1, 3, extended-mkcol'],
-            'MS-Author-Via'  => ['DAV'],
-            'Allow'          => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'],
-            'Accept-Ranges'  => ['bytes'],
-            'Content-Length' => ['0'],
+        $this->assertEquals([
+            'DAV'             => ['1, 3, extended-mkcol'],
+            'MS-Author-Via'   => ['DAV'],
+            'Allow'           => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'],
+            'Accept-Ranges'   => ['bytes'],
+            'Content-Length'  => ['0'],
             'X-Sabre-Version' => [Version::VERSION],
-        ),$this->response->getHeaders());
+        ],$this->response->getHeaders());
 
         $this->assertEquals(200, $this->response->status);
         $this->assertEquals('', $this->response->body);
@@ -207,14 +212,14 @@ class ServerSimpleTest extends AbstractServer{
 
         $this->server->exec();
 
-        $this->assertEquals(array(
-            'DAV'            => ['1, 3, extended-mkcol'],
-            'MS-Author-Via'  => ['DAV'],
-            'Allow'          => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT, MKCOL'],
-            'Accept-Ranges'  => ['bytes'],
-            'Content-Length' => ['0'],
+        $this->assertEquals([
+            'DAV'             => ['1, 3, extended-mkcol'],
+            'MS-Author-Via'   => ['DAV'],
+            'Allow'           => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT, MKCOL'],
+            'Accept-Ranges'   => ['bytes'],
+            'Content-Length'  => ['0'],
             'X-Sabre-Version' => [Version::VERSION],
-        ),$this->response->getHeaders());
+        ],$this->response->getHeaders());
 
         $this->assertEquals(200, $this->response->status);
         $this->assertEquals('', $this->response->body);
@@ -223,19 +228,19 @@ class ServerSimpleTest extends AbstractServer{
 
     function testNonExistantMethod() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/',
             'REQUEST_METHOD' => 'BLABLA',
-        );
+        ];
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/xml; charset=utf-8'],
-        ),$this->response->getHeaders());
+            'Content-Type'    => ['application/xml; charset=utf-8'],
+        ],$this->response->getHeaders());
 
         $this->assertEquals(501, $this->response->status);
 
@@ -244,19 +249,19 @@ class ServerSimpleTest extends AbstractServer{
 
     function testGETOnCollection() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/',
             'REQUEST_METHOD' => 'GET',
-        );
+        ];
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/xml; charset=utf-8'],
-        ),$this->response->getHeaders());
+            'Content-Type'    => ['application/xml; charset=utf-8'],
+        ],$this->response->getHeaders());
 
         $this->assertEquals(501, $this->response->status);
 
@@ -274,10 +279,11 @@ class ServerSimpleTest extends AbstractServer{
 
     function testBaseUri() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/blabla/test.txt',
             'REQUEST_METHOD' => 'GET',
-        );
+        ];
+        $filename = $this->tempDir . '/test.txt';
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->setBaseUri('/blabla/');
@@ -285,13 +291,13 @@ class ServerSimpleTest extends AbstractServer{
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/octet-stream'],
-            'Content-Length' => [13],
-            'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag' => ['"' . sha1(filemtime($this->tempDir . '/test.txt')) . '"'],
-            ),
+            'Content-Type'    => ['application/octet-stream'],
+            'Content-Length'  => [13],
+            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
+            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -302,13 +308,13 @@ class ServerSimpleTest extends AbstractServer{
 
     function testBaseUriAddSlash() {
 
-        $tests = array(
+        $tests = [
             '/'         => '/',
             '/foo'      => '/foo/',
             '/foo/'     => '/foo/',
             '/foo/bar'  => '/foo/bar/',
             '/foo/bar/' => '/foo/bar/',
-        );
+        ];
 
         foreach($tests as $test=>$result) {
             $this->server->setBaseUri($test);
@@ -321,11 +327,11 @@ class ServerSimpleTest extends AbstractServer{
 
     function testCalculateUri() {
 
-        $uris = array(
+        $uris = [
             'http://www.example.org/root/somepath',
             '/root/somepath',
             '/root/somepath/',
-        );
+        ];
 
         $this->server->setBaseUri('/root/');
 
@@ -349,11 +355,11 @@ class ServerSimpleTest extends AbstractServer{
 
     function testCalculateUriSpecialChars() {
 
-        $uris = array(
+        $uris = [
             'http://www.example.org/root/%C3%A0fo%C3%B3',
             '/root/%C3%A0fo%C3%B3',
             '/root/%C3%A0fo%C3%B3/'
-        );
+        ];
 
         $this->server->setBaseUri('/root/');
 
@@ -382,13 +388,29 @@ class ServerSimpleTest extends AbstractServer{
     }
 
     /**
+     * @expectedException \Sabre\DAV\Exception\Forbidden
      */
+    function testBaseUriCheck() {
+
+        $uris = [
+            'http://www.example.org/root/somepath',
+            '/root/somepath',
+            '/root/somepath/'
+        ];
+
+        $this->server->setBaseUri('root/');
+        $this->server->calculateUri('/root/testuri');
+
+        $this->fail('Expected an exception');
+
+    }
+
     function testGuessBaseUri() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI' => '/index.php/root',
             'PATH_INFO'   => '/root',
-        );
+        ];
 
         $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
         $server = new Server();
@@ -403,10 +425,10 @@ class ServerSimpleTest extends AbstractServer{
      */
     function testGuessBaseUriPercentEncoding() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI' => '/index.php/dir/path2/path%20with%20spaces',
             'PATH_INFO'   => '/dir/path2/path with spaces',
-        );
+        ];
 
         $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
         $server = new Server();
@@ -423,10 +445,10 @@ class ServerSimpleTest extends AbstractServer{
     function testGuessBaseUriPercentEncoding2() {
 
         $this->markTestIncomplete('This behaviour is not yet implemented');
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI' => '/some%20directory+mixed/index.php/dir/path2/path%20with%20spaces',
             'PATH_INFO'   => '/dir/path2/path with spaces',
-        );
+        ];
 
         $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
         $server = new Server();
@@ -438,10 +460,10 @@ class ServerSimpleTest extends AbstractServer{
 
     function testGuessBaseUri2() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI' => '/index.php/root/',
             'PATH_INFO'   => '/root/',
-        );
+        ];
 
         $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
         $server = new Server();
@@ -453,9 +475,9 @@ class ServerSimpleTest extends AbstractServer{
 
     function testGuessBaseUriNoPathInfo() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI' => '/index.php/root',
-        );
+        ];
 
         $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
         $server = new Server();
@@ -467,9 +489,9 @@ class ServerSimpleTest extends AbstractServer{
 
     function testGuessBaseUriNoPathInfo2() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI' => '/a/b/c/test.php',
-        );
+        ];
 
         $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
         $server = new Server();
@@ -485,10 +507,10 @@ class ServerSimpleTest extends AbstractServer{
      */
     function testGuessBaseUriQueryString() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI' => '/index.php/root?query_string=blabla',
             'PATH_INFO'   => '/root',
-        );
+        ];
 
         $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
         $server = new Server();
@@ -504,10 +526,10 @@ class ServerSimpleTest extends AbstractServer{
      */
     function testGuessBaseUriBadConfig() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI' => '/index.php/root/heyyy',
             'PATH_INFO'   => '/root',
-        );
+        ];
 
         $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
         $server = new Server();
@@ -519,19 +541,19 @@ class ServerSimpleTest extends AbstractServer{
 
     function testTriggerException() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI' => '/',
             'REQUEST_METHOD' => 'FOO',
-        );
+        ];
 
         $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = $httpRequest;
         $this->server->on('beforeMethod', [$this,'exceptionTrigger']);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'Content-Type' => ['application/xml; charset=utf-8'],
-        ),$this->response->getHeaders());
+        ],$this->response->getHeaders());
 
         $this->assertEquals(500, $this->response->status);
 
@@ -545,20 +567,20 @@ class ServerSimpleTest extends AbstractServer{
 
     function testReportNotFound() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/',
             'REQUEST_METHOD' => 'REPORT',
-        );
+        ];
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
         $this->server->httpRequest->setBody('<?xml version="1.0"?><bla:myreport xmlns:bla="http://www.rooftopsolutions.nl/NS"></bla:myreport>');
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type' => ['application/xml; charset=utf-8'],
-            ),
+            'Content-Type'    => ['application/xml; charset=utf-8'],
+            ],
             $this->response->getHeaders()
          );
 
@@ -568,10 +590,10 @@ class ServerSimpleTest extends AbstractServer{
 
     function testReportIntercepted() {
 
-        $serverVars = array(
+        $serverVars = [
             'REQUEST_URI'    => '/',
             'REQUEST_METHOD' => 'REPORT',
-        );
+        ];
 
         $request = HTTP\Sapi::createFromServerArray($serverVars);
         $this->server->httpRequest = ($request);
@@ -579,10 +601,10 @@ class ServerSimpleTest extends AbstractServer{
         $this->server->on('report', [$this,'reportHandler']);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => [Version::VERSION],
-            'testheader' => ['testvalue'],
-            ),
+            'testheader'      => ['testvalue'],
+            ],
             $this->response->getHeaders()
         );
 
@@ -603,14 +625,14 @@ class ServerSimpleTest extends AbstractServer{
 
     function testGetPropertiesForChildren() {
 
-        $result = $this->server->getPropertiesForChildren('',array(
+        $result = $this->server->getPropertiesForChildren('',[
             '{DAV:}getcontentlength',
-        ));
+        ]);
 
-        $expected = array(
-            'test.txt' => array('{DAV:}getcontentlength' => 13),
-            'dir/' => array(),
-        );
+        $expected = [
+            'test.txt' => ['{DAV:}getcontentlength' => 13],
+            'dir/'     => [],
+        ];
 
         $this->assertEquals($expected,$result);
 
diff --git a/tests/Sabre/DAV/SimpleFileTest.php b/tests/Sabre/DAV/SimpleFileTest.php
index de8b057..406c193 100644
--- a/tests/Sabre/DAV/SimpleFileTest.php
+++ b/tests/Sabre/DAV/SimpleFileTest.php
@@ -11,7 +11,7 @@ class SimpleFileTest extends \PHPUnit_Framework_TestCase {
         $this->assertEquals('filename.txt', $file->getName());
         $this->assertEquals('contents', $file->get());
         $this->assertEquals('8', $file->getSize());
-        $this->assertEquals('"' . md5('contents') . '"', $file->getETag());
+        $this->assertEquals('"' . sha1('contents') . '"', $file->getETag());
         $this->assertEquals('text/plain', $file->getContentType());
 
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list