diff options
Diffstat (limited to 'tests/lib/files/node')
-rw-r--r-- | tests/lib/files/node/file.php | 2 | ||||
-rw-r--r-- | tests/lib/files/node/folder.php | 78 | ||||
-rw-r--r-- | tests/lib/files/node/hookconnector.php | 176 | ||||
-rw-r--r-- | tests/lib/files/node/integration.php | 2 | ||||
-rw-r--r-- | tests/lib/files/node/node.php | 2 | ||||
-rw-r--r-- | tests/lib/files/node/root.php | 2 |
6 files changed, 227 insertions, 35 deletions
diff --git a/tests/lib/files/node/file.php b/tests/lib/files/node/file.php index e3b8019b4ca..c431a2eb366 100644 --- a/tests/lib/files/node/file.php +++ b/tests/lib/files/node/file.php @@ -18,7 +18,7 @@ class File extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->user = new \OC\User\User('', new \OC_User_Dummy); + $this->user = new \OC\User\User('', new \Test\Util\User\Dummy); } protected function getFileInfo($data) { diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php index 4a88e2acd36..8c98256575e 100644 --- a/tests/lib/files/node/folder.php +++ b/tests/lib/files/node/folder.php @@ -21,7 +21,7 @@ class Folder extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->user = new \OC\User\User('', new \OC_User_Dummy); + $this->user = new \OC\User\User('', new \Test\Util\User\Dummy); } protected function getFileInfo($data) { @@ -143,38 +143,13 @@ class Folder extends \Test\TestCase { ->method('getUser') ->will($this->returnValue($this->user)); - /** - * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage - */ - $storage = $this->getMock('\OC\Files\Storage\Storage'); - - $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array('')); - $cache->expects($this->any()) - ->method('getStatus') - ->with('foo') - ->will($this->returnValue(Cache::COMPLETE)); - - $cache->expects($this->once()) - ->method('getFolderContents') - ->with('foo') - ->will($this->returnValue(array( - array('fileid' => 2, 'path' => '/bar/foo/asd', 'name' => 'asd', 'size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain'), - array('fileid' => 3, 'path' => '/bar/foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'httpd/unix-directory') - ))); - - $root->expects($this->once()) - ->method('getMountsIn') - ->with('/bar/foo') - ->will($this->returnValue(array())); - - $storage->expects($this->any()) - ->method('getCache') - ->will($this->returnValue($cache)); - $view->expects($this->any()) - ->method('resolvePath') + ->method('getDirectoryContent') ->with('/bar/foo') - ->will($this->returnValue(array($storage, 'foo'))); + ->will($this->returnValue(array( + new FileInfo('/bar/foo/asd', null, 'foo/asd', ['fileid' => 2, 'path' => '/bar/foo/asd', 'name' => 'asd', 'size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain'], null), + new FileInfo('/bar/foo/qwerty', null, 'foo/qwerty', ['fileid' => 3, 'path' => '/bar/foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'httpd/unix-directory'], null) + ))); $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo'); $children = $node->getDirectoryListing(); @@ -183,6 +158,8 @@ class Folder extends \Test\TestCase { $this->assertInstanceOf('\OC\Files\Node\Folder', $children[1]); $this->assertEquals('asd', $children[0]->getName()); $this->assertEquals('qwerty', $children[1]->getName()); + $this->assertEquals(2, $children[0]->getId()); + $this->assertEquals(3, $children[1]->getId()); } public function testGet() { @@ -444,6 +421,45 @@ class Folder extends \Test\TestCase { $this->assertEquals('/foo', $result[0]->getPath()); } + public function testSearchInStorageRoot() { + $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)); + $storage = $this->getMock('\OC\Files\Storage\Storage'); + $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array('')); + + $storage->expects($this->once()) + ->method('getCache') + ->will($this->returnValue($cache)); + + $cache->expects($this->once()) + ->method('search') + ->with('%qw%') + ->will($this->returnValue(array( + array('fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain') + ))); + + $root->expects($this->once()) + ->method('getMountsIn') + ->with('/bar') + ->will($this->returnValue(array())); + + $view->expects($this->once()) + ->method('resolvePath') + ->will($this->returnValue(array($storage, ''))); + + $node = new \OC\Files\Node\Folder($root, $view, '/bar'); + $result = $node->search('qw'); + $this->assertEquals(1, count($result)); + $this->assertEquals('/bar/foo/qwerty', $result[0]->getPath()); + } + public function testSearchByTag() { $manager = $this->getMock('\OC\Files\Mount\Manager'); /** diff --git a/tests/lib/files/node/hookconnector.php b/tests/lib/files/node/hookconnector.php new file mode 100644 index 00000000000..10566cf5fb1 --- /dev/null +++ b/tests/lib/files/node/hookconnector.php @@ -0,0 +1,176 @@ +<?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\Files\Node; + +use OC\Files\Filesystem; +use OC\Files\Node\Root; +use OC\Files\Storage\Temporary; +use OC\Files\View; +use OCP\Files\Node; +use Test\TestCase; +use Test\Traits\MountProviderTrait; +use Test\Traits\UserTrait; + +class HookConnector extends TestCase { + use UserTrait; + use MountProviderTrait; + + /** + * @var View + */ + private $view; + + /** + * @var Root + */ + private $root; + + /** + * @var string + */ + private $userId; + + public function setUp() { + parent::setUp(); + $this->userId = $this->getUniqueID(); + $this->createUser($this->userId, 'pass'); + $this->registerMount($this->userId, new Temporary(), '/' . $this->userId . '/files/'); + \OC_Util::setupFS($this->userId); + $this->view = new View(); + $this->root = new Root(Filesystem::getMountManager(), $this->view, \OC::$server->getUserManager()->get($this->userId)); + } + + public function tearDown() { + parent::tearDown(); + \OC_Hook::clear('OC_Filesystem'); + \OC_Util::tearDownFS(); + } + + public function viewToNodeProvider() { + return [ + [function () { + Filesystem::file_put_contents('test.txt', 'asd'); + }, 'preWrite'], + [function () { + Filesystem::file_put_contents('test.txt', 'asd'); + }, 'postWrite'], + [function () { + Filesystem::file_put_contents('test.txt', 'asd'); + }, 'preCreate'], + [function () { + Filesystem::file_put_contents('test.txt', 'asd'); + }, 'postCreate'], + [function () { + Filesystem::mkdir('test.txt'); + }, 'preCreate'], + [function () { + Filesystem::mkdir('test.txt'); + }, 'postCreate'], + [function () { + Filesystem::touch('test.txt'); + }, 'preTouch'], + [function () { + Filesystem::touch('test.txt'); + }, 'postTouch'], + [function () { + Filesystem::touch('test.txt'); + }, 'preCreate'], + [function () { + Filesystem::touch('test.txt'); + }, 'postCreate'], + [function () { + Filesystem::file_put_contents('test.txt', 'asd'); + Filesystem::unlink('test.txt'); + }, 'preDelete'], + [function () { + Filesystem::file_put_contents('test.txt', 'asd'); + Filesystem::unlink('test.txt'); + }, 'postDelete'], + [function () { + Filesystem::mkdir('test.txt'); + Filesystem::rmdir('test.txt'); + }, 'preDelete'], + [function () { + Filesystem::mkdir('test.txt'); + Filesystem::rmdir('test.txt'); + }, 'postDelete'], + ]; + } + + /** + * @param callable $operation + * @param string $expectedHook + * @dataProvider viewToNodeProvider + */ + public function testViewToNode(callable $operation, $expectedHook) { + $connector = new \OC\Files\Node\HookConnector($this->root, $this->view); + $connector->viewToNode(); + $hookCalled = false; + /** @var Node $hookNode */ + $hookNode = null; + + $this->root->listen('\OC\Files', $expectedHook, function ($node) use (&$hookNode, &$hookCalled) { + $hookCalled = true; + $hookNode = $node; + }); + + $operation(); + + $this->assertTrue($hookCalled); + $this->assertEquals('/' . $this->userId . '/files/test.txt', $hookNode->getPath()); + } + + public function viewToNodeProviderCopyRename() { + return [ + [function () { + Filesystem::file_put_contents('source', 'asd'); + Filesystem::rename('source', 'target'); + }, 'preRename'], + [function () { + Filesystem::file_put_contents('source', 'asd'); + Filesystem::rename('source', 'target'); + }, 'postRename'], + [function () { + Filesystem::file_put_contents('source', 'asd'); + Filesystem::copy('source', 'target'); + }, 'preCopy'], + [function () { + Filesystem::file_put_contents('source', 'asd'); + Filesystem::copy('source', 'target'); + }, 'postCopy'], + ]; + } + + /** + * @param callable $operation + * @param string $expectedHook + * @dataProvider viewToNodeProviderCopyRename + */ + public function testViewToNodeCopyRename(callable $operation, $expectedHook) { + $connector = new \OC\Files\Node\HookConnector($this->root, $this->view); + $connector->viewToNode(); + $hookCalled = false; + /** @var Node $hookSourceNode */ + $hookSourceNode = null; + /** @var Node $hookTargetNode */ + $hookTargetNode = null; + + $this->root->listen('\OC\Files', $expectedHook, function ($sourceNode, $targetNode) use (&$hookCalled, &$hookSourceNode, &$hookTargetNode) { + $hookCalled = true; + $hookSourceNode = $sourceNode; + $hookTargetNode = $targetNode; + }); + + $operation(); + + $this->assertTrue($hookCalled); + $this->assertEquals('/' . $this->userId . '/files/source', $hookSourceNode->getPath()); + $this->assertEquals('/' . $this->userId . '/files/target', $hookTargetNode->getPath()); + } +} diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php index 2d5ccd1fb85..5580b40a126 100644 --- a/tests/lib/files/node/integration.php +++ b/tests/lib/files/node/integration.php @@ -36,7 +36,7 @@ class IntegrationTests extends \Test\TestCase { \OC_Hook::clear('OC_Filesystem'); - $user = new User($this->getUniqueID('user'), new \OC_User_Dummy); + $user = new User($this->getUniqueID('user'), new \Test\Util\User\Dummy); $this->loginAsUser($user->getUID()); $this->view = new View(); diff --git a/tests/lib/files/node/node.php b/tests/lib/files/node/node.php index 01ed84c4a06..afcf4cbabaa 100644 --- a/tests/lib/files/node/node.php +++ b/tests/lib/files/node/node.php @@ -15,7 +15,7 @@ class Node extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->user = new \OC\User\User('', new \OC_User_Dummy); + $this->user = new \OC\User\User('', new \Test\Util\User\Dummy); } protected function getFileInfo($data) { diff --git a/tests/lib/files/node/root.php b/tests/lib/files/node/root.php index a763428209c..4b1aea1da4e 100644 --- a/tests/lib/files/node/root.php +++ b/tests/lib/files/node/root.php @@ -17,7 +17,7 @@ class Root extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->user = new \OC\User\User('', new \OC_User_Dummy); + $this->user = new \OC\User\User('', new \Test\Util\User\Dummy); } protected function getFileInfo($data) { |