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;
|
|
|
|
|
|
|
|
use OC\Files\Cache\Cache;
|
2014-12-04 15:27:08 +03:00
|
|
|
use OC\Files\FileInfo;
|
2014-11-24 17:54:42 +03:00
|
|
|
use OC\Files\Mount\MountPoint;
|
2013-09-01 21:47:48 +04:00
|
|
|
use OC\Files\Node\Node;
|
2016-07-22 15:37:37 +03:00
|
|
|
use OC\Files\Storage\Temporary;
|
|
|
|
use OC\Files\Storage\Wrapper\Jail;
|
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;
|
|
|
|
|
2015-11-20 13:27:11 +03:00
|
|
|
/**
|
2016-05-20 16:38:20 +03:00
|
|
|
* Class FolderTest
|
2015-11-20 13:27:11 +03:00
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package Test\Files\Node
|
|
|
|
*/
|
2016-05-20 16:38:20 +03:00
|
|
|
class FolderTest 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
|
|
|
}
|
|
|
|
|
2015-12-08 18:33:39 +03:00
|
|
|
protected function getMockStorage() {
|
|
|
|
$storage = $this->getMock('\OCP\Files\Storage');
|
|
|
|
$storage->expects($this->any())
|
|
|
|
->method('getId')
|
|
|
|
->will($this->returnValue('home::someuser'));
|
|
|
|
return $storage;
|
|
|
|
}
|
|
|
|
|
2014-12-04 15:27:08 +03:00
|
|
|
protected function getFileInfo($data) {
|
2015-12-08 18:33:39 +03:00
|
|
|
return new FileInfo('', $this->getMockStorage(), '', $data, null);
|
2014-12-04 15:27:08 +03:00
|
|
|
}
|
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
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->any())
|
|
|
|
->method('getUser')
|
|
|
|
->will($this->returnValue($this->user));
|
|
|
|
$root->expects($this->exactly(2))
|
|
|
|
->method('emit')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$view->expects($this->any())
|
|
|
|
->method('getFileInfo')
|
2014-12-04 15:27:08 +03:00
|
|
|
->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('rmdir')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($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\Folder', $node);
|
|
|
|
$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->assertInstanceOf('\OC\Files\Node\NonExistingFolder', $node);
|
|
|
|
$test->assertEquals('foo', $node->getInternalPath());
|
|
|
|
$test->assertEquals('/bar/foo', $node->getPath());
|
2015-12-01 15:22:58 +03:00
|
|
|
$test->assertEquals(1, $node->getId());
|
2013-09-01 21:47:48 +04:00
|
|
|
$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')
|
2014-12-04 15:27:08 +03:00
|
|
|
->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('rmdir')
|
|
|
|
->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\Folder($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-12-04 15:27:08 +03:00
|
|
|
->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$node->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDirectoryContent() {
|
|
|
|
$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->any())
|
2015-09-08 23:38:50 +03:00
|
|
|
->method('getDirectoryContent')
|
2013-09-01 21:47:48 +04:00
|
|
|
->with('/bar/foo')
|
2015-09-08 23:38:50 +03:00
|
|
|
->will($this->returnValue(array(
|
|
|
|
new FileInfo('/bar/foo/asd', null, 'foo/asd', ['fileid' => 2, 'path' => '/bar/foo/asd', 'name' => 'asd', 'size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain'], null),
|
|
|
|
new FileInfo('/bar/foo/qwerty', null, 'foo/qwerty', ['fileid' => 3, 'path' => '/bar/foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'httpd/unix-directory'], null)
|
|
|
|
)));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$children = $node->getDirectoryListing();
|
|
|
|
$this->assertEquals(2, count($children));
|
|
|
|
$this->assertInstanceOf('\OC\Files\Node\File', $children[0]);
|
|
|
|
$this->assertInstanceOf('\OC\Files\Node\Folder', $children[1]);
|
|
|
|
$this->assertEquals('asd', $children[0]->getName());
|
|
|
|
$this->assertEquals('qwerty', $children[1]->getName());
|
2015-09-08 23:38:50 +03:00
|
|
|
$this->assertEquals(2, $children[0]->getId());
|
|
|
|
$this->assertEquals(3, $children[1]->getId());
|
2013-09-01 21:47:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGet() {
|
|
|
|
$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));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('/bar/foo/asd');
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$node->get('asd');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNodeExists() {
|
|
|
|
$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));
|
|
|
|
|
|
|
|
$child = new \OC\Files\Node\Folder($root, $view, '/bar/foo/asd');
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('/bar/foo/asd')
|
|
|
|
->will($this->returnValue($child));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$this->assertTrue($node->nodeExists('asd'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNodeExistsNotExists() {
|
|
|
|
$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));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('/bar/foo/asd')
|
|
|
|
->will($this->throwException(new NotFoundException()));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$this->assertFalse($node->nodeExists('asd'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNewFolder() {
|
|
|
|
$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-12-04 15:27:08 +03:00
|
|
|
->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('mkdir')
|
|
|
|
->with('/bar/foo/asd')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$child = new \OC\Files\Node\Folder($root, $view, '/bar/foo/asd');
|
|
|
|
$result = $node->newFolder('asd');
|
|
|
|
$this->assertEquals($child, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testNewFolderNotPermitted() {
|
|
|
|
$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-12-04 15:27:08 +03:00
|
|
|
->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$node->newFolder('asd');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNewFile() {
|
|
|
|
$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-12-04 15:27:08 +03:00
|
|
|
->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('touch')
|
|
|
|
->with('/bar/foo/asd')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$child = new \OC\Files\Node\File($root, $view, '/bar/foo/asd');
|
|
|
|
$result = $node->newFile('asd');
|
|
|
|
$this->assertEquals($child, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-11 00:21:49 +04:00
|
|
|
* @expectedException \OCP\Files\NotPermittedException
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
|
|
|
public function testNewFileNotPermitted() {
|
|
|
|
$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-12-04 15:27:08 +03:00
|
|
|
->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$node->newFile('asd');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetFreeSpace() {
|
|
|
|
$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('free_space')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(100));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$this->assertEquals(100, $node->getFreeSpace());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSearch() {
|
|
|
|
$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));
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
|
|
|
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
|
|
|
|
|
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
|
|
|
->will($this->returnValue($cache));
|
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
|
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getStorage')
|
|
|
|
->will($this->returnValue($storage));
|
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getInternalPath')
|
|
|
|
->will($this->returnValue('foo'));
|
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('%qw%')
|
|
|
|
->will($this->returnValue(array(
|
|
|
|
array('fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain')
|
|
|
|
)));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue($mount));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$result = $node->search('qw');
|
|
|
|
$this->assertEquals(1, count($result));
|
|
|
|
$this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
|
|
|
|
}
|
|
|
|
|
2015-01-12 21:33:00 +03:00
|
|
|
public function testSearchInRoot() {
|
|
|
|
$manager = $this->getMock('\OC\Files\Mount\Manager');
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
|
|
|
|
*/
|
|
|
|
$view = $this->getMock('\OC\Files\View');
|
2016-03-21 16:20:33 +03:00
|
|
|
$root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
|
2015-01-12 21:33:00 +03:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
|
|
|
->will($this->returnValue($this->user));
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
|
|
|
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
|
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
|
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getStorage')
|
|
|
|
->will($this->returnValue($storage));
|
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getInternalPath')
|
|
|
|
->will($this->returnValue('files'));
|
|
|
|
|
2015-01-12 21:33:00 +03:00
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
|
|
|
->will($this->returnValue($cache));
|
|
|
|
|
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('%qw%')
|
|
|
|
->will($this->returnValue(array(
|
|
|
|
array('fileid' => 3, 'path' => 'files/foo', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'),
|
|
|
|
array('fileid' => 3, 'path' => 'files_trashbin/foo2.d12345', 'name' => 'foo2.d12345', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'),
|
|
|
|
)));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('')
|
|
|
|
->will($this->returnValue($mount));
|
2015-01-12 21:33:00 +03:00
|
|
|
|
|
|
|
$result = $root->search('qw');
|
|
|
|
$this->assertEquals(1, count($result));
|
|
|
|
$this->assertEquals('/foo', $result[0]->getPath());
|
|
|
|
}
|
|
|
|
|
2015-10-06 16:02:33 +03:00
|
|
|
public function testSearchInStorageRoot() {
|
|
|
|
$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));
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
|
|
|
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
|
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
|
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getStorage')
|
|
|
|
->will($this->returnValue($storage));
|
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getInternalPath')
|
|
|
|
->will($this->returnValue(''));
|
|
|
|
|
2015-10-06 16:02:33 +03:00
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
|
|
|
->will($this->returnValue($cache));
|
|
|
|
|
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('%qw%')
|
|
|
|
->will($this->returnValue(array(
|
|
|
|
array('fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain')
|
|
|
|
)));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar')
|
|
|
|
->will($this->returnValue($mount));
|
2015-10-06 16:02:33 +03:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar');
|
|
|
|
$result = $node->search('qw');
|
|
|
|
$this->assertEquals(1, count($result));
|
|
|
|
$this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
|
|
|
|
}
|
|
|
|
|
2014-12-12 13:18:35 +03:00
|
|
|
public function testSearchByTag() {
|
|
|
|
$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));
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
|
|
|
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
|
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
|
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getStorage')
|
|
|
|
->will($this->returnValue($storage));
|
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getInternalPath')
|
|
|
|
->will($this->returnValue('foo'));
|
|
|
|
|
2014-12-12 13:18:35 +03:00
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
|
|
|
->will($this->returnValue($cache));
|
|
|
|
|
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('searchByTag')
|
|
|
|
->with('tag1', 'user1')
|
|
|
|
->will($this->returnValue(array(
|
|
|
|
array('fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain')
|
|
|
|
)));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue($mount));
|
2014-12-12 13:18:35 +03:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$result = $node->searchByTag('tag1', 'user1');
|
|
|
|
$this->assertEquals(1, count($result));
|
|
|
|
$this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
|
|
|
|
}
|
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
public function testSearchSubStorages() {
|
|
|
|
$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));
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
|
|
|
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
|
|
|
|
$subCache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
|
|
|
|
$subStorage = $this->getMock('\OC\Files\Storage\Storage');
|
2014-11-24 17:54:42 +03:00
|
|
|
$subMount = $this->getMock('\OC\Files\Mount\MountPoint', array(), array(null, ''));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
|
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getStorage')
|
|
|
|
->will($this->returnValue($storage));
|
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getInternalPath')
|
|
|
|
->will($this->returnValue('foo'));
|
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
$subMount->expects($this->once())
|
|
|
|
->method('getStorage')
|
|
|
|
->will($this->returnValue($subStorage));
|
|
|
|
|
|
|
|
$subMount->expects($this->once())
|
|
|
|
->method('getMountPoint')
|
|
|
|
->will($this->returnValue('/bar/foo/bar/'));
|
|
|
|
|
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
|
|
|
->will($this->returnValue($cache));
|
|
|
|
|
|
|
|
$subStorage->expects($this->once())
|
|
|
|
->method('getCache')
|
|
|
|
->will($this->returnValue($subCache));
|
|
|
|
|
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('%qw%')
|
|
|
|
->will($this->returnValue(array(
|
|
|
|
array('fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain')
|
|
|
|
)));
|
|
|
|
|
|
|
|
$subCache->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('%qw%')
|
|
|
|
->will($this->returnValue(array(
|
|
|
|
array('fileid' => 4, 'path' => 'asd/qweasd', 'name' => 'qweasd', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain')
|
|
|
|
)));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(array($subMount)));
|
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue($mount));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$result = $node->search('qw');
|
|
|
|
$this->assertEquals(2, count($result));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsSubNode() {
|
|
|
|
$file = new Node(null, null, '/foo/bar');
|
|
|
|
$folder = new \OC\Files\Node\Folder(null, null, '/foo');
|
|
|
|
$this->assertTrue($folder->isSubNode($file));
|
|
|
|
$this->assertFalse($folder->isSubNode($folder));
|
|
|
|
|
|
|
|
$file = new Node(null, null, '/foobar');
|
|
|
|
$this->assertFalse($folder->isSubNode($file));
|
|
|
|
}
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
public function testGetById() {
|
|
|
|
$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('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
|
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
|
|
|
->will($this->returnValue($this->user));
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
2014-11-24 17:54:42 +03:00
|
|
|
$mount = new MountPoint($storage, '/bar');
|
2014-08-05 18:58:10 +04:00
|
|
|
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
2016-02-18 17:41:10 +03:00
|
|
|
->method('getFileInfo')
|
2016-03-21 16:20:33 +03:00
|
|
|
->will($this->returnValue(new FileInfo('/bar/foo/qwerty', null, 'qwerty', ['mimetype' => 'text/plain'], null)));
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
|
|
|
->will($this->returnValue($cache));
|
|
|
|
|
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('getPathById')
|
|
|
|
->with('1')
|
|
|
|
->will($this->returnValue('foo/qwerty'));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue($mount));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$result = $node->getById(1);
|
|
|
|
$this->assertEquals(1, count($result));
|
|
|
|
$this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetByIdOutsideFolder() {
|
|
|
|
$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('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
|
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
|
|
|
->will($this->returnValue($this->user));
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
2014-11-24 17:54:42 +03:00
|
|
|
$mount = new MountPoint($storage, '/bar');
|
2014-08-05 18:58:10 +04:00
|
|
|
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
|
|
|
|
|
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
|
|
|
->will($this->returnValue($cache));
|
|
|
|
|
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('getPathById')
|
|
|
|
->with('1')
|
|
|
|
->will($this->returnValue('foobar'));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue($mount));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
2014-08-06 14:06:41 +04:00
|
|
|
$result = $node->getById(1);
|
|
|
|
$this->assertCount(0, $result);
|
2014-08-05 18:58:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetByIdMultipleStorages() {
|
|
|
|
$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('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
|
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
|
|
|
->will($this->returnValue($this->user));
|
|
|
|
$storage = $this->getMock('\OC\Files\Storage\Storage');
|
2014-11-24 17:54:42 +03:00
|
|
|
$mount1 = new MountPoint($storage, '/bar');
|
|
|
|
$mount2 = new MountPoint($storage, '/bar/foo/asd');
|
2014-08-05 18:58:10 +04:00
|
|
|
$cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
|
|
|
|
|
|
|
|
$view->expects($this->any())
|
2016-02-18 17:41:10 +03:00
|
|
|
->method('getFileInfo')
|
2016-03-21 16:20:33 +03:00
|
|
|
->will($this->returnValue(new FileInfo('/bar/foo/qwerty', null, 'qwerty', ['mimetype' => 'plain'], null)));
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$storage->expects($this->any())
|
|
|
|
->method('getCache')
|
|
|
|
->will($this->returnValue($cache));
|
|
|
|
|
|
|
|
$cache->expects($this->any())
|
|
|
|
->method('getPathById')
|
|
|
|
->with('1')
|
|
|
|
->will($this->returnValue('foo/qwerty'));
|
|
|
|
|
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue(array($mount2)));
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar/foo')
|
|
|
|
->will($this->returnValue($mount1));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$result = $node->getById(1);
|
|
|
|
$this->assertEquals(2, count($result));
|
|
|
|
$this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
|
|
|
|
$this->assertEquals('/bar/foo/asd/foo/qwerty', $result[1]->getPath());
|
|
|
|
}
|
2015-03-24 17:00:36 +03:00
|
|
|
|
|
|
|
public function uniqueNameProvider() {
|
|
|
|
return [
|
|
|
|
// input, existing, expected
|
2016-07-22 15:37:37 +03:00
|
|
|
['foo', [], 'foo'],
|
|
|
|
['foo', ['foo'], 'foo (2)'],
|
|
|
|
['foo', ['foo', 'foo (2)'], 'foo (3)']
|
2015-03-24 17:00:36 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider uniqueNameProvider
|
|
|
|
*/
|
|
|
|
public function testGetUniqueName($name, $existingFiles, $expected) {
|
|
|
|
$manager = $this->getMock('\OC\Files\Mount\Manager');
|
|
|
|
$folderPath = '/bar/foo';
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
|
|
|
|
*/
|
|
|
|
$view = $this->getMock('\OC\Files\View');
|
|
|
|
$root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
|
|
|
|
|
|
|
|
$view->expects($this->any())
|
|
|
|
->method('file_exists')
|
|
|
|
->will($this->returnCallback(function ($path) use ($existingFiles, $folderPath) {
|
|
|
|
foreach ($existingFiles as $existing) {
|
2016-07-22 15:37:37 +03:00
|
|
|
if ($folderPath . '/' . $existing === $path) {
|
2015-03-24 17:00:36 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, $folderPath);
|
|
|
|
$this->assertEquals($expected, $node->getNonExistingName($name));
|
|
|
|
}
|
2016-07-22 15:37:37 +03:00
|
|
|
|
|
|
|
public function testRecent() {
|
|
|
|
$manager = $this->getMock('\OC\Files\Mount\Manager');
|
|
|
|
$folderPath = '/bar/foo';
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
|
|
|
|
*/
|
|
|
|
$view = $this->getMock('\OC\Files\View');
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
|
|
|
|
$root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
|
|
|
|
$folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
$baseTime = 1000;
|
|
|
|
$storage = new Temporary();
|
|
|
|
$mount = new MountPoint($storage, '');
|
|
|
|
|
|
|
|
$folderInfo->expects($this->any())
|
|
|
|
->method('getMountPoint')
|
|
|
|
->will($this->returnValue($mount));
|
|
|
|
|
|
|
|
$cache = $storage->getCache();
|
|
|
|
|
|
|
|
$id1 = $cache->put('bar/foo/inside.txt', [
|
|
|
|
'storage_mtime' => $baseTime,
|
|
|
|
'mtime' => $baseTime,
|
|
|
|
'mimetype' => 'text/plain',
|
|
|
|
'size' => 3
|
|
|
|
]);
|
|
|
|
$id2 = $cache->put('bar/foo/old.txt', [
|
|
|
|
'storage_mtime' => $baseTime - 100,
|
|
|
|
'mtime' => $baseTime - 100,
|
|
|
|
'mimetype' => 'text/plain',
|
|
|
|
'size' => 3
|
|
|
|
]);
|
|
|
|
$cache->put('bar/asd/outside.txt', [
|
|
|
|
'storage_mtime' => $baseTime,
|
|
|
|
'mtime' => $baseTime,
|
|
|
|
'mimetype' => 'text/plain',
|
|
|
|
'size' => 3
|
|
|
|
]);
|
2016-07-22 14:58:53 +03:00
|
|
|
$id3 = $cache->put('bar/foo/older.txt', [
|
2016-07-22 15:37:37 +03:00
|
|
|
'storage_mtime' => $baseTime - 600,
|
|
|
|
'mtime' => $baseTime - 600,
|
|
|
|
'mimetype' => 'text/plain',
|
|
|
|
'size' => 3
|
|
|
|
]);
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, $folderPath, $folderInfo);
|
|
|
|
|
|
|
|
|
2016-07-22 14:58:53 +03:00
|
|
|
$nodes = $node->getRecent(5);
|
2016-07-22 15:37:37 +03:00
|
|
|
$ids = array_map(function (Node $node) {
|
|
|
|
return (int)$node->getId();
|
|
|
|
}, $nodes);
|
2016-07-22 14:58:53 +03:00
|
|
|
$this->assertEquals([$id1, $id2, $id3], $ids);
|
2016-07-22 15:37:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecentFolder() {
|
|
|
|
$manager = $this->getMock('\OC\Files\Mount\Manager');
|
|
|
|
$folderPath = '/bar/foo';
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
|
|
|
|
*/
|
|
|
|
$view = $this->getMock('\OC\Files\View');
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
|
|
|
|
$root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
|
|
|
|
$folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
$baseTime = 1000;
|
|
|
|
$storage = new Temporary();
|
|
|
|
$mount = new MountPoint($storage, '');
|
|
|
|
|
|
|
|
$folderInfo->expects($this->any())
|
|
|
|
->method('getMountPoint')
|
|
|
|
->will($this->returnValue($mount));
|
|
|
|
|
|
|
|
$cache = $storage->getCache();
|
|
|
|
|
|
|
|
$id1 = $cache->put('bar/foo/folder', [
|
|
|
|
'storage_mtime' => $baseTime,
|
|
|
|
'mtime' => $baseTime,
|
|
|
|
'mimetype' => \OCP\Files\FileInfo::MIMETYPE_FOLDER,
|
|
|
|
'size' => 3
|
|
|
|
]);
|
|
|
|
$id2 = $cache->put('bar/foo/folder/bar.txt', [
|
|
|
|
'storage_mtime' => $baseTime,
|
|
|
|
'mtime' => $baseTime,
|
|
|
|
'mimetype' => 'text/plain',
|
|
|
|
'size' => 3,
|
|
|
|
'parent' => $id1
|
|
|
|
]);
|
|
|
|
$id3 = $cache->put('bar/foo/folder/asd.txt', [
|
2016-07-11 13:58:43 +03:00
|
|
|
'storage_mtime' => $baseTime - 100,
|
2016-07-22 15:37:37 +03:00
|
|
|
'mtime' => $baseTime - 100,
|
|
|
|
'mimetype' => 'text/plain',
|
|
|
|
'size' => 3,
|
|
|
|
'parent' => $id1
|
|
|
|
]);
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, $folderPath, $folderInfo);
|
|
|
|
|
|
|
|
|
2016-07-22 14:58:53 +03:00
|
|
|
$nodes = $node->getRecent(5);
|
2016-07-22 15:37:37 +03:00
|
|
|
$ids = array_map(function (Node $node) {
|
|
|
|
return (int)$node->getId();
|
|
|
|
}, $nodes);
|
2016-07-22 14:58:53 +03:00
|
|
|
$this->assertEquals([$id2, $id3], $ids);
|
2016-07-11 13:58:43 +03:00
|
|
|
$this->assertEquals($baseTime, $nodes[0]->getMTime());
|
|
|
|
$this->assertEquals($baseTime - 100, $nodes[1]->getMTime());
|
2016-07-22 15:37:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecentJail() {
|
|
|
|
$manager = $this->getMock('\OC\Files\Mount\Manager');
|
|
|
|
$folderPath = '/bar/foo';
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
|
|
|
|
*/
|
|
|
|
$view = $this->getMock('\OC\Files\View');
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
|
|
|
|
$root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
|
|
|
|
$folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
$baseTime = 1000;
|
|
|
|
$storage = new Temporary();
|
|
|
|
$jail = new Jail([
|
|
|
|
'storage' => $storage,
|
|
|
|
'root' => 'folder'
|
|
|
|
]);
|
|
|
|
$mount = new MountPoint($jail, '/bar/foo');
|
|
|
|
|
|
|
|
$folderInfo->expects($this->any())
|
|
|
|
->method('getMountPoint')
|
|
|
|
->will($this->returnValue($mount));
|
|
|
|
|
|
|
|
$cache = $storage->getCache();
|
|
|
|
|
|
|
|
$id1 = $cache->put('folder/inside.txt', [
|
|
|
|
'storage_mtime' => $baseTime,
|
|
|
|
'mtime' => $baseTime,
|
|
|
|
'mimetype' => 'text/plain',
|
|
|
|
'size' => 3
|
|
|
|
]);
|
|
|
|
$cache->put('outside.txt', [
|
|
|
|
'storage_mtime' => $baseTime - 100,
|
|
|
|
'mtime' => $baseTime - 100,
|
|
|
|
'mimetype' => 'text/plain',
|
|
|
|
'size' => 3
|
|
|
|
]);
|
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, $folderPath, $folderInfo);
|
|
|
|
|
2016-07-22 14:58:53 +03:00
|
|
|
$nodes = $node->getRecent(5);
|
2016-07-22 15:37:37 +03:00
|
|
|
$ids = array_map(function (Node $node) {
|
|
|
|
return (int)$node->getId();
|
|
|
|
}, $nodes);
|
|
|
|
$this->assertEquals([$id1], $ids);
|
|
|
|
}
|
2013-09-01 21:47:48 +04:00
|
|
|
}
|