2013-09-01 17:47:48 +00: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;
|
|
|
|
|
2014-12-04 12:27:08 +00:00
|
|
|
use OC\Files\FileInfo;
|
2013-09-01 17:47:48 +00:00
|
|
|
|
2016-05-20 13:38:20 +00:00
|
|
|
class RootTest extends \Test\TestCase {
|
2016-07-13 12:35:34 +00:00
|
|
|
/** @var \OC\User\User */
|
2013-09-01 17:47:48 +00:00
|
|
|
private $user;
|
|
|
|
|
2016-07-13 12:35:34 +00:00
|
|
|
/** @var \OC\Files\Mount\Manager */
|
|
|
|
private $manager;
|
|
|
|
|
2014-11-07 14:23:15 +00:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
2016-07-13 12:35:34 +00:00
|
|
|
|
|
|
|
$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();
|
2013-09-01 17:47:48 +00:00
|
|
|
}
|
|
|
|
|
2014-12-04 12:27:08 +00:00
|
|
|
protected function getFileInfo($data) {
|
2014-12-16 13:24:48 +00:00
|
|
|
return new FileInfo('', null, '', $data, null);
|
2014-12-04 12:27:08 +00:00
|
|
|
}
|
|
|
|
|
2013-09-01 17:47:48 +00:00
|
|
|
public function testGet() {
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Storage\Storage $storage
|
|
|
|
*/
|
2016-07-13 12:35:34 +00:00
|
|
|
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2013-09-01 17:47:48 +00:00
|
|
|
/**
|
|
|
|
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
|
|
|
|
*/
|
2016-07-13 12:35:34 +00:00
|
|
|
$view = $this->getMockBuilder('\OC\Files\View')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user);
|
2013-09-01 17:47:48 +00:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-12-04 12:27:08 +00:00
|
|
|
->will($this->returnValue($this->getFileInfo(array('fileid' => 10, 'path' => 'bar/foo', 'name', 'mimetype' => 'text/plain'))));
|
2013-09-01 17:47:48 +00:00
|
|
|
|
|
|
|
$root->mount($storage, '');
|
|
|
|
$node = $root->get('/bar/foo');
|
|
|
|
$this->assertEquals(10, $node->getId());
|
|
|
|
$this->assertInstanceOf('\OC\Files\Node\File', $node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-10 20:21:49 +00:00
|
|
|
* @expectedException \OCP\Files\NotFoundException
|
2013-09-01 17:47:48 +00:00
|
|
|
*/
|
|
|
|
public function testGetNotFound() {
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Storage\Storage $storage
|
|
|
|
*/
|
2016-07-13 12:35:34 +00:00
|
|
|
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2013-09-01 17:47:48 +00:00
|
|
|
/**
|
|
|
|
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
|
|
|
|
*/
|
2016-07-13 12:35:34 +00:00
|
|
|
$view = $this->getMockBuilder('\OC\Files\View')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user);
|
2013-09-01 17:47:48 +00:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
2016-02-18 14:41:10 +00:00
|
|
|
->method('getFileInfo')
|
2013-09-01 17:47:48 +00:00
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
$root->mount($storage, '');
|
|
|
|
$root->get('/bar/foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-10 20:21:49 +00:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 17:47:48 +00:00
|
|
|
*/
|
|
|
|
public function testGetInvalidPath() {
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
|
|
|
|
*/
|
2016-07-13 12:35:34 +00:00
|
|
|
$view = $this->getMockBuilder('\OC\Files\View')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user);
|
2013-09-01 17:47:48 +00:00
|
|
|
|
|
|
|
$root->get('/../foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-10 20:21:49 +00:00
|
|
|
* @expectedException \OCP\Files\NotFoundException
|
2013-09-01 17:47:48 +00:00
|
|
|
*/
|
|
|
|
public function testGetNoStorages() {
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
|
|
|
|
*/
|
2016-07-13 12:35:34 +00:00
|
|
|
$view = $this->getMockBuilder('\OC\Files\View')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$root = new \OC\Files\Node\Root($this->manager, $view, $this->user);
|
2013-09-01 17:47:48 +00:00
|
|
|
|
|
|
|
$root->get('/bar/foo');
|
|
|
|
}
|
|
|
|
}
|