123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770 |
- <?php
- /**
- * Copyright (c) 2013 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\FileInfo;
- use OC\Files\View;
- use OCP\Files\Config\IUserMountCache;
- use OCP\Files\IRootFolder;
- use OCP\Files\Node;
- use OCP\ILogger;
- use OCP\IUserManager;
- use OCP\Files\NotFoundException;
- /**
- * Class NodeTest
- *
- * @package Test\Files\Node
- */
- abstract class NodeTest extends \Test\TestCase {
- /** @var \OC\User\User */
- protected $user;
- /** @var \OC\Files\Mount\Manager */
- protected $manager;
- /** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */
- protected $view;
- /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject */
- protected $root;
- /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */
- protected $userMountCache;
- /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
- protected $logger;
- /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
- protected $userManager;
- protected function setUp() {
- parent::setUp();
- $config = $this->getMockBuilder('\OCP\IConfig')
- ->disableOriginalConstructor()
- ->getMock();
- $urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
- ->disableOriginalConstructor()
- ->getMock();
- $this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlGenerator);
- $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);
- $this->root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
- }
- /**
- * @param IRootFolder $root
- * @param View $view
- * @param string $path
- * @return Node
- */
- protected abstract function createTestNode($root, $view, $path);
- /**
- * @return string
- */
- protected abstract function getNodeClass();
- /**
- * @return string
- */
- protected abstract function getNonExistingNodeClass();
- /**
- * @return string
- */
- protected abstract function getViewDeleteMethod();
- protected function getMockStorage() {
- $storage = $this->getMockBuilder('\OCP\Files\Storage')
- ->disableOriginalConstructor()
- ->getMock();
- $storage->expects($this->any())
- ->method('getId')
- ->will($this->returnValue('home::someuser'));
- return $storage;
- }
- protected function getFileInfo($data) {
- return new FileInfo('', $this->getMockStorage(), '', $data, null);
- }
- public function testDelete() {
- $this->root->expects($this->exactly(2))
- ->method('emit')
- ->will($this->returnValue(true));
- $this->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(['permissions' => \OCP\Constants::PERMISSION_ALL])));
- $this->view->expects($this->once())
- ->method($this->getViewDeleteMethod())
- ->with('/bar/foo')
- ->will($this->returnValue(true));
- $node = $this->createTestNode($this->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($this->getNodeClass(), $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($this->getNonExistingNodeClass(), $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(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain'])));
- $this->view->expects($this->once())
- ->method($this->getViewDeleteMethod())
- ->with('/bar/foo')
- ->will($this->returnValue(true));
- $this->view->expects($this->any())
- ->method('resolvePath')
- ->with('/bar/foo')
- ->will($this->returnValue([null, 'foo']));
- $node = $this->createTestNode($root, $this->view, '/bar/foo');
- $node->delete();
- $this->assertEquals(2, $hooksRun);
- }
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testDeleteNotPermitted() {
- $this->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(['permissions' => \OCP\Constants::PERMISSION_READ])));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $node->delete();
- }
- public function testStat() {
- $this->root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- $stat = array(
- 'fileid' => 1,
- 'size' => 100,
- 'etag' => 'qwerty',
- 'mtime' => 50,
- 'permissions' => 0
- );
- $this->view->expects($this->once())
- ->method('stat')
- ->with('/bar/foo')
- ->will($this->returnValue($stat));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $this->assertEquals($stat, $node->stat());
- }
- public function testGetId() {
- $this->root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- $stat = $this->getFileInfo(array(
- 'fileid' => 1,
- 'size' => 100,
- 'etag' => 'qwerty',
- 'mtime' => 50
- ));
- $this->view->expects($this->once())
- ->method('getFileInfo')
- ->with('/bar/foo')
- ->will($this->returnValue($stat));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $this->assertEquals(1, $node->getId());
- }
- public function testGetSize() {
- $this->root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- $stat = $this->getFileInfo(array(
- 'fileid' => 1,
- 'size' => 100,
- 'etag' => 'qwerty',
- 'mtime' => 50
- ));
- $this->view->expects($this->once())
- ->method('getFileInfo')
- ->with('/bar/foo')
- ->will($this->returnValue($stat));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $this->assertEquals(100, $node->getSize());
- }
- public function testGetEtag() {
- $this->root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- $stat = $this->getFileInfo(array(
- 'fileid' => 1,
- 'size' => 100,
- 'etag' => 'qwerty',
- 'mtime' => 50
- ));
- $this->view->expects($this->once())
- ->method('getFileInfo')
- ->with('/bar/foo')
- ->will($this->returnValue($stat));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $this->assertEquals('qwerty', $node->getEtag());
- }
- public function testGetMTime() {
- $this->root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- $stat = $this->getFileInfo(array(
- 'fileid' => 1,
- 'size' => 100,
- 'etag' => 'qwerty',
- 'mtime' => 50
- ));
- $this->view->expects($this->once())
- ->method('getFileInfo')
- ->with('/bar/foo')
- ->will($this->returnValue($stat));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $this->assertEquals(50, $node->getMTime());
- }
- public function testGetStorage() {
- $this->root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- /**
- * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
- */
- $storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
- ->disableOriginalConstructor()
- ->getMock();
- $this->view->expects($this->once())
- ->method('resolvePath')
- ->with('/bar/foo')
- ->will($this->returnValue(array($storage, 'foo')));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $this->assertEquals($storage, $node->getStorage());
- }
- public function testGetPath() {
- $this->root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $this->assertEquals('/bar/foo', $node->getPath());
- }
- public function testGetInternalPath() {
- $this->root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- /**
- * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
- */
- $storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
- ->disableOriginalConstructor()
- ->getMock();
- $this->view->expects($this->once())
- ->method('resolvePath')
- ->with('/bar/foo')
- ->will($this->returnValue(array($storage, 'foo')));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $this->assertEquals('foo', $node->getInternalPath());
- }
- public function testGetName() {
- $this->root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $this->assertEquals('foo', $node->getName());
- }
- public function testTouchSetMTime() {
- $this->root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- $this->view->expects($this->once())
- ->method('touch')
- ->with('/bar/foo', 100)
- ->will($this->returnValue(true));
- $this->view->expects($this->once())
- ->method('getFileInfo')
- ->with('/bar/foo')
- ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
- $node = $this->createTestNode($this->root, $this->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++;
- };
- $root = new \OC\Files\Node\Root(
- $this->manager,
- $this->view,
- $this->user,
- $this->userMountCache,
- $this->logger,
- $this->userManager
- );
- $root->listen('\OC\Files', 'preTouch', $preListener);
- $root->listen('\OC\Files', 'postTouch', $postListener);
- $this->view->expects($this->once())
- ->method('touch')
- ->with('/bar/foo', 100)
- ->will($this->returnValue(true));
- $this->view->expects($this->any())
- ->method('resolvePath')
- ->with('/bar/foo')
- ->will($this->returnValue(array(null, 'foo')));
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->with('/bar/foo')
- ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
- $node = $this->createTestNode($root, $this->view, '/bar/foo');
- $node->touch(100);
- $this->assertEquals(2, $hooksRun);
- }
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testTouchNotPermitted() {
- $this->root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->with('/bar/foo')
- ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $node->touch(100);
- }
- /**
- * @expectedException \OCP\Files\InvalidPathException
- */
- public function testInvalidPath() {
- $node = $this->createTestNode($this->root, $this->view, '/../foo');
- $node->getFileInfo();
- }
- public function testCopySameStorage() {
- $this->view->expects($this->any())
- ->method('copy')
- ->with('/bar/foo', '/bar/asd')
- ->will($this->returnValue(true));
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->will($this->returnValue($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 3])));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
- $newNode = $this->createTestNode($this->root, $this->view, '/bar/asd');
- $this->root->expects($this->exactly(2))
- ->method('get')
- ->will($this->returnValueMap([
- ['/bar/asd', $newNode],
- ['/bar', $parentNode]
- ]));
- $target = $node->copy('/bar/asd');
- $this->assertInstanceOf($this->getNodeClass(), $target);
- $this->assertEquals(3, $target->getId());
- }
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testCopyNotPermitted() {
- /**
- * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
- */
- $storage = $this->createMock('\OC\Files\Storage\Storage');
- $this->root->expects($this->never())
- ->method('getMount');
- $storage->expects($this->never())
- ->method('copy');
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->will($this->returnValue($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ, 'fileid' => 3])));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
- $this->root->expects($this->once())
- ->method('get')
- ->will($this->returnValueMap([
- ['/bar', $parentNode]
- ]));
- $node->copy('/bar/asd');
- }
- /**
- * @expectedException \OCP\Files\NotFoundException
- */
- public function testCopyNoParent() {
- $this->view->expects($this->never())
- ->method('copy');
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $this->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() {
- $this->view->expects($this->never())
- ->method('copy');
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\File($this->root, $this->view, '/bar');
- $this->root->expects($this->once())
- ->method('get')
- ->will($this->returnValueMap([
- ['/bar', $parentNode]
- ]));
- $node->copy('/bar/asd');
- }
- public function testMoveSameStorage() {
- $this->view->expects($this->any())
- ->method('rename')
- ->with('/bar/foo', '/bar/asd')
- ->will($this->returnValue(true));
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->will($this->returnValue($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1])));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
- $this->root->expects($this->any())
- ->method('get')
- ->will($this->returnValueMap([['/bar', $parentNode], ['/bar/asd', $node]]));
- $target = $node->move('/bar/asd');
- $this->assertInstanceOf($this->getNodeClass(), $target);
- $this->assertEquals(1, $target->getId());
- $this->assertEquals('/bar/asd', $node->getPath());
- }
- public function moveOrCopyProvider() {
- return [
- ['move', 'rename', 'preRename', 'postRename'],
- ['copy', 'copy', 'preCopy', 'postCopy'],
- ];
- }
- /**
- * @dataProvider moveOrCopyProvider
- * @param string $operationMethod
- * @param string $viewMethod
- * @param string $preHookName
- * @param string $postHookName
- */
- public function testMoveCopyHooks($operationMethod, $viewMethod, $preHookName, $postHookName) {
- /** @var IRootFolder|\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])
- ->setMethods(['get'])
- ->getMock();
- $this->view->expects($this->any())
- ->method($viewMethod)
- ->with('/bar/foo', '/bar/asd')
- ->will($this->returnValue(true));
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->will($this->returnValue($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1])));
- /**
- * @var \OC\Files\Node\File|\PHPUnit_Framework_MockObject_MockObject $node
- */
- $node = $this->createTestNode($root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($root, $this->view, '/bar');
- $targetTestNode = $this->createTestNode($root, $this->view, '/bar/asd');
- $root->expects($this->any())
- ->method('get')
- ->will($this->returnValueMap([['/bar', $parentNode], ['/bar/asd', $targetTestNode]]));
- $hooksRun = 0;
- $preListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node) {
- $this->assertSame($node, $sourceNode);
- $this->assertInstanceOf($this->getNodeClass(), $sourceNode);
- $this->assertInstanceOf($this->getNonExistingNodeClass(), $targetNode);
- $this->assertEquals('/bar/asd', $targetNode->getPath());
- $hooksRun++;
- };
- $postListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node, $targetTestNode) {
- $this->assertSame($node, $sourceNode);
- $this->assertNotSame($node, $targetNode);
- $this->assertSame($targetTestNode, $targetNode);
- $this->assertInstanceOf($this->getNodeClass(), $sourceNode);
- $this->assertInstanceOf($this->getNodeClass(), $targetNode);
- $hooksRun++;
- };
- $preWriteListener = function (Node $targetNode) use (&$hooksRun) {
- $this->assertInstanceOf($this->getNonExistingNodeClass(), $targetNode);
- $this->assertEquals('/bar/asd', $targetNode->getPath());
- $hooksRun++;
- };
- $postWriteListener = function (Node $targetNode) use (&$hooksRun, $targetTestNode) {
- $this->assertSame($targetTestNode, $targetNode);
- $hooksRun++;
- };
- $root->listen('\OC\Files', $preHookName, $preListener);
- $root->listen('\OC\Files', 'preWrite', $preWriteListener);
- $root->listen('\OC\Files', $postHookName, $postListener);
- $root->listen('\OC\Files', 'postWrite', $postWriteListener);
- $node->$operationMethod('/bar/asd');
- $this->assertEquals(4, $hooksRun);
- }
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testMoveNotPermitted() {
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->will($this->returnValue($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ])));
- $this->view->expects($this->never())
- ->method('rename');
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
- $this->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\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
- */
- $storage = $this->createMock('\OC\Files\Storage\Storage');
- $storage->expects($this->never())
- ->method('rename');
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $this->root->expects($this->once())
- ->method('get')
- ->with('/bar')
- ->will($this->throwException(new NotFoundException()));
- $node->move('/bar/asd');
- }
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testMoveParentIsFile() {
- $this->view->expects($this->never())
- ->method('rename');
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\File($this->root, $this->view, '/bar');
- $this->root->expects($this->once())
- ->method('get')
- ->with('/bar')
- ->will($this->returnValue($parentNode));
- $node->move('/bar/asd');
- }
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testMoveFailed() {
- $this->view->expects($this->any())
- ->method('rename')
- ->with('/bar/foo', '/bar/asd')
- ->will($this->returnValue(false));
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->will($this->returnValue($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1])));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
- $this->root->expects($this->any())
- ->method('get')
- ->will($this->returnValueMap([['/bar', $parentNode], ['/bar/asd', $node]]));
- $node->move('/bar/asd');
- }
- /**
- * @expectedException \OCP\Files\NotPermittedException
- */
- public function testCopyFailed() {
- $this->view->expects($this->any())
- ->method('copy')
- ->with('/bar/foo', '/bar/asd')
- ->will($this->returnValue(false));
- $this->view->expects($this->any())
- ->method('getFileInfo')
- ->will($this->returnValue($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1])));
- $node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
- $this->root->expects($this->any())
- ->method('get')
- ->will($this->returnValueMap([['/bar', $parentNode], ['/bar/asd', $node]]));
- $node->copy('/bar/asd');
- }
- }
|