From a22f9ff301312bb24332edaacfb65c280cd8fcd8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 1 Sep 2013 19:47:48 +0200 Subject: Provide an implementation of the fileapi for oc6 build on top of the old api --- tests/lib/files/node/node.php | 330 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 tests/lib/files/node/node.php (limited to 'tests/lib/files/node/node.php') diff --git a/tests/lib/files/node/node.php b/tests/lib/files/node/node.php new file mode 100644 index 00000000000..aa9d2a382eb --- /dev/null +++ b/tests/lib/files/node/node.php @@ -0,0 +1,330 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Files\Node; + +class Node extends \PHPUnit_Framework_TestCase { + private $user; + + public function setUp() { + $this->user = new \OC\User\User('', new \OC_User_Dummy); + } + + public function testStat() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + + $stat = array( + 'fileid' => 1, + 'size' => 100, + 'etag' => 'qwerty', + 'mtime' => 50, + 'permissions' => 0 + ); + + $view->expects($this->once()) + ->method('stat') + ->with('/bar/foo') + ->will($this->returnValue($stat)); + + $node = new \OC\Files\Node\File($root, $view, '/bar/foo'); + $this->assertEquals($stat, $node->stat()); + } + + public function testGetId() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + + $stat = array( + 'fileid' => 1, + 'size' => 100, + 'etag' => 'qwerty', + 'mtime' => 50 + ); + + $view->expects($this->once()) + ->method('getFileInfo') + ->with('/bar/foo') + ->will($this->returnValue($stat)); + + $node = new \OC\Files\Node\File($root, $view, '/bar/foo'); + $this->assertEquals(1, $node->getId()); + } + + public function testGetSize() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + + $view->expects($this->once()) + ->method('filesize') + ->with('/bar/foo') + ->will($this->returnValue(100)); + + $node = new \OC\Files\Node\File($root, $view, '/bar/foo'); + $this->assertEquals(100, $node->getSize()); + } + + public function testGetEtag() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + + $stat = array( + 'fileid' => 1, + 'size' => 100, + 'etag' => 'qwerty', + 'mtime' => 50 + ); + + $view->expects($this->once()) + ->method('getFileInfo') + ->with('/bar/foo') + ->will($this->returnValue($stat)); + + $node = new \OC\Files\Node\File($root, $view, '/bar/foo'); + $this->assertEquals('qwerty', $node->getEtag()); + } + + public function testGetMTime() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + /** + * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage + */ + $storage = $this->getMock('\OC\Files\Storage\Storage'); + + $view->expects($this->once()) + ->method('filemtime') + ->with('/bar/foo') + ->will($this->returnValue(50)); + + $node = new \OC\Files\Node\File($root, $view, '/bar/foo'); + $this->assertEquals(50, $node->getMTime()); + } + + public function testGetStorage() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + /** + * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage + */ + $storage = $this->getMock('\OC\Files\Storage\Storage'); + + $view->expects($this->once()) + ->method('resolvePath') + ->with('/bar/foo') + ->will($this->returnValue(array($storage, 'foo'))); + + + $node = new \OC\Files\Node\File($root, $view, '/bar/foo'); + $this->assertEquals($storage, $node->getStorage()); + } + + public function testGetPath() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + + $node = new \OC\Files\Node\File($root, $view, '/bar/foo'); + $this->assertEquals('/bar/foo', $node->getPath()); + } + + public function testGetInternalPath() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + /** + * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage + */ + $storage = $this->getMock('\OC\Files\Storage\Storage'); + + $view->expects($this->once()) + ->method('resolvePath') + ->with('/bar/foo') + ->will($this->returnValue(array($storage, 'foo'))); + + + $node = new \OC\Files\Node\File($root, $view, '/bar/foo'); + $this->assertEquals('foo', $node->getInternalPath()); + } + + public function testGetName() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + + $node = new \OC\Files\Node\File($root, $view, '/bar/foo'); + $this->assertEquals('foo', $node->getName()); + } + + public function testTouchSetMTime() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + + $view->expects($this->once()) + ->method('touch') + ->with('/bar/foo', 100) + ->will($this->returnValue(true)); + + $view->expects($this->once()) + ->method('filemtime') + ->with('/bar/foo') + ->will($this->returnValue(100)); + + $view->expects($this->once()) + ->method('getFileInfo') + ->with('/bar/foo') + ->will($this->returnValue(array('permissions' => \OCP\PERMISSION_ALL))); + + $node = new \OC\Files\Node\Node($root, $view, '/bar/foo'); + $node->touch(100); + $this->assertEquals(100, $node->getMTime()); + } + + public function testTouchHooks() { + $test = $this; + $hooksRun = 0; + /** + * @param \OC\Files\Node\File $node + */ + $preListener = function ($node) use (&$test, &$hooksRun) { + $test->assertEquals('foo', $node->getInternalPath()); + $test->assertEquals('/bar/foo', $node->getPath()); + $hooksRun++; + }; + + /** + * @param \OC\Files\Node\File $node + */ + $postListener = function ($node) use (&$test, &$hooksRun) { + $test->assertEquals('foo', $node->getInternalPath()); + $test->assertEquals('/bar/foo', $node->getPath()); + $hooksRun++; + }; + + /** + * @var \OC\Files\Mount\Manager $manager + */ + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = new \OC\Files\Node\Root($manager, $view, $this->user); + $root->listen('\OC\Files', 'preTouch', $preListener); + $root->listen('\OC\Files', 'postTouch', $postListener); + + $view->expects($this->once()) + ->method('touch') + ->with('/bar/foo', 100) + ->will($this->returnValue(true)); + + $view->expects($this->any()) + ->method('resolvePath') + ->with('/bar/foo') + ->will($this->returnValue(array(null, 'foo'))); + + $view->expects($this->any()) + ->method('getFileInfo') + ->with('/bar/foo') + ->will($this->returnValue(array('permissions' => \OCP\PERMISSION_ALL))); + + $node = new \OC\Files\Node\Node($root, $view, '/bar/foo'); + $node->touch(100); + $this->assertEquals(2, $hooksRun); + } + + /** + * @expectedException \OC\Files\NotPermittedException + */ + public function testTouchNotPermitted() { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user)); + $root->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); + + $view->expects($this->any()) + ->method('getFileInfo') + ->with('/bar/foo') + ->will($this->returnValue(array('permissions' => \OCP\PERMISSION_READ))); + + $node = new \OC\Files\Node\Node($root, $view, '/bar/foo'); + $node->touch(100); + } +} -- cgit v1.2.3 From b9167196fb331d7197210e4a130e03d32d839b8a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 10 Sep 2013 22:21:49 +0200 Subject: adjust test cases to namespace changes --- tests/lib/files/node/file.php | 28 ++++++++++++++-------------- tests/lib/files/node/folder.php | 10 +++++----- tests/lib/files/node/integration.php | 4 ++-- tests/lib/files/node/node.php | 2 +- tests/lib/files/node/root.php | 8 ++++---- 5 files changed, 26 insertions(+), 26 deletions(-) (limited to 'tests/lib/files/node/node.php') diff --git a/tests/lib/files/node/file.php b/tests/lib/files/node/file.php index 707106373b5..76938a0dcc8 100644 --- a/tests/lib/files/node/file.php +++ b/tests/lib/files/node/file.php @@ -8,8 +8,8 @@ namespace Test\Files\Node; -use OC\Files\NotFoundException; -use OC\Files\NotPermittedException; +use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OC\Files\View; class File extends \PHPUnit_Framework_TestCase { @@ -106,7 +106,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testDeleteNotPermitted() { $manager = $this->getMock('\OC\Files\Mount\Manager'); @@ -162,7 +162,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testGetContentNotPermitted() { $manager = $this->getMock('\OC\Files\Mount\Manager'); @@ -212,7 +212,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testPutContentNotPermitted() { $manager = $this->getMock('\OC\Files\Mount\Manager'); @@ -327,7 +327,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testFOpenReadNotPermitted() { /** @@ -354,7 +354,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testFOpenReadWriteNoReadPermissions() { /** @@ -381,7 +381,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testFOpenReadWriteNoWritePermissions() { /** @@ -443,7 +443,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testCopyNotPermitted() { /** @@ -483,7 +483,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotFoundException + * @expectedException \OCP\Files\NotFoundException */ public function testCopyNoParent() { /** @@ -510,7 +510,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testCopyParentIsFile() { /** @@ -571,7 +571,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testMoveNotPermitted() { /** @@ -603,7 +603,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotFoundException + * @expectedException \OCP\Files\NotFoundException */ public function testMoveNoParent() { /** @@ -635,7 +635,7 @@ class File extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testMoveParentIsFile() { /** diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php index 691aa612c7f..b1589a276ba 100644 --- a/tests/lib/files/node/folder.php +++ b/tests/lib/files/node/folder.php @@ -10,8 +10,8 @@ namespace Test\Files\Node; use OC\Files\Cache\Cache; use OC\Files\Node\Node; -use OC\Files\NotFoundException; -use OC\Files\NotPermittedException; +use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OC\Files\View; class Folder extends \PHPUnit_Framework_TestCase { @@ -103,7 +103,7 @@ class Folder extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testDeleteNotPermitted() { $manager = $this->getMock('\OC\Files\Mount\Manager'); @@ -275,7 +275,7 @@ class Folder extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testNewFolderNotPermitted() { $manager = $this->getMock('\OC\Files\Mount\Manager'); @@ -325,7 +325,7 @@ class Folder extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testNewFileNotPermitted() { $manager = $this->getMock('\OC\Files\Mount\Manager'); diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php index c99b6f99ebc..bc439c1aa0b 100644 --- a/tests/lib/files/node/integration.php +++ b/tests/lib/files/node/integration.php @@ -11,8 +11,8 @@ namespace Test\Files\Node; use OC\Files\Cache\Cache; use OC\Files\Mount\Manager; use OC\Files\Node\Root; -use OC\Files\NotFoundException; -use OC\Files\NotPermittedException; +use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OC\Files\Storage\Temporary; use OC\Files\View; use OC\User\User; diff --git a/tests/lib/files/node/node.php b/tests/lib/files/node/node.php index aa9d2a382eb..cf5fec30522 100644 --- a/tests/lib/files/node/node.php +++ b/tests/lib/files/node/node.php @@ -306,7 +306,7 @@ class Node extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testTouchNotPermitted() { $manager = $this->getMock('\OC\Files\Mount\Manager'); diff --git a/tests/lib/files/node/root.php b/tests/lib/files/node/root.php index 0b356ec6d97..97eaf7f7162 100644 --- a/tests/lib/files/node/root.php +++ b/tests/lib/files/node/root.php @@ -9,7 +9,7 @@ namespace Test\Files\Node; use OC\Files\Cache\Cache; -use OC\Files\NotPermittedException; +use OCP\Files\NotPermittedException; use OC\Files\Mount\Manager; class Root extends \PHPUnit_Framework_TestCase { @@ -53,7 +53,7 @@ class Root extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotFoundException + * @expectedException \OCP\Files\NotFoundException */ public function testGetNotFound() { $manager = new Manager(); @@ -77,7 +77,7 @@ class Root extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotPermittedException + * @expectedException \OCP\Files\NotPermittedException */ public function testGetInvalidPath() { $manager = new Manager(); @@ -91,7 +91,7 @@ class Root extends \PHPUnit_Framework_TestCase { } /** - * @expectedException \OC\Files\NotFoundException + * @expectedException \OCP\Files\NotFoundException */ public function testGetNoStorages() { $manager = new Manager(); -- cgit v1.2.3