summaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Node/FileTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Node/FileTest.php')
-rw-r--r--tests/lib/Files/Node/FileTest.php384
1 files changed, 16 insertions, 368 deletions
diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php
index 823e3b50249..a17cc1d1a3a 100644
--- a/tests/lib/Files/Node/FileTest.php
+++ b/tests/lib/Files/Node/FileTest.php
@@ -8,161 +8,28 @@
namespace Test\Files\Node;
-use OC\Files\FileInfo;
-use OCP\Files\NotFoundException;
-use OCP\ILogger;
-use OCP\IUserManager;
-
-class FileTest extends \Test\TestCase {
- /** @var \OC\User\User */
- private $user;
- /** @var \OC\Files\Mount\Manager */
- private $manager;
- /** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */
- private $view;
- /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
- private $userMountCache;
- /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
- private $logger;
- /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
- private $userManager;
-
- protected function setUp() {
- parent::setUp();
- $config = $this->getMockBuilder('\OCP\IConfig')
- ->disableOriginalConstructor()
- ->getMock();
- $this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config);
- $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager')
- ->disableOriginalConstructor()
- ->getMock();
- $this->view = $this->getMockBuilder('\OC\Files\View')
- ->disableOriginalConstructor()
- ->getMock();
- $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
- ->disableOriginalConstructor()
- ->getMock();
- $this->logger = $this->createMock(ILogger::class);
- $this->userManager = $this->createMock(IUserManager::class);
- }
-
- protected function getMockStorage() {
- $storage = $this->getMockBuilder('\OCP\Files\Storage')
- ->getMock();
- $storage->expects($this->any())
- ->method('getId')
- ->will($this->returnValue('home::someuser'));
- return $storage;
+/**
+ * Class FileTest
+ *
+ * @group DB
+ *
+ * @package Test\Files\Node
+ */
+class FileTest extends NodeTest {
+ protected function createTestNode($root, $view, $path) {
+ return new \OC\Files\Node\File($root, $view, $path);
}
- protected function getFileInfo($data) {
- return new FileInfo('', $this->getMockStorage(), '', $data, null);
+ protected function getNodeClass() {
+ return '\OC\Files\Node\File';
}
- public function testDelete() {
- /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
-
- $root->expects($this->exactly(2))
- ->method('emit')
- ->will($this->returnValue(true));
- $root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
-
- $this->view->expects($this->once())
- ->method('getFileInfo')
- ->with('/bar/foo')
- ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
-
- $this->view->expects($this->once())
- ->method('unlink')
- ->with('/bar/foo')
- ->will($this->returnValue(true));
-
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
- $node->delete();
- }
-
- public function testDeleteHooks() {
- $test = $this;
- $hooksRun = 0;
- /**
- * @param \OC\Files\Node\File $node
- */
- $preListener = function ($node) use (&$test, &$hooksRun) {
- $test->assertInstanceOf('\OC\Files\Node\File', $node);
- $test->assertEquals('foo', $node->getInternalPath());
- $test->assertEquals('/bar/foo', $node->getPath());
- $test->assertEquals(1, $node->getId());
- $hooksRun++;
- };
-
- /**
- * @param \OC\Files\Node\File $node
- */
- $postListener = function ($node) use (&$test, &$hooksRun) {
- $test->assertInstanceOf('\OC\Files\Node\NonExistingFile', $node);
- $test->assertEquals('foo', $node->getInternalPath());
- $test->assertEquals('/bar/foo', $node->getPath());
- $test->assertEquals(1, $node->getId());
- $test->assertEquals('text/plain', $node->getMimeType());
- $hooksRun++;
- };
-
- $root = new \OC\Files\Node\Root(
- $this->manager,
- $this->view,
- $this->user,
- $this->userMountCache,
- $this->logger,
- $this->userManager
- );
- $root->listen('\OC\Files', 'preDelete', $preListener);
- $root->listen('\OC\Files', 'postDelete', $postListener);
-
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->with('/bar/foo')
- ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain'))));
-
- $this->view->expects($this->once())
- ->method('unlink')
- ->with('/bar/foo')
- ->will($this->returnValue(true));
-
- $this->view->expects($this->any())
- ->method('resolvePath')
- ->with('/bar/foo')
- ->will($this->returnValue(array(null, 'foo')));
-
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
- $node->delete();
- $this->assertEquals(2, $hooksRun);
+ protected function getNonExistingNodeClass() {
+ return '\OC\Files\Node\NonExistingFile';
}
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testDeleteNotPermitted() {
- /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
-
- $root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
-
- $this->view->expects($this->once())
- ->method('getFileInfo')
- ->with('/bar/foo')
- ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
-
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
- $node->delete();
+ protected function getViewDeleteMethod() {
+ return 'unlink';
}
public function testGetContent() {
@@ -421,224 +288,5 @@ class FileTest extends \Test\TestCase {
$node->fopen('w');
}
- public function testCopySameStorage() {
- /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
-
- $this->view->expects($this->any())
- ->method('copy')
- ->with('/bar/foo', '/bar/asd');
-
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 3))));
-
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($root, $this->view, '/bar');
- $newNode = new \OC\Files\Node\File($root, $this->view, '/bar/asd');
-
- $root->expects($this->exactly(2))
- ->method('get')
- ->will($this->returnValueMap(array(
- array('/bar/asd', $newNode),
- array('/bar', $parentNode)
- )));
-
- $target = $node->copy('/bar/asd');
- $this->assertInstanceOf('\OC\Files\Node\File', $target);
- $this->assertEquals(3, $target->getId());
- }
-
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testCopyNotPermitted() {
- /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
-
- /**
- * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
- */
- $storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
- ->disableOriginalConstructor()
- ->getMock();
-
- $root->expects($this->never())
- ->method('getMount');
-
- $storage->expects($this->never())
- ->method('copy');
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ, 'fileid' => 3))));
-
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($root, $this->view, '/bar');
-
- $root->expects($this->once())
- ->method('get')
- ->will($this->returnValueMap(array(
- array('/bar', $parentNode)
- )));
-
- $node->copy('/bar/asd');
- }
-
- /**
- * @expectedException \OCP\Files\NotFoundException
- */
- public function testCopyNoParent() {
- /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
-
- $this->view->expects($this->never())
- ->method('copy');
-
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
-
- $root->expects($this->once())
- ->method('get')
- ->with('/bar/asd')
- ->will($this->throwException(new NotFoundException()));
-
- $node->copy('/bar/asd/foo');
- }
-
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testCopyParentIsFile() {
- /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
-
- $this->view->expects($this->never())
- ->method('copy');
-
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\File($root, $this->view, '/bar');
-
- $root->expects($this->once())
- ->method('get')
- ->will($this->returnValueMap(array(
- array('/bar', $parentNode)
- )));
-
- $node->copy('/bar/asd');
- }
-
- public function testMoveSameStorage() {
- /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
-
- $this->view->expects($this->any())
- ->method('rename')
- ->with('/bar/foo', '/bar/asd');
-
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
-
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($root, $this->view, '/bar');
-
- $root->expects($this->any())
- ->method('get')
- ->will($this->returnValueMap(array(array('/bar', $parentNode), array('/bar/asd', $node))));
-
- $target = $node->move('/bar/asd');
- $this->assertInstanceOf('\OC\Files\Node\File', $target);
- $this->assertEquals(1, $target->getId());
- $this->assertEquals('/bar/asd', $node->getPath());
- }
-
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testMoveNotPermitted() {
- /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
-
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
-
- $this->view->expects($this->never())
- ->method('rename');
-
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($root, $this->view, '/bar');
-
- $root->expects($this->once())
- ->method('get')
- ->with('/bar')
- ->will($this->returnValue($parentNode));
-
- $node->move('/bar/asd');
- }
-
- /**
- * @expectedException \OCP\Files\NotFoundException
- */
- public function testMoveNoParent() {
- /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
-
- /**
- * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
- */
- $storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
- ->disableOriginalConstructor()
- ->getMock();
-
- $storage->expects($this->never())
- ->method('rename');
-
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($root, $this->view, '/bar');
-
- $root->expects($this->once())
- ->method('get')
- ->with('/bar')
- ->will($this->throwException(new NotFoundException()));
-
- $node->move('/bar/asd');
- }
-
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testMoveParentIsFile() {
- /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
-
- $this->view->expects($this->never())
- ->method('rename');
-
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\File($root, $this->view, '/bar');
-
- $root->expects($this->once())
- ->method('get')
- ->with('/bar')
- ->will($this->returnValue($parentNode));
-
- $node->move('/bar/asd');
- }
}