diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-09-18 11:57:28 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-09-18 11:57:28 +0200 |
commit | 3ca61db63b9e32f316479582171f4b1b2144f295 (patch) | |
tree | 52aaa7635f6a427aa12cd5cbd79b7bf4842fb733 /tests | |
parent | 8fa4ebaf6dcede56968d4ae387f3542385ca2f0d (diff) | |
parent | 3cf4fc02f9c99ba523f384f3def9f04eac21a067 (diff) | |
download | nextcloud-server-3ca61db63b9e32f316479582171f4b1b2144f295.tar.gz nextcloud-server-3ca61db63b9e32f316479582171f4b1b2144f295.zip |
Merge pull request #19017 from owncloud/dav-download-tests
Add tests for downloading files over dav
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/connector/sabre/requesttest/downloadtest.php | 52 | ||||
-rw-r--r-- | tests/lib/connector/sabre/requesttest/sapi.php | 10 |
2 files changed, 61 insertions, 1 deletions
diff --git a/tests/lib/connector/sabre/requesttest/downloadtest.php b/tests/lib/connector/sabre/requesttest/downloadtest.php new file mode 100644 index 00000000000..67dd9f52308 --- /dev/null +++ b/tests/lib/connector/sabre/requesttest/downloadtest.php @@ -0,0 +1,52 @@ +<?php +/** + * Copyright (c) 2015 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Connector\Sabre\RequestTest; + +use OCP\AppFramework\Http; +use OCP\Lock\ILockingProvider; + +class DownloadTest extends RequestTest { + public function testDownload() { + $user = $this->getUniqueID(); + $view = $this->setupUser($user, 'pass'); + + $view->file_put_contents('foo.txt', 'bar'); + + $response = $this->request($view, $user, 'pass', 'GET', '/foo.txt'); + $this->assertEquals(Http::STATUS_OK, $response->getStatus()); + $this->assertEquals(stream_get_contents($response->getBody()), 'bar'); + } + + /** + * @expectedException \OC\Connector\Sabre\Exception\FileLocked + */ + public function testDownloadWriteLocked() { + $user = $this->getUniqueID(); + $view = $this->setupUser($user, 'pass'); + + $view->file_put_contents('foo.txt', 'bar'); + + $view->lockFile('/foo.txt', ILockingProvider::LOCK_EXCLUSIVE); + + $this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd'); + } + + public function testDownloadReadLocked() { + $user = $this->getUniqueID(); + $view = $this->setupUser($user, 'pass'); + + $view->file_put_contents('foo.txt', 'bar'); + + $view->lockFile('/foo.txt', ILockingProvider::LOCK_SHARED); + + $response = $this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd'); + $this->assertEquals(Http::STATUS_OK, $response->getStatus()); + $this->assertEquals(stream_get_contents($response->getBody()), 'bar'); + } +} diff --git a/tests/lib/connector/sabre/requesttest/sapi.php b/tests/lib/connector/sabre/requesttest/sapi.php index 7072b8bd286..cda9fdb70f5 100644 --- a/tests/lib/connector/sabre/requesttest/sapi.php +++ b/tests/lib/connector/sabre/requesttest/sapi.php @@ -41,7 +41,15 @@ class Sapi { * @return void */ public function sendResponse(Response $response) { - $this->response = $response; + // we need to copy the body since we close the source stream + $copyStream = fopen('php://temp', 'r+'); + if (is_string($response->getBody())) { + fwrite($copyStream, $response->getBody()); + } else if (is_resource($response->getBody())) { + stream_copy_to_stream($response->getBody(), $copyStream); + } + rewind($copyStream); + $this->response = new Response($response->getStatus(), $response->getHeaders(), $copyStream); } /** |