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;
|
2016-09-18 19:36:53 +03:00
|
|
|
use OC\Files\Cache\CacheEntry;
|
|
|
|
use OC\Files\Config\CachedMountInfo;
|
2014-12-04 15:27:08 +03:00
|
|
|
use OC\Files\FileInfo;
|
2016-09-12 22:21:42 +03:00
|
|
|
use OC\Files\Mount\Manager;
|
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-09-12 22:21:42 +03:00
|
|
|
use OC\Files\Node\Root;
|
2016-07-22 15:37:37 +03:00
|
|
|
use OC\Files\Storage\Temporary;
|
|
|
|
use OC\Files\Storage\Wrapper\Jail;
|
2016-11-14 20:20:33 +03:00
|
|
|
use OC\Files\View;
|
2016-09-12 22:21:42 +03:00
|
|
|
use OCP\Files\Mount\IMountPoint;
|
2013-09-11 00:21:49 +04:00
|
|
|
use OCP\Files\NotFoundException;
|
2016-09-12 22:21:42 +03:00
|
|
|
use OCP\Files\Storage;
|
2013-09-01 21:47:48 +04:00
|
|
|
|
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-11-14 20:20:33 +03:00
|
|
|
class FolderTest extends NodeTest {
|
|
|
|
protected function createTestNode($root, $view, $path) {
|
|
|
|
return new \OC\Files\Node\Folder($root, $view, $path);
|
2013-09-01 21:47:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-14 20:20:33 +03:00
|
|
|
protected function getNodeClass() {
|
|
|
|
return '\OC\Files\Node\Folder';
|
2015-12-08 18:33:39 +03:00
|
|
|
}
|
|
|
|
|
2016-11-14 20:20:33 +03:00
|
|
|
protected function getNonExistingNodeClass() {
|
|
|
|
return '\OC\Files\Node\NonExistingFolder';
|
2013-09-01 21:47:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-14 20:20:33 +03:00
|
|
|
protected function getViewDeleteMethod() {
|
|
|
|
return 'rmdir';
|
2013-09-01 21:47:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDirectoryContent() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
|
|
|
$root = $this->getMockBuilder(Root::class)
|
2016-11-03 01:16:51 +03:00
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
2016-09-12 22:21:42 +03:00
|
|
|
->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$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')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([
|
2015-09-08 23:38:50 +03:00
|
|
|
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)
|
2020-03-26 11:30:18 +03:00
|
|
|
]);
|
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() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$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() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$child = new \OC\Files\Node\Folder($root, $view, '/bar/foo/asd');
|
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('/bar/foo/asd')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($child);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$this->assertTrue($node->nodeExists('asd'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNodeExistsNotExists() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$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() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('mkdir')
|
|
|
|
->with('/bar/foo/asd')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
public function testNewFolderNotPermitted() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\Files\NotPermittedException::class);
|
|
|
|
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn($this->getFileInfo(['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() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('touch')
|
|
|
|
->with('/bar/foo/asd')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
public function testNewFileNotPermitted() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\Files\NotPermittedException::class);
|
|
|
|
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('getFileInfo')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn($this->getFileInfo(['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() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
->method('free_space')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(100);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
|
|
|
$this->assertEquals(100, $node->getFreeSpace());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSearch() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2016-09-12 22:21:42 +03:00
|
|
|
$storage = $this->createMock(Storage::class);
|
2019-01-22 19:28:57 +03:00
|
|
|
$storage->method('getId')->willReturn('');
|
|
|
|
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($cache);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
2016-09-12 22:21:42 +03:00
|
|
|
$mount = $this->createMock(IMountPoint::class);
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getStorage')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($storage);
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getInternalPath')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('foo');
|
2016-03-21 16:20:33 +03:00
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('%qw%')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([
|
|
|
|
['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
|
|
|
|
]);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([]);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($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() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2015-01-12 21:33:00 +03:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2015-01-12 21:33:00 +03:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setMethods(['getUser', 'getMountsIn', 'getMount'])
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2015-01-12 21:33:00 +03:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|Storage $storage */
|
2016-09-12 22:21:42 +03:00
|
|
|
$storage = $this->createMock(Storage::class);
|
2019-01-22 19:28:57 +03:00
|
|
|
$storage->method('getId')->willReturn('');
|
|
|
|
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
|
2015-01-12 21:33:00 +03:00
|
|
|
|
2016-09-12 22:21:42 +03:00
|
|
|
$mount = $this->createMock(IMountPoint::class);
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getStorage')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($storage);
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getInternalPath')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('files');
|
2016-03-21 16:20:33 +03:00
|
|
|
|
2015-01-12 21:33:00 +03:00
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($cache);
|
2015-01-12 21:33:00 +03:00
|
|
|
|
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('%qw%')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([
|
|
|
|
['fileid' => 3, 'path' => 'files/foo', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'],
|
|
|
|
['fileid' => 3, 'path' => 'files_trashbin/foo2.d12345', 'name' => 'foo2.d12345', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'],
|
|
|
|
]);
|
2015-01-12 21:33:00 +03:00
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([]);
|
2015-01-12 21:33:00 +03:00
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($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() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2015-10-06 16:02:33 +03:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2015-10-06 16:02:33 +03:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2015-10-06 16:02:33 +03:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2016-09-12 22:21:42 +03:00
|
|
|
$storage = $this->createMock(Storage::class);
|
2019-01-22 19:28:57 +03:00
|
|
|
$storage->method('getId')->willReturn('');
|
|
|
|
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
|
2015-10-06 16:02:33 +03:00
|
|
|
|
2016-09-12 22:21:42 +03:00
|
|
|
$mount = $this->createMock(IMountPoint::class);
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getStorage')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($storage);
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getInternalPath')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('');
|
2016-03-21 16:20:33 +03:00
|
|
|
|
2015-10-06 16:02:33 +03:00
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($cache);
|
2015-10-06 16:02:33 +03:00
|
|
|
|
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('%qw%')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([
|
|
|
|
['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
|
|
|
|
]);
|
2015-10-06 16:02:33 +03:00
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([]);
|
2015-10-06 16:02:33 +03:00
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($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());
|
|
|
|
}
|
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
public function testSearchSubStorages() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2013-09-01 21:47:48 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2013-09-01 21:47:48 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($this->user);
|
2016-09-12 22:21:42 +03:00
|
|
|
$storage = $this->createMock(Storage::class);
|
2019-01-22 19:28:57 +03:00
|
|
|
$storage->method('getId')->willReturn('');
|
|
|
|
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
|
|
|
|
$subCache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
|
2016-09-12 22:21:42 +03:00
|
|
|
$subStorage = $this->createMock(Storage::class);
|
|
|
|
$subMount = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([null, ''])->getMock();
|
2013-09-01 21:47:48 +04:00
|
|
|
|
2016-09-12 22:21:42 +03:00
|
|
|
$mount = $this->createMock(IMountPoint::class);
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getStorage')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($storage);
|
2016-03-21 16:20:33 +03:00
|
|
|
$mount->expects($this->once())
|
|
|
|
->method('getInternalPath')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('foo');
|
2016-03-21 16:20:33 +03:00
|
|
|
|
2013-09-01 21:47:48 +04:00
|
|
|
$subMount->expects($this->once())
|
|
|
|
->method('getStorage')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subStorage);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$subMount->expects($this->once())
|
|
|
|
->method('getMountPoint')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('/bar/foo/bar/');
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($cache);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$subStorage->expects($this->once())
|
|
|
|
->method('getCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subCache);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('%qw%')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([
|
|
|
|
['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
|
|
|
|
]);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$subCache->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('%qw%')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([
|
|
|
|
['fileid' => 4, 'path' => 'asd/qweasd', 'name' => 'qweasd', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
|
|
|
|
]);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([$subMount]);
|
2013-09-01 21:47:48 +04:00
|
|
|
|
2016-03-21 16:20:33 +03:00
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($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() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2014-08-05 18:58:10 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2014-08-05 18:58:10 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setMethods(['getMountsIn', 'getMount'])
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2016-09-12 22:21:42 +03:00
|
|
|
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
|
2014-11-24 17:54:42 +03:00
|
|
|
$mount = new MountPoint($storage, '/bar');
|
2019-01-22 19:28:57 +03:00
|
|
|
$storage->method('getId')->willReturn('');
|
|
|
|
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
|
2014-08-05 18:58:10 +04:00
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
$fileInfo = new CacheEntry(['path' => 'foo/qwerty', 'mimetype' => 'text/plain'], null);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($cache);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->userMountCache->expects($this->any())
|
|
|
|
->method('getMountsForFileId')
|
|
|
|
->with(1)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([new CachedMountInfo(
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->user,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
'/bar/',
|
|
|
|
1,
|
|
|
|
''
|
2020-03-26 00:21:27 +03:00
|
|
|
)]);
|
2016-09-18 19:36:53 +03:00
|
|
|
|
2014-08-05 18:58:10 +04:00
|
|
|
$cache->expects($this->once())
|
2016-09-18 19:36:53 +03:00
|
|
|
->method('get')
|
|
|
|
->with(1)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($fileInfo);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([]);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($mount);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$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());
|
|
|
|
}
|
|
|
|
|
2018-11-28 17:18:29 +03:00
|
|
|
public function testGetByIdMountRoot() {
|
|
|
|
$manager = $this->createMock(Manager::class);
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2018-11-28 17:18:29 +03:00
|
|
|
*/
|
|
|
|
$view = $this->createMock(View::class);
|
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setMethods(['getMountsIn', 'getMount'])
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
|
|
|
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
|
|
|
|
$mount = new MountPoint($storage, '/bar');
|
2019-01-22 19:28:57 +03:00
|
|
|
$storage->method('getId')->willReturn('');
|
|
|
|
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
|
2018-11-28 17:18:29 +03:00
|
|
|
|
|
|
|
$fileInfo = new CacheEntry(['path' => '', 'mimetype' => 'text/plain'], null);
|
|
|
|
|
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($cache);
|
2018-11-28 17:18:29 +03:00
|
|
|
|
|
|
|
$this->userMountCache->expects($this->any())
|
|
|
|
->method('getMountsForFileId')
|
|
|
|
->with(1)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([new CachedMountInfo(
|
2018-11-28 17:18:29 +03:00
|
|
|
$this->user,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
'/bar/',
|
|
|
|
1,
|
|
|
|
''
|
2020-03-26 00:21:27 +03:00
|
|
|
)]);
|
2018-11-28 17:18:29 +03:00
|
|
|
|
|
|
|
$cache->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with(1)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($fileInfo);
|
2018-11-28 17:18:29 +03:00
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($mount);
|
2018-11-28 17:18:29 +03:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar');
|
|
|
|
$result = $node->getById(1);
|
|
|
|
$this->assertEquals(1, count($result));
|
|
|
|
$this->assertEquals('/bar', $result[0]->getPath());
|
|
|
|
}
|
|
|
|
|
2014-08-05 18:58:10 +04:00
|
|
|
public function testGetByIdOutsideFolder() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2014-08-05 18:58:10 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2014-08-05 18:58:10 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setMethods(['getMountsIn', 'getMount'])
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2016-09-12 22:21:42 +03:00
|
|
|
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
|
2014-11-24 17:54:42 +03:00
|
|
|
$mount = new MountPoint($storage, '/bar');
|
2019-01-22 19:28:57 +03:00
|
|
|
$storage->method('getId')->willReturn('');
|
|
|
|
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
|
2014-08-05 18:58:10 +04:00
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
$fileInfo = new CacheEntry(['path' => 'foobar', 'mimetype' => 'text/plain'], null);
|
|
|
|
|
2014-08-05 18:58:10 +04:00
|
|
|
$storage->expects($this->once())
|
|
|
|
->method('getCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($cache);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->userMountCache->expects($this->any())
|
|
|
|
->method('getMountsForFileId')
|
|
|
|
->with(1)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([new CachedMountInfo(
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->user,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
'/bar/',
|
|
|
|
1,
|
|
|
|
''
|
2020-03-26 00:21:27 +03:00
|
|
|
)]);
|
2016-09-18 19:36:53 +03:00
|
|
|
|
2014-08-05 18:58:10 +04:00
|
|
|
$cache->expects($this->once())
|
2016-09-18 19:36:53 +03:00
|
|
|
->method('get')
|
|
|
|
->with(1)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($fileInfo);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([]);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($mount);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
|
2014-08-06 14:06:41 +04:00
|
|
|
$result = $node->getById(1);
|
2016-09-18 19:36:53 +03:00
|
|
|
$this->assertEquals(0, count($result));
|
2014-08-05 18:58:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetByIdMultipleStorages() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2014-08-05 18:58:10 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2014-08-05 18:58:10 +04:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setMethods(['getMountsIn', 'getMount'])
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2016-09-12 22:21:42 +03:00
|
|
|
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
|
2014-11-24 17:54:42 +03:00
|
|
|
$mount1 = new MountPoint($storage, '/bar');
|
|
|
|
$mount2 = new MountPoint($storage, '/bar/foo/asd');
|
2019-01-22 19:28:57 +03:00
|
|
|
$storage->method('getId')->willReturn('');
|
|
|
|
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
|
2014-08-05 18:58:10 +04:00
|
|
|
|
2016-09-18 19:36:53 +03:00
|
|
|
$fileInfo = new CacheEntry(['path' => 'foo/qwerty', 'mimetype' => 'text/plain'], null);
|
|
|
|
|
2018-03-22 14:06:45 +03:00
|
|
|
$storage->expects($this->exactly(2))
|
2016-09-18 19:36:53 +03:00
|
|
|
->method('getCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($cache);
|
2016-09-18 19:36:53 +03:00
|
|
|
|
|
|
|
$this->userMountCache->expects($this->any())
|
|
|
|
->method('getMountsForFileId')
|
|
|
|
->with(1)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([
|
2016-09-18 19:36:53 +03:00
|
|
|
new CachedMountInfo(
|
|
|
|
$this->user,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
'/bar/',
|
|
|
|
1,
|
|
|
|
''
|
|
|
|
),
|
|
|
|
new CachedMountInfo(
|
|
|
|
$this->user,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
'/bar/foo/asd/',
|
|
|
|
1,
|
|
|
|
''
|
|
|
|
)
|
2020-03-26 00:21:27 +03:00
|
|
|
]);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$storage->expects($this->any())
|
|
|
|
->method('getCache')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($cache);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$cache->expects($this->any())
|
2016-09-18 19:36:53 +03:00
|
|
|
->method('get')
|
|
|
|
->with(1)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($fileInfo);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$root->expects($this->any())
|
|
|
|
->method('getMountsIn')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn([$mount2]);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('getMount')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($mount1);
|
2014-08-05 18:58:10 +04:00
|
|
|
|
|
|
|
$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) {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2015-03-24 17:00:36 +03:00
|
|
|
$folderPath = '/bar/foo';
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2015-03-24 17:00:36 +03:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setMethods(['getUser', 'getMountsIn', 'getMount'])
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2015-03-24 17:00:36 +03:00
|
|
|
|
|
|
|
$view->expects($this->any())
|
|
|
|
->method('file_exists')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($path) use ($existingFiles, $folderPath) {
|
2015-03-24 17:00:36 +03:00
|
|
|
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;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2015-03-24 17:00:36 +03:00
|
|
|
|
|
|
|
$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() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2016-07-22 15:37:37 +03:00
|
|
|
$folderPath = '/bar/foo';
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2016-07-22 15:37:37 +03:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setMethods(['getUser', 'getMountsIn', 'getMount'])
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
|
2017-10-25 01:03:28 +03:00
|
|
|
$folderInfo = $this->getMockBuilder(FileInfo::class)
|
2016-07-22 15:37:37 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
$baseTime = 1000;
|
|
|
|
$storage = new Temporary();
|
|
|
|
$mount = new MountPoint($storage, '');
|
|
|
|
|
|
|
|
$folderInfo->expects($this->any())
|
|
|
|
->method('getMountPoint')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($mount);
|
2016-07-22 15:37:37 +03:00
|
|
|
|
|
|
|
$cache = $storage->getCache();
|
|
|
|
|
|
|
|
$id1 = $cache->put('bar/foo/inside.txt', [
|
|
|
|
'storage_mtime' => $baseTime,
|
|
|
|
'mtime' => $baseTime,
|
|
|
|
'mimetype' => 'text/plain',
|
2019-07-22 17:41:15 +03:00
|
|
|
'size' => 3,
|
|
|
|
'permissions' => \OCP\Constants::PERMISSION_ALL
|
2016-07-22 15:37:37 +03:00
|
|
|
]);
|
|
|
|
$id2 = $cache->put('bar/foo/old.txt', [
|
|
|
|
'storage_mtime' => $baseTime - 100,
|
|
|
|
'mtime' => $baseTime - 100,
|
|
|
|
'mimetype' => 'text/plain',
|
2019-07-22 17:41:15 +03:00
|
|
|
'size' => 3,
|
|
|
|
'permissions' => \OCP\Constants::PERMISSION_READ
|
2016-07-22 15:37:37 +03:00
|
|
|
]);
|
|
|
|
$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',
|
2019-07-22 17:41:15 +03:00
|
|
|
'size' => 3,
|
|
|
|
'permissions' => \OCP\Constants::PERMISSION_ALL
|
2016-07-22 15:37:37 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$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() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2016-07-22 15:37:37 +03:00
|
|
|
$folderPath = '/bar/foo';
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2016-07-22 15:37:37 +03:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setMethods(['getUser', 'getMountsIn', 'getMount'])
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
|
2017-10-25 01:03:28 +03:00
|
|
|
$folderInfo = $this->getMockBuilder(FileInfo::class)
|
2016-07-22 15:37:37 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
$baseTime = 1000;
|
|
|
|
$storage = new Temporary();
|
|
|
|
$mount = new MountPoint($storage, '');
|
|
|
|
|
|
|
|
$folderInfo->expects($this->any())
|
|
|
|
->method('getMountPoint')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($mount);
|
2016-07-22 15:37:37 +03:00
|
|
|
|
|
|
|
$cache = $storage->getCache();
|
|
|
|
|
|
|
|
$id1 = $cache->put('bar/foo/folder', [
|
|
|
|
'storage_mtime' => $baseTime,
|
|
|
|
'mtime' => $baseTime,
|
|
|
|
'mimetype' => \OCP\Files\FileInfo::MIMETYPE_FOLDER,
|
2019-07-22 17:41:15 +03:00
|
|
|
'size' => 3,
|
|
|
|
'permissions' => 0
|
2016-07-22 15:37:37 +03:00
|
|
|
]);
|
|
|
|
$id2 = $cache->put('bar/foo/folder/bar.txt', [
|
|
|
|
'storage_mtime' => $baseTime,
|
|
|
|
'mtime' => $baseTime,
|
|
|
|
'mimetype' => 'text/plain',
|
|
|
|
'size' => 3,
|
2019-07-22 17:41:15 +03:00
|
|
|
'parent' => $id1,
|
|
|
|
'permissions' => \OCP\Constants::PERMISSION_ALL
|
2016-07-22 15:37:37 +03:00
|
|
|
]);
|
|
|
|
$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,
|
2019-07-22 17:41:15 +03:00
|
|
|
'parent' => $id1,
|
|
|
|
'permissions' => \OCP\Constants::PERMISSION_ALL
|
2016-07-22 15:37:37 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$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() {
|
2016-09-12 22:21:42 +03:00
|
|
|
$manager = $this->createMock(Manager::class);
|
2016-07-22 15:37:37 +03:00
|
|
|
$folderPath = '/bar/foo';
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
|
2016-07-22 15:37:37 +03:00
|
|
|
*/
|
2016-09-12 22:21:42 +03:00
|
|
|
$view = $this->createMock(View::class);
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
|
2016-11-03 01:16:51 +03:00
|
|
|
$root = $this->getMockBuilder(Root::class)
|
|
|
|
->setMethods(['getUser', 'getMountsIn', 'getMount'])
|
|
|
|
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
|
|
|
|
->getMock();
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
|
2017-10-25 01:03:28 +03:00
|
|
|
$folderInfo = $this->getMockBuilder(FileInfo::class)
|
2016-07-22 15:37:37 +03:00
|
|
|
->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')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($mount);
|
2016-07-22 15:37:37 +03:00
|
|
|
|
|
|
|
$cache = $storage->getCache();
|
|
|
|
|
|
|
|
$id1 = $cache->put('folder/inside.txt', [
|
|
|
|
'storage_mtime' => $baseTime,
|
|
|
|
'mtime' => $baseTime,
|
|
|
|
'mimetype' => 'text/plain',
|
2019-07-22 17:41:15 +03:00
|
|
|
'size' => 3,
|
|
|
|
'permissions' => \OCP\Constants::PERMISSION_ALL
|
2016-07-22 15:37:37 +03:00
|
|
|
]);
|
|
|
|
$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
|
|
|
}
|