2013-09-01 21:47:48 +04:00
|
|
|
<?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;
|
|
|
|
|
2013-09-11 00:21:49 +04:00
|
|
|
use OCP\Files\NotFoundException;
|
|
|
|
use OCP\Files\NotPermittedException;
|
2013-09-01 21:47:48 +04:00
|
|
|
use OC\Files\View;
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
class File extends \Test\TestCase {
|
2013-09-01 21:47:48 +04:00
|
|
|
private $user;
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
2013-09-01 21:47:48 +04:00
|
|
|
$this->user = new \OC\User\User('', new \OC_User_Dummy);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDelete() {
|
|
|
|
$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->exactly(2))
|
|
|
|
->method('emit')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
|
|
|
->will($this->returnValue($this->user));
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('unlink')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $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());
|
|
|
|
$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', 'preDelete', $preListener);
|
|
|
|
$root->listen('\OC\Files', 'postDelete', $postListener);
|
|
|
|
|
|
|
|
$view->expects($this->any())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('unlink')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$view->expects($this->any())
|
|
|
|
->method('resolvePath')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(array(null, 'foo')));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$node->delete();
|
|
|
|
$this->assertEquals(2, $hooksRun);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testDeleteNotPermitted() {
|
|
|
|
$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('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$node->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetContent() {
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
$hook = function ($file) {
|
|
|
|
throw new \Exception('Hooks are not supposed to be called');
|
|
|
|
};
|
|
|
|
|
|
|
|
$root->listen('\OC\Files', 'preWrite', $hook);
|
|
|
|
$root->listen('\OC\Files', 'postWrite', $hook);
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('file_get_contents')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue('bar'));
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$this->assertEquals('bar', $node->getContent());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testGetContentNotPermitted() {
|
|
|
|
$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('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(array('permissions' => 0)));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$node->getContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPutContent() {
|
|
|
|
$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('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('file_put_contents')
|
|
|
|
->with('/bar/foo', 'bar')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$node->putContent('bar');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testPutContentNotPermitted() {
|
|
|
|
$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));
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$node->putContent('bar');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMimeType() {
|
|
|
|
$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));
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getMimeType')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue('text/plain'));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$this->assertEquals('text/plain', $node->getMimeType());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFOpenRead() {
|
|
|
|
$stream = fopen('php://memory', 'w+');
|
|
|
|
fwrite($stream, 'bar');
|
|
|
|
rewind($stream);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
$hook = function ($file) {
|
|
|
|
throw new \Exception('Hooks are not supposed to be called');
|
|
|
|
};
|
|
|
|
|
|
|
|
$root->listen('\OC\Files', 'preWrite', $hook);
|
|
|
|
$root->listen('\OC\Files', 'postWrite', $hook);
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('fopen')
|
|
|
|
->with('/bar/foo', 'r')
|
|
|
|
->will($this->returnValue($stream));
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$fh = $node->fopen('r');
|
|
|
|
$this->assertEquals($stream, $fh);
|
|
|
|
$this->assertEquals('bar', fread($fh, 3));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFOpenWrite() {
|
|
|
|
$stream = fopen('php://memory', 'w+');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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, new $view, $this->user);
|
|
|
|
|
|
|
|
$hooksCalled = 0;
|
|
|
|
$hook = function ($file) use (&$hooksCalled) {
|
|
|
|
$hooksCalled++;
|
|
|
|
};
|
|
|
|
|
|
|
|
$root->listen('\OC\Files', 'preWrite', $hook);
|
|
|
|
$root->listen('\OC\Files', 'postWrite', $hook);
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('fopen')
|
|
|
|
->with('/bar/foo', 'w')
|
|
|
|
->will($this->returnValue($stream));
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$fh = $node->fopen('w');
|
|
|
|
$this->assertEquals($stream, $fh);
|
|
|
|
fwrite($fh, 'bar');
|
|
|
|
rewind($fh);
|
|
|
|
$this->assertEquals('bar', fread($stream, 3));
|
|
|
|
$this->assertEquals(2, $hooksCalled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testFOpenReadNotPermitted() {
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
$hook = function ($file) {
|
|
|
|
throw new \Exception('Hooks are not supposed to be called');
|
|
|
|
};
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(array('permissions' => 0)));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$node->fopen('r');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testFOpenReadWriteNoReadPermissions() {
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
$hook = function () {
|
|
|
|
throw new \Exception('Hooks are not supposed to be called');
|
|
|
|
};
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_UPDATE)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$node->fopen('w');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testFOpenReadWriteNoWritePermissions() {
|
|
|
|
/**
|
|
|
|
* @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, new $view, $this->user);
|
|
|
|
|
|
|
|
$hook = function () {
|
|
|
|
throw new \Exception('Hooks are not supposed to be called');
|
|
|
|
};
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$node->fopen('w');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCopySameStorage() {
|
|
|
|
/**
|
|
|
|
* @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 = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
|
|
|
|
|
|
|
|
$view->expects($this->any())
|
|
|
|
->method('copy')
|
|
|
|
->with('/bar/foo', '/bar/asd');
|
|
|
|
|
|
|
|
$view->expects($this->any())
|
|
|
|
->method('getFileInfo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 3)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
|
|
|
|
$newNode = new \OC\Files\Node\File($root, $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());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testCopyNotPermitted() {
|
|
|
|
/**
|
|
|
|
* @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 = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
|
|
|
|
*/
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
|
|
|
|
|
|
|
$root->expects($this->never())
|
|
|
|
->method('getMount');
|
|
|
|
|
|
|
|
$storage->expects($this->never())
|
|
|
|
->method('copy');
|
|
|
|
|
|
|
|
$view->expects($this->any())
|
|
|
|
->method('getFileInfo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ, 'fileid' => 3)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->will($this->returnValueMap(array(
|
|
|
|
array('/bar', $parentNode)
|
|
|
|
)));
|
|
|
|
|
|
|
|
$node->copy('/bar/asd');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotFoundException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testCopyNoParent() {
|
|
|
|
/**
|
|
|
|
* @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 = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
|
|
|
|
|
|
|
|
$view->expects($this->never())
|
|
|
|
->method('copy');
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('/bar/asd')
|
|
|
|
->will($this->throwException(new NotFoundException()));
|
|
|
|
|
|
|
|
$node->copy('/bar/asd/foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testCopyParentIsFile() {
|
|
|
|
/**
|
|
|
|
* @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 = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
|
|
|
|
|
|
|
|
$view->expects($this->never())
|
|
|
|
->method('copy');
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$parentNode = new \OC\Files\Node\File($root, $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\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 = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
|
|
|
|
|
|
|
|
$view->expects($this->any())
|
|
|
|
->method('rename')
|
|
|
|
->with('/bar/foo', '/bar/asd');
|
|
|
|
|
|
|
|
$view->expects($this->any())
|
|
|
|
->method('getFileInfo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$parentNode = new \OC\Files\Node\Folder($root, $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());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testMoveNotPermitted() {
|
|
|
|
/**
|
|
|
|
* @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 = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
|
|
|
|
|
|
|
|
$view->expects($this->any())
|
|
|
|
->method('getFileInfo')
|
2014-11-25 18:28:41 +03:00
|
|
|
->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->never())
|
|
|
|
->method('rename');
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('/bar')
|
|
|
|
->will($this->returnValue($parentNode));
|
|
|
|
|
|
|
|
$node->move('/bar/asd');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotFoundException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testMoveNoParent() {
|
|
|
|
/**
|
|
|
|
* @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 = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
|
|
|
|
*/
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
|
|
|
|
|
|
|
$storage->expects($this->never())
|
|
|
|
->method('rename');
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('/bar')
|
|
|
|
->will($this->throwException(new NotFoundException()));
|
|
|
|
|
|
|
|
$node->move('/bar/asd');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testMoveParentIsFile() {
|
|
|
|
/**
|
|
|
|
* @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 = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
|
|
|
|
|
|
|
|
$view->expects($this->never())
|
|
|
|
->method('rename');
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
|
|
|
|
$parentNode = new \OC\Files\Node\File($root, $view, '/bar');
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('/bar')
|
|
|
|
->will($this->returnValue($parentNode));
|
|
|
|
|
|
|
|
$node->move('/bar/asd');
|
|
|
|
}
|
|
|
|
}
|