summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-26 10:50:15 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-26 10:50:15 +0200
commitb11d8799c17b24e7823de8d8dc171fb78f9b8442 (patch)
tree35f4876285f0e1ae043b67387671c611139706ba /tests
parentee1f627155cad4153f3da3160ca6040c137841d3 (diff)
downloadnextcloud-server-b11d8799c17b24e7823de8d8dc171fb78f9b8442.tar.gz
nextcloud-server-b11d8799c17b24e7823de8d8dc171fb78f9b8442.zip
adding unit tests for ObjectTree::move()
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/connector/sabre/objecttree.php104
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php
new file mode 100644
index 00000000000..c920441c8b4
--- /dev/null
+++ b/tests/lib/connector/sabre/objecttree.php
@@ -0,0 +1,104 @@
+<?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.
+ */
+
+namespace Test\OC\Connector\Sabre;
+
+
+use OC_Connector_Sabre_Directory;
+use PHPUnit_Framework_TestCase;
+use Sabre_DAV_Exception_Forbidden;
+
+class TestDoubleFileView extends \OC\Files\View{
+
+ public function __construct($updatables, $canRename = true) {
+ $this->updatables = $updatables;
+ $this->canRename = $canRename;
+ }
+
+ public function isUpdatable($path) {
+ return $this->updatables[$path];
+ }
+
+ public function rename($path1, $path2) {
+ return $this->canRename;
+ }
+}
+
+class ObjectTree extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @dataProvider moveFailedProvider
+ * @expectedException Sabre_DAV_Exception_Forbidden
+ */
+ public function testMoveFailed($source, $dest, $updatables) {
+ $rootDir = new OC_Connector_Sabre_Directory('');
+ $objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree',
+ array('nodeExists', 'getNodeForPath'),
+ array($rootDir));
+
+ $objectTree->expects($this->once())
+ ->method('getNodeForPath')
+ ->with($this->identicalTo('a/b'))
+ ->will($this->returnValue(false));
+
+ /** @var $objectTree \OC\Connector\Sabre\ObjectTree */
+ $objectTree->fileView = new TestDoubleFileView($updatables);
+ $objectTree->move($source, $dest);
+ }
+
+ /**
+ * @dataProvider moveSuccessProvider
+ */
+ public function testMoveSuccess($source, $dest, $updatables) {
+ $rootDir = new OC_Connector_Sabre_Directory('');
+ $objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree',
+ array('nodeExists', 'getNodeForPath'),
+ array($rootDir));
+
+ $objectTree->expects($this->once())
+ ->method('getNodeForPath')
+ ->with($this->identicalTo('a/b'))
+ ->will($this->returnValue(false));
+
+ /** @var $objectTree \OC\Connector\Sabre\ObjectTree */
+ $objectTree->fileView = new TestDoubleFileView($updatables);
+ $objectTree->move($source, $dest);
+ $this->assertTrue(true);
+ }
+
+ function moveFailedProvider() {
+ return array(
+ array('a/b', 'a/c', array('a' => false, 'a/b' => false, 'a/c' => false)),
+ array('a/b', 'b/b', array('a' => false, 'a/b' => false, 'b' => false, 'b/b' => false)),
+ array('a/b', 'b/b', array('a' => false, 'a/b' => true, 'b' => false, 'b/b' => false)),
+ array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => false, 'b/b' => false)),
+ );
+ }
+
+ function moveSuccessProvider() {
+ return array(
+ array('a/b', 'a/c', array('a' => false, 'a/b' => true, 'a/c' => false)),
+ array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => true, 'b/b' => false)),
+ );
+ }
+
+// private function buildFileViewMock($updatables) {
+// // mock filesysten
+// $view = $this->getMock('\OC\Files\View', array('isUpdatable'), array(), '', FALSE);
+//
+// foreach ($updatables as $path => $updatable) {
+// $view->expects($this->any())
+// ->method('isUpdatable')
+// ->with($this->identicalTo($path))
+// ->will($this->returnValue($updatable));
+// }
+//
+// return $view;
+// }
+
+}