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;
|
|
|
|
|
2014-12-04 15:27:08 +03:00
|
|
|
use OC\Files\FileInfo;
|
2013-09-11 00:21:49 +04:00
|
|
|
use OCP\Files\NotPermittedException;
|
2013-09-01 21:47:48 +04:00
|
|
|
use OC\Files\Mount\Manager;
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
class Root 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();
|
2015-09-22 01:56:36 +03:00
|
|
|
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy);
|
2013-09-01 21:47:48 +04:00
|
|
|
}
|
|
|
|
|
2014-12-04 15:27:08 +03:00
|
|
|
protected function getFileInfo($data) {
|
2014-12-16 16:24:48 +03:00
|
|
|
return new FileInfo('', null, '', $data, null);
|
2014-12-04 15:27:08 +03:00
|
|
|
}
|
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
public function testGet() {
|
|
|
|
$manager = new Manager();
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Storage\Storage $storage
|
|
|
|
*/
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2014-12-04 15:27:08 +03:00
|
|
|
->will($this->returnValue($this->getFileInfo(array('fileid' => 10, 'path' => 'bar/foo', 'name', 'mimetype' => 'text/plain'))));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('is_dir')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('file_exists')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$root->mount($storage, '');
|
|
|
|
$node = $root->get('/bar/foo');
|
|
|
|
$this->assertEquals(10, $node->getId());
|
|
|
|
$this->assertInstanceOf('\OC\Files\Node\File', $node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotFoundException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testGetNotFound() {
|
|
|
|
$manager = new Manager();
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Storage\Storage $storage
|
|
|
|
*/
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('file_exists')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
$root->mount($storage, '');
|
|
|
|
$root->get('/bar/foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testGetInvalidPath() {
|
|
|
|
$manager = new 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->get('/../foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotFoundException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testGetNoStorages() {
|
|
|
|
$manager = new 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->get('/bar/foo');
|
|
|
|
}
|
|
|
|
}
|