summaryrefslogtreecommitdiffstats
path: root/tests/lib/connector/sabre
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/connector/sabre')
-rw-r--r--tests/lib/connector/sabre/aborteduploaddetectionplugin.php27
-rw-r--r--tests/lib/connector/sabre/directory.php22
-rw-r--r--tests/lib/connector/sabre/file.php77
-rw-r--r--tests/lib/connector/sabre/objecttree.php15
-rw-r--r--tests/lib/connector/sabre/quotaplugin.php23
5 files changed, 110 insertions, 54 deletions
diff --git a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php b/tests/lib/connector/sabre/aborteduploaddetectionplugin.php
index 201f1263867..60d141e72bc 100644
--- a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php
+++ b/tests/lib/connector/sabre/aborteduploaddetectionplugin.php
@@ -1,11 +1,11 @@
<?php
+
/**
* Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
-
class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Framework_TestCase {
/**
@@ -18,17 +18,18 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame
*/
private $plugin;
- public function setUp() {
+ private function init($view) {
$this->server = new Sabre_DAV_Server();
- $this->plugin = new OC_Connector_Sabre_AbortedUploadDetectionPlugin();
+ $this->plugin = new OC_Connector_Sabre_AbortedUploadDetectionPlugin($view);
$this->plugin->initialize($this->server);
}
/**
* @dataProvider lengthProvider
*/
- public function testLength($expected, $headers)
- {
+ public function testLength($expected, $headers) {
+ $this->init(null);
+
$this->server->httpRequest = new Sabre_HTTP_Request($headers);
$length = $this->plugin->getLength();
$this->assertEquals($expected, $length);
@@ -37,9 +38,8 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame
/**
* @dataProvider verifyContentLengthProvider
*/
- public function testVerifyContentLength($method, $fileSize, $headers)
- {
- $this->plugin->fileView = $this->buildFileViewMock($fileSize);
+ public function testVerifyContentLength($method, $fileSize, $headers) {
+ $this->init($this->buildFileViewMock($fileSize));
$headers['REQUEST_METHOD'] = $method;
$this->server->httpRequest = new Sabre_HTTP_Request($headers);
@@ -51,12 +51,11 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame
* @dataProvider verifyContentLengthFailedProvider
* @expectedException Sabre_DAV_Exception_BadRequest
*/
- public function testVerifyContentLengthFailed($method, $fileSize, $headers)
- {
- $this->plugin->fileView = $this->buildFileViewMock($fileSize);
-
+ public function testVerifyContentLengthFailed($method, $fileSize, $headers) {
+ $view = $this->buildFileViewMock($fileSize);
+ $this->init($view);
// we expect unlink to be called
- $this->plugin->fileView->expects($this->once())->method('unlink');
+ $view->expects($this->once())->method('unlink');
$headers['REQUEST_METHOD'] = $method;
$this->server->httpRequest = new Sabre_HTTP_Request($headers);
@@ -92,7 +91,7 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame
private function buildFileViewMock($fileSize) {
// mock filesystem
- $view = $this->getMock('\OC\Files\View', array('filesize', 'unlink'), array(), '', FALSE);
+ $view = $this->getMock('\OC\Files\View', array('filesize', 'unlink'), array(), '', false);
$view->expects($this->any())->method('filesize')->withAnyParameters()->will($this->returnValue($fileSize));
return $view;
diff --git a/tests/lib/connector/sabre/directory.php b/tests/lib/connector/sabre/directory.php
index c501521b601..b2bf0d4a6d2 100644
--- a/tests/lib/connector/sabre/directory.php
+++ b/tests/lib/connector/sabre/directory.php
@@ -1,18 +1,32 @@
<?php
+
/**
* Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
-
class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase {
+ private function getRootDir() {
+ $view = $this->getMock('OC\Files\View', array(), array(), '', false);
+ $view->expects($this->once())
+ ->method('getRelativePath')
+ ->will($this->returnValue(''));
+
+ $info = $this->getMock('OC\Files\FileInfo', array(), array(), '', false);
+ $info->expects($this->once())
+ ->method('getPath')
+ ->will($this->returnValue(''));
+
+ return new OC_Connector_Sabre_Directory($view, $info);
+ }
+
/**
* @expectedException Sabre_DAV_Exception_Forbidden
*/
public function testCreateSharedFileFails() {
- $dir = new OC_Connector_Sabre_Directory('');
+ $dir = $this->getRootDir();
$dir->createFile('Shared');
}
@@ -20,7 +34,7 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase {
* @expectedException Sabre_DAV_Exception_Forbidden
*/
public function testCreateSharedFolderFails() {
- $dir = new OC_Connector_Sabre_Directory('');
+ $dir = $this->getRootDir();
$dir->createDirectory('Shared');
}
@@ -28,7 +42,7 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase {
* @expectedException Sabre_DAV_Exception_Forbidden
*/
public function testDeleteSharedFolderFails() {
- $dir = new OC_Connector_Sabre_Directory('Shared');
+ $dir = $this->getRootDir();
$dir->delete();
}
}
diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php
index c2f0ffa12d4..a9056460a5c 100644
--- a/tests/lib/connector/sabre/file.php
+++ b/tests/lib/connector/sabre/file.php
@@ -13,9 +13,20 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
*/
public function testSimplePutFails() {
// setup
- $file = new OC_Connector_Sabre_File('/test.txt');
- $file->fileView = $this->getMock('\OC\Files\View', array('file_put_contents'), array(), '', FALSE);
- $file->fileView->expects($this->any())->method('file_put_contents')->withAnyParameters()->will($this->returnValue(false));
+ $view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath'), array(), '', false);
+ $view->expects($this->any())
+ ->method('file_put_contents')
+ ->will($this->returnValue(false));
+
+ $view->expects($this->any())
+ ->method('getRelativePath')
+ ->will($this->returnValue('/test.txt'));
+
+ $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
+ 'permissions'=>\OCP\PERMISSION_ALL
+ ));
+
+ $file = new OC_Connector_Sabre_File($view, $info);
// action
$etag = $file->put('test data');
@@ -26,10 +37,25 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
*/
public function testSimplePutFailsOnRename() {
// setup
- $file = new OC_Connector_Sabre_File('/test.txt');
- $file->fileView = $this->getMock('\OC\Files\View', array('file_put_contents', 'rename'), array(), '', FALSE);
- $file->fileView->expects($this->any())->method('file_put_contents')->withAnyParameters()->will($this->returnValue(true));
- $file->fileView->expects($this->any())->method('rename')->withAnyParameters()->will($this->returnValue(false));
+ $view = $this->getMock('\OC\Files\View', array('file_put_contents', 'rename', 'getRelativePath'), array(), '', false);
+ $view->expects($this->any())
+ ->method('file_put_contents')
+ ->withAnyParameters()
+ ->will($this->returnValue(true));
+ $view->expects($this->any())
+ ->method('rename')
+ ->withAnyParameters()
+ ->will($this->returnValue(false));
+
+ $view->expects($this->any())
+ ->method('getRelativePath')
+ ->will($this->returnValue('/test.txt'));
+
+ $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
+ 'permissions' => \OCP\PERMISSION_ALL
+ ));
+
+ $file = new OC_Connector_Sabre_File($view, $info);
// action
$etag = $file->put('test data');
@@ -40,9 +66,19 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
*/
public function testSimplePutInvalidChars() {
// setup
- $file = new OC_Connector_Sabre_File('/super*star.txt');
- $file->fileView = $this->getMock('\OC\Files\View', array('file_put_contents'), array(), '', FALSE);
- $file->fileView->expects($this->any())->method('file_put_contents')->withAnyParameters()->will($this->returnValue(false));
+ $view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath'), array(), '', false);
+ $view->expects($this->any())
+ ->method('file_put_contents')
+ ->will($this->returnValue(false));
+
+ $view->expects($this->any())
+ ->method('getRelativePath')
+ ->will($this->returnValue('/super*star.txt'));
+
+ $info = new \OC\Files\FileInfo('/super*star.txt', null, null, array(
+ 'permissions' => \OCP\PERMISSION_ALL
+ ));
+ $file = new OC_Connector_Sabre_File($view, $info);
// action
$etag = $file->put('test data');
@@ -54,17 +90,16 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
*/
public function testSetNameInvalidChars() {
// setup
- $file = new OC_Connector_Sabre_File('/test.txt');
- $file->fileView = $this->getMock('\OC\Files\View', array('isUpdatable'), array(), '', FALSE);
- $file->fileView->expects($this->any())->method('isUpdatable')->withAnyParameters()->will($this->returnValue(true));
- $file->setName('/super*star.txt');
- }
+ $view = $this->getMock('\OC\Files\View', array('getRelativePath'), array(), '', false);
- /**
- * @expectedException Sabre_DAV_Exception_Forbidden
- */
- public function testDeleteSharedFails() {
- $file = new OC_Connector_Sabre_File('Shared');
- $file->delete();
+ $view->expects($this->any())
+ ->method('getRelativePath')
+ ->will($this->returnValue('/super*star.txt'));
+
+ $info = new \OC\Files\FileInfo('/super*star.txt', null, null, array(
+ 'permissions' => \OCP\PERMISSION_ALL
+ ));
+ $file = new OC_Connector_Sabre_File($view, $info);
+ $file->setName('/super*star.txt');
}
}
diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php
index fb50c736edd..bc8ec98faee 100644
--- a/tests/lib/connector/sabre/objecttree.php
+++ b/tests/lib/connector/sabre/objecttree.php
@@ -9,6 +9,7 @@
namespace Test\OC\Connector\Sabre;
+use OC\Files\FileInfo;
use OC_Connector_Sabre_Directory;
use PHPUnit_Framework_TestCase;
use Sabre_DAV_Exception_Forbidden;
@@ -32,6 +33,10 @@ class TestDoubleFileView extends \OC\Files\View{
public function rename($path1, $path2) {
return $this->canRename;
}
+
+ public function getRelativePath($path){
+ return $path;
+ }
}
class ObjectTree extends PHPUnit_Framework_TestCase {
@@ -91,10 +96,14 @@ class ObjectTree extends PHPUnit_Framework_TestCase {
* @param $updatables
*/
private function moveTest($source, $dest, $updatables, $deletables) {
- $rootDir = new OC_Connector_Sabre_Directory('');
+ $view = new TestDoubleFileView($updatables, $deletables);
+
+ $info = new FileInfo('', null, null, array());
+
+ $rootDir = new OC_Connector_Sabre_Directory($view, $info);
$objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree',
array('nodeExists', 'getNodeForPath'),
- array($rootDir));
+ array($rootDir, $view));
$objectTree->expects($this->once())
->method('getNodeForPath')
@@ -102,7 +111,7 @@ class ObjectTree extends PHPUnit_Framework_TestCase {
->will($this->returnValue(false));
/** @var $objectTree \OC\Connector\Sabre\ObjectTree */
- $objectTree->fileView = new TestDoubleFileView($updatables, $deletables);
+ $objectTree->init($rootDir, $view);
$objectTree->move($source, $dest);
}
diff --git a/tests/lib/connector/sabre/quotaplugin.php b/tests/lib/connector/sabre/quotaplugin.php
index 1186de28742..6781b970a4f 100644
--- a/tests/lib/connector/sabre/quotaplugin.php
+++ b/tests/lib/connector/sabre/quotaplugin.php
@@ -1,11 +1,11 @@
<?php
+
/**
* Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
-
class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase {
/**
@@ -18,17 +18,18 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase {
*/
private $plugin;
- public function setUp() {
+ private function init($quota) {
+ $view = $this->buildFileViewMock($quota);
$this->server = new Sabre_DAV_Server();
- $this->plugin = new OC_Connector_Sabre_QuotaPlugin();
+ $this->plugin = new OC_Connector_Sabre_QuotaPlugin($view);
$this->plugin->initialize($this->server);
}
/**
* @dataProvider lengthProvider
*/
- public function testLength($expected, $headers)
- {
+ public function testLength($expected, $headers) {
+ $this->init(0);
$this->server->httpRequest = new Sabre_HTTP_Request($headers);
$length = $this->plugin->getLength();
$this->assertEquals($expected, $length);
@@ -37,9 +38,8 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase {
/**
* @dataProvider quotaOkayProvider
*/
- public function testCheckQuota($quota, $headers)
- {
- $this->plugin->fileView = $this->buildFileViewMock($quota);
+ public function testCheckQuota($quota, $headers) {
+ $this->init($quota);
$this->server->httpRequest = new Sabre_HTTP_Request($headers);
$result = $this->plugin->checkQuota('');
@@ -50,9 +50,8 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase {
* @expectedException Sabre_DAV_Exception_InsufficientStorage
* @dataProvider quotaExceededProvider
*/
- public function testCheckExceededQuota($quota, $headers)
- {
- $this->plugin->fileView = $this->buildFileViewMock($quota);
+ public function testCheckExceededQuota($quota, $headers) {
+ $this->init($quota);
$this->server->httpRequest = new Sabre_HTTP_Request($headers);
$this->plugin->checkQuota('');
@@ -92,7 +91,7 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase {
private function buildFileViewMock($quota) {
// mock filesysten
- $view = $this->getMock('\OC\Files\View', array('free_space'), array(), '', FALSE);
+ $view = $this->getMock('\OC\Files\View', array('free_space'), array(), '', false);
$view->expects($this->any())->method('free_space')->withAnyParameters()->will($this->returnValue($quota));
return $view;