aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Node/FolderTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Node/FolderTest.php')
-rw-r--r--tests/lib/Files/Node/FolderTest.php850
1 files changed, 467 insertions, 383 deletions
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index 1ba052b8de4..439535cf2c1 100644
--- a/tests/lib/Files/Node/FolderTest.php
+++ b/tests/lib/Files/Node/FolderTest.php
@@ -1,9 +1,9 @@
<?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.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files\Node;
@@ -14,14 +14,30 @@ use OC\Files\Config\CachedMountInfo;
use OC\Files\FileInfo;
use OC\Files\Mount\Manager;
use OC\Files\Mount\MountPoint;
+use OC\Files\Node\File;
+use OC\Files\Node\Folder;
use OC\Files\Node\Node;
use OC\Files\Node\Root;
+use OC\Files\Search\SearchBinaryOperator;
+use OC\Files\Search\SearchComparison;
+use OC\Files\Search\SearchOrder;
+use OC\Files\Search\SearchQuery;
+use OC\Files\Storage\Storage;
use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\View;
+use OCP\Constants;
+use OCP\Files\Cache\ICacheEntry;
+use OCP\Files\InvalidPathException;
+use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
-use OCP\Files\Storage;
+use OCP\Files\NotPermittedException;
+use OCP\Files\Search\ISearchBinaryOperator;
+use OCP\Files\Search\ISearchComparison;
+use OCP\Files\Search\ISearchOrder;
+use OCP\Files\Storage\IStorage;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class FolderTest
@@ -30,9 +46,16 @@ use OCP\Files\Storage;
*
* @package Test\Files\Node
*/
-class FolderTest extends NodeTest {
- protected function createTestNode($root, $view, $path) {
- return new \OC\Files\Node\Folder($root, $view, $path);
+class FolderTest extends NodeTestCase {
+ protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) {
+ $view->expects($this->any())
+ ->method('getRoot')
+ ->willReturn('');
+ if ($data || $internalPath || $storage) {
+ return new Folder($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
+ } else {
+ return new Folder($root, $view, $path);
+ }
}
protected function getNodeClass() {
@@ -47,28 +70,31 @@ class FolderTest extends NodeTest {
return 'rmdir';
}
- public function testGetDirectoryContent() {
+ public function testGetDirectoryContent(): void {
$manager = $this->createMock(Manager::class);
/**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
+ * @var View|\PHPUnit\Framework\MockObject\MockObject $view
*/
- $view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
->willReturn($this->user);
- $view->expects($this->any())
+ $this->view->expects($this->any())
->method('getDirectoryContent')
->with('/bar/foo')
->willReturn([
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)
+ 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),
]);
+ $this->view->method('getFileInfo')
+ ->willReturn($this->createMock(FileInfo::class));
+ $this->view->method('getRelativePath')
+ ->willReturn('/bar/foo');
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $node = new Folder($root, $this->view, '/bar/foo');
$children = $node->getDirectoryListing();
$this->assertEquals(2, count($children));
$this->assertInstanceOf('\OC\Files\Node\File', $children[0]);
@@ -79,461 +105,420 @@ class FolderTest extends NodeTest {
$this->assertEquals(3, $children[1]->getId());
}
- public function testGet() {
+ public function testGet(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
->willReturn($this->user);
- $root->expects($this->once())
- ->method('get')
- ->with('/bar/foo/asd');
+ $node = new File($root, $view, '/bar/foo/asd');
+ $root->method('get')
+ ->with('/bar/foo/asd')
+ ->willReturn($node);
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
- $node->get('asd');
+ $parentNode = new Folder($root, $view, '/bar/foo');
+ self::assertEquals($node, $parentNode->get('asd'));
}
- public function testNodeExists() {
+ public function testNodeExists(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
->willReturn($this->user);
- $child = new \OC\Files\Node\Folder($root, $view, '/bar/foo/asd');
+ $child = new Folder($root, $view, '/bar/foo/asd');
- $root->expects($this->once())
- ->method('get')
+ $root->method('get')
->with('/bar/foo/asd')
->willReturn($child);
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $node = new Folder($root, $view, '/bar/foo');
$this->assertTrue($node->nodeExists('asd'));
}
- public function testNodeExistsNotExists() {
+ public function testNodeExistsNotExists(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
->willReturn($this->user);
- $root->expects($this->once())
- ->method('get')
+ $root->method('get')
->with('/bar/foo/asd')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $node = new Folder($root, $view, '/bar/foo');
$this->assertFalse($node->nodeExists('asd'));
}
- public function testNewFolder() {
+ public function testNewFolder(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
->willReturn($this->user);
- $view->expects($this->once())
- ->method('getFileInfo')
+ $view->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
- $view->expects($this->once())
- ->method('mkdir')
+ $view->method('mkdir')
->with('/bar/foo/asd')
->willReturn(true);
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
- $child = new \OC\Files\Node\Folder($root, $view, '/bar/foo/asd');
+ $node = new Folder($root, $view, '/bar/foo');
+ $child = new Folder($root, $view, '/bar/foo/asd', null, $node);
$result = $node->newFolder('asd');
$this->assertEquals($child, $result);
}
-
- public function testNewFolderNotPermitted() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
-
+ public function testNewFolderDeepParent(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
->willReturn($this->user);
- $view->expects($this->once())
- ->method('getFileInfo')
+ $view->method('getFileInfo')
+ ->with('/foobar')
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
+
+ $view->method('mkdir')
+ ->with('/foobar/asd/sdf')
+ ->willReturn(true);
+
+ $node = new Folder($root, $view, '/foobar');
+ $child = new Folder($root, $view, '/foobar/asd/sdf', null, null);
+ $result = $node->newFolder('asd/sdf');
+ $this->assertEquals($child, $result);
+ }
+
+
+ public function testNewFolderNotPermitted(): void {
+ $this->expectException(NotPermittedException::class);
+
+ $manager = $this->createMock(Manager::class);
+ $view = $this->getRootViewMock();
+ $root = $this->getMockBuilder(Root::class)
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
+ ->getMock();
+ $root->method('getUser')
+ ->willReturn($this->user);
+
+ $view->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $node = new Folder($root, $view, '/bar/foo');
$node->newFolder('asd');
}
- public function testNewFile() {
+ public function testNewFile(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
->willReturn($this->user);
- $view->expects($this->once())
- ->method('getFileInfo')
+ $view->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
- $view->expects($this->once())
- ->method('touch')
+ $view->method('touch')
->with('/bar/foo/asd')
->willReturn(true);
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
- $child = new \OC\Files\Node\File($root, $view, '/bar/foo/asd');
+ $node = new Folder($root, $view, '/bar/foo');
+ $child = new File($root, $view, '/bar/foo/asd', null, $node);
$result = $node->newFile('asd');
$this->assertEquals($child, $result);
}
- public function testNewFileNotPermitted() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testNewFileNotPermitted(): void {
+ $this->expectException(NotPermittedException::class);
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $root->expects($this->any())
- ->method('getUser')
+ $root->method('getUser')
->willReturn($this->user);
- $view->expects($this->once())
- ->method('getFileInfo')
+ $view->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $node = new Folder($root, $view, '/bar/foo');
$node->newFile('asd');
}
- public function testGetFreeSpace() {
+ public function testGetFreeSpace(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $root->expects($this->any())
- ->method('getUser')
+ $root->method('getUser')
->willReturn($this->user);
- $view->expects($this->once())
- ->method('free_space')
+ $view->method('free_space')
->with('/bar/foo')
->willReturn(100);
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $node = new Folder($root, $view, '/bar/foo');
$this->assertEquals(100, $node->getFreeSpace());
}
- public function testSearch() {
+ public function testSearch(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $root->expects($this->any())
- ->method('getUser')
+ $root->method('getUser')
->willReturn($this->user);
- $storage = $this->createMock(Storage::class);
- $storage->method('getId')->willReturn('');
- $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
+ /** @var Storage\IStorage&MockObject $storage */
+ $storage = $this->createMock(IStorage::class);
+ $storage->method('getId')->willReturn('test::1');
+ $cache = new Cache($storage);
- $storage->expects($this->once())
- ->method('getCache')
+ $storage->method('getCache')
->willReturn($cache);
+ $storage->expects($this->atLeastOnce())
+ ->method('getOwner')
+ ->with('qwerty')
+ ->willReturn(false);
+
$mount = $this->createMock(IMountPoint::class);
- $mount->expects($this->once())
+ $mount->expects($this->atLeastOnce())
->method('getStorage')
->willReturn($storage);
- $mount->expects($this->once())
+ $mount->expects($this->atLeastOnce())
->method('getInternalPath')
->willReturn('foo');
- $cache->expects($this->once())
- ->method('search')
- ->with('%qw%')
- ->willReturn([
- ['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
- ]);
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('foo/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
- $root->expects($this->once())
- ->method('getMountsIn')
+ $root->method('getMountsIn')
->with('/bar/foo')
->willReturn([]);
- $root->expects($this->once())
- ->method('getMount')
+ $root->method('getMount')
->with('/bar/foo')
->willReturn($mount);
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $node = new Folder($root, $view, '/bar/foo');
$result = $node->search('qw');
+ $cache->clear();
$this->assertEquals(1, count($result));
$this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
}
- public function testSearchInRoot() {
+ public function testSearchInRoot(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getUser', 'getMountsIn', 'getMount'])
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->onlyMethods(['getUser', 'getMountsIn', 'getMount'])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
->willReturn($this->user);
/** @var \PHPUnit\Framework\MockObject\MockObject|Storage $storage */
- $storage = $this->createMock(Storage::class);
- $storage->method('getId')->willReturn('');
- $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
+ $storage = $this->createMock(IStorage::class);
+ $storage->method('getId')->willReturn('test::2');
+ $cache = new Cache($storage);
$mount = $this->createMock(IMountPoint::class);
- $mount->expects($this->once())
- ->method('getStorage')
+ $mount->method('getStorage')
->willReturn($storage);
- $mount->expects($this->once())
- ->method('getInternalPath')
+ $mount->method('getInternalPath')
->willReturn('files');
- $storage->expects($this->once())
- ->method('getCache')
+ $storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
- $cache->expects($this->once())
- ->method('search')
- ->with('%qw%')
- ->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'],
- ]);
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('files', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('files/foo', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
- $root->expects($this->once())
- ->method('getMountsIn')
+ $root->method('getMountsIn')
->with('')
->willReturn([]);
- $root->expects($this->once())
- ->method('getMount')
+ $root->method('getMount')
->with('')
->willReturn($mount);
- $result = $root->search('qw');
+ $result = $root->search('foo');
+ $cache->clear();
$this->assertEquals(1, count($result));
$this->assertEquals('/foo', $result[0]->getPath());
}
- public function testSearchInStorageRoot() {
+ public function testSearchInStorageRoot(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $root->expects($this->any())
- ->method('getUser')
+ $root->method('getUser')
->willReturn($this->user);
- $storage = $this->createMock(Storage::class);
- $storage->method('getId')->willReturn('');
- $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
+ $storage = $this->createMock(IStorage::class);
+ $storage->method('getId')->willReturn('test::1');
+ $cache = new Cache($storage);
$mount = $this->createMock(IMountPoint::class);
- $mount->expects($this->once())
- ->method('getStorage')
+ $mount->method('getStorage')
->willReturn($storage);
- $mount->expects($this->once())
- ->method('getInternalPath')
+ $mount->method('getInternalPath')
->willReturn('');
- $storage->expects($this->once())
- ->method('getCache')
+ $storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
- $cache->expects($this->once())
- ->method('search')
- ->with('%qw%')
- ->willReturn([
- ['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
- ]);
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('foo/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
- $root->expects($this->once())
- ->method('getMountsIn')
+
+ $root->method('getMountsIn')
->with('/bar')
->willReturn([]);
- $root->expects($this->once())
- ->method('getMount')
+ $root->method('getMount')
->with('/bar')
->willReturn($mount);
- $node = new \OC\Files\Node\Folder($root, $view, '/bar');
+ $node = new Folder($root, $view, '/bar');
$result = $node->search('qw');
+ $cache->clear();
$this->assertEquals(1, count($result));
$this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
}
- public function testSearchSubStorages() {
+ public function testSearchSubStorages(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
->willReturn($this->user);
- $storage = $this->createMock(Storage::class);
- $storage->method('getId')->willReturn('');
- $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
- $subCache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
- $subStorage = $this->createMock(Storage::class);
- $subMount = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([null, ''])->getMock();
+ $storage = $this->createMock(IStorage::class);
+ $storage->method('getId')->willReturn('test::1');
+ $cache = new Cache($storage);
+ $subStorage = $this->createMock(IStorage::class);
+ $subStorage->method('getId')->willReturn('test::2');
+ $subCache = new Cache($subStorage);
+ $subMount = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([Temporary::class, ''])->getMock();
$mount = $this->createMock(IMountPoint::class);
- $mount->expects($this->once())
- ->method('getStorage')
+ $mount->method('getStorage')
->willReturn($storage);
- $mount->expects($this->once())
- ->method('getInternalPath')
+ $mount->method('getInternalPath')
->willReturn('foo');
- $subMount->expects($this->once())
- ->method('getStorage')
+ $subMount->method('getStorage')
->willReturn($subStorage);
- $subMount->expects($this->once())
- ->method('getMountPoint')
+ $subMount->method('getMountPoint')
->willReturn('/bar/foo/bar/');
- $storage->expects($this->once())
- ->method('getCache')
+ $storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
- $subStorage->expects($this->once())
- ->method('getCache')
+ $subStorage->method('getCache')
->willReturn($subCache);
+ $subStorage->method('getOwner')
+ ->willReturn('owner');
- $cache->expects($this->once())
- ->method('search')
- ->with('%qw%')
- ->willReturn([
- ['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
- ]);
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('foo', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('foo/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
- $subCache->expects($this->once())
- ->method('search')
- ->with('%qw%')
- ->willReturn([
- ['fileid' => 4, 'path' => 'asd/qweasd', 'name' => 'qweasd', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']
- ]);
+ $subCache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $subCache->insert('asd', ['size' => 200, 'mtime' => 55, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $subCache->insert('asd/qwerty', ['size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']);
- $root->expects($this->once())
- ->method('getMountsIn')
+
+ $root->method('getMountsIn')
->with('/bar/foo')
->willReturn([$subMount]);
- $root->expects($this->once())
- ->method('getMount')
+ $root->method('getMount')
->with('/bar/foo')
->willReturn($mount);
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $node = new Folder($root, $view, '/bar/foo');
$result = $node->search('qw');
+ $cache->clear();
+ $subCache->clear();
$this->assertEquals(2, count($result));
}
- public function testIsSubNode() {
- $file = new Node(null, null, '/foo/bar');
- $folder = new \OC\Files\Node\Folder(null, null, '/foo');
+ public function testIsSubNode(): void {
+ $rootFolderMock = $this->createMock(IRootFolder::class);
+ $file = new Node($rootFolderMock, $this->view, '/foo/bar');
+ $folder = new Folder($rootFolderMock, $this->view, '/foo');
$this->assertTrue($folder->isSubNode($file));
$this->assertFalse($folder->isSubNode($folder));
- $file = new Node(null, null, '/foobar');
+ $file = new Node($rootFolderMock, $this->view, '/foobar');
$this->assertFalse($folder->isSubNode($file));
}
- public function testGetById() {
+ public function testGetById(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getMountsIn', 'getMount'])
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->onlyMethods(['getMountsIn', 'getMount'])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $storage = $this->createMock(\OC\Files\Storage\Storage::class);
+ $storage = $this->createMock(Storage::class);
$mount = new MountPoint($storage, '/bar');
$storage->method('getId')->willReturn('');
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
$fileInfo = new CacheEntry(['path' => 'foo/qwerty', 'mimetype' => 'text/plain'], null);
- $storage->expects($this->once())
- ->method('getCache')
+ $storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -543,51 +528,46 @@ class FolderTest extends NodeTest {
1,
0,
'/bar/',
+ 'test',
1,
''
)]);
- $cache->expects($this->once())
- ->method('get')
+ $cache->method('get')
->with(1)
->willReturn($fileInfo);
- $root->expects($this->once())
- ->method('getMountsIn')
+ $root->method('getMountsIn')
->with('/bar/foo')
->willReturn([]);
- $root->expects($this->once())
- ->method('getMount')
- ->with('/bar/foo')
- ->willReturn($mount);
+ $manager->method('getMountsByMountProvider')
+ ->willReturn([$mount]);
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $node = new Folder($root, $view, '/bar/foo');
$result = $node->getById(1);
$this->assertEquals(1, count($result));
$this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
}
- public function testGetByIdMountRoot() {
+ public function testGetByIdMountRoot(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getMountsIn', 'getMount'])
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->onlyMethods(['getMountsIn', 'getMount'])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $storage = $this->createMock(\OC\Files\Storage\Storage::class);
+ $storage = $this->createMock(Storage::class);
$mount = new MountPoint($storage, '/bar');
$storage->method('getId')->willReturn('');
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
$fileInfo = new CacheEntry(['path' => '', 'mimetype' => 'text/plain'], null);
- $storage->expects($this->once())
- ->method('getCache')
+ $storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -597,46 +577,42 @@ class FolderTest extends NodeTest {
1,
0,
'/bar/',
+ 'test',
1,
''
)]);
- $cache->expects($this->once())
- ->method('get')
+ $cache->method('get')
->with(1)
->willReturn($fileInfo);
- $root->expects($this->once())
- ->method('getMount')
- ->with('/bar')
- ->willReturn($mount);
+ $manager->method('getMountsByMountProvider')
+ ->willReturn([$mount]);
- $node = new \OC\Files\Node\Folder($root, $view, '/bar');
+ $node = new Folder($root, $view, '/bar');
$result = $node->getById(1);
$this->assertEquals(1, count($result));
$this->assertEquals('/bar', $result[0]->getPath());
}
- public function testGetByIdOutsideFolder() {
+ public function testGetByIdOutsideFolder(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getMountsIn', 'getMount'])
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->onlyMethods(['getMountsIn', 'getMount'])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $storage = $this->createMock(\OC\Files\Storage\Storage::class);
+ $storage = $this->createMock(Storage::class);
$mount = new MountPoint($storage, '/bar');
$storage->method('getId')->willReturn('');
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
$fileInfo = new CacheEntry(['path' => 'foobar', 'mimetype' => 'text/plain'], null);
- $storage->expects($this->once())
- ->method('getCache')
+ $storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -646,41 +622,31 @@ class FolderTest extends NodeTest {
1,
0,
'/bar/',
+ 'test',
1,
''
)]);
- $cache->expects($this->once())
- ->method('get')
+ $cache->method('get')
->with(1)
->willReturn($fileInfo);
- $root->expects($this->once())
- ->method('getMountsIn')
- ->with('/bar/foo')
- ->willReturn([]);
+ $manager->method('getMountsByMountProvider')
+ ->willReturn([$mount]);
- $root->expects($this->once())
- ->method('getMount')
- ->with('/bar/foo')
- ->willReturn($mount);
-
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $node = new Folder($root, $view, '/bar/foo');
$result = $node->getById(1);
$this->assertEquals(0, count($result));
}
- public function testGetByIdMultipleStorages() {
+ public function testGetByIdMultipleStorages(): void {
$manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getMountsIn', 'getMount'])
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->onlyMethods(['getMountsIn', 'getMount'])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $storage = $this->createMock(\OC\Files\Storage\Storage::class);
+ $storage = $this->createMock(Storage::class);
$mount1 = new MountPoint($storage, '/bar');
$mount2 = new MountPoint($storage, '/bar/foo/asd');
$storage->method('getId')->willReturn('');
@@ -688,12 +654,12 @@ class FolderTest extends NodeTest {
$fileInfo = new CacheEntry(['path' => 'foo/qwerty', 'mimetype' => 'text/plain'], null);
- $storage->expects($this->exactly(2))
- ->method('getCache')
+ $storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
- $this->userMountCache->expects($this->any())
- ->method('getMountsForFileId')
+ $this->userMountCache->method('getMountsForFileId')
->with(1)
->willReturn([
new CachedMountInfo(
@@ -701,67 +667,43 @@ class FolderTest extends NodeTest {
1,
0,
'/bar/',
+ 'test',
1,
''
),
- new CachedMountInfo(
- $this->user,
- 1,
- 0,
- '/bar/foo/asd/',
- 1,
- ''
- )
]);
- $storage->expects($this->any())
- ->method('getCache')
- ->willReturn($cache);
-
- $cache->expects($this->any())
- ->method('get')
+ $cache->method('get')
->with(1)
->willReturn($fileInfo);
- $root->expects($this->any())
- ->method('getMountsIn')
- ->with('/bar/foo')
- ->willReturn([$mount2]);
+ $manager->method('getMountsByMountProvider')
+ ->willReturn([$mount1, $mount2]);
- $root->expects($this->once())
- ->method('getMount')
- ->with('/bar/foo')
- ->willReturn($mount1);
-
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $node = new 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());
}
- public function uniqueNameProvider() {
+ public static function uniqueNameProvider(): array {
return [
// input, existing, expected
['foo', [], 'foo'],
['foo', ['foo'], 'foo (2)'],
- ['foo', ['foo', 'foo (2)'], 'foo (3)']
+ ['foo', ['foo', 'foo (2)'], 'foo (3)'],
];
}
- /**
- * @dataProvider uniqueNameProvider
- */
- public function testGetUniqueName($name, $existingFiles, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('uniqueNameProvider')]
+ public function testGetUniqueName($name, $existingFiles, $expected): void {
$manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getUser', 'getMountsIn', 'getMount'])
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->onlyMethods(['getUser', 'getMountsIn', 'getMount'])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$view->expects($this->any())
@@ -775,65 +717,70 @@ class FolderTest extends NodeTest {
return false;
});
- $node = new \OC\Files\Node\Folder($root, $view, $folderPath);
+ $node = new Folder($root, $view, $folderPath);
$this->assertEquals($expected, $node->getNonExistingName($name));
}
- public function testRecent() {
+ public function testRecent(): void {
$manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getUser', 'getMountsIn', 'getMount'])
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->onlyMethods(['getUser', 'getMountsIn', 'getMount'])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
+ /** @var \PHPUnit\Framework\MockObject\MockObject|FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()->getMock();
- $baseTime = 1000;
+ $baseTime = time();
$storage = new Temporary();
$mount = new MountPoint($storage, '');
$folderInfo->expects($this->any())
->method('getMountPoint')
->willReturn($mount);
+ $root->method('getMount')
+ ->willReturn($mount);
+ $root->method('getMountsIn')
+ ->willReturn([]);
$cache = $storage->getCache();
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('bar', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('bar/foo', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('bar/asd', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$id1 = $cache->put('bar/foo/inside.txt', [
'storage_mtime' => $baseTime,
'mtime' => $baseTime,
'mimetype' => 'text/plain',
'size' => 3,
- 'permissions' => \OCP\Constants::PERMISSION_ALL
+ 'permissions' => Constants::PERMISSION_ALL,
]);
$id2 = $cache->put('bar/foo/old.txt', [
'storage_mtime' => $baseTime - 100,
'mtime' => $baseTime - 100,
'mimetype' => 'text/plain',
'size' => 3,
- 'permissions' => \OCP\Constants::PERMISSION_READ
+ 'permissions' => Constants::PERMISSION_READ,
]);
$cache->put('bar/asd/outside.txt', [
'storage_mtime' => $baseTime,
'mtime' => $baseTime,
'mimetype' => 'text/plain',
- 'size' => 3
+ 'size' => 3,
]);
$id3 = $cache->put('bar/foo/older.txt', [
'storage_mtime' => $baseTime - 600,
'mtime' => $baseTime - 600,
'mimetype' => 'text/plain',
'size' => 3,
- 'permissions' => \OCP\Constants::PERMISSION_ALL
+ 'permissions' => Constants::PERMISSION_ALL,
]);
- $node = new \OC\Files\Node\Folder($root, $view, $folderPath, $folderInfo);
+ $node = new Folder($root, $view, $folderPath, $folderInfo);
$nodes = $node->getRecent(5);
@@ -843,23 +790,20 @@ class FolderTest extends NodeTest {
$this->assertEquals([$id1, $id2, $id3], $ids);
}
- public function testRecentFolder() {
+ public function testRecentFolder(): void {
$manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getUser', 'getMountsIn', 'getMount'])
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->onlyMethods(['getUser', 'getMountsIn', 'getMount'])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
+ /** @var \PHPUnit\Framework\MockObject\MockObject|FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()->getMock();
- $baseTime = 1000;
+ $baseTime = time();
$storage = new Temporary();
$mount = new MountPoint($storage, '');
@@ -867,14 +811,22 @@ class FolderTest extends NodeTest {
->method('getMountPoint')
->willReturn($mount);
+ $root->method('getMount')
+ ->willReturn($mount);
+ $root->method('getMountsIn')
+ ->willReturn([]);
+
$cache = $storage->getCache();
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('bar', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('bar/foo', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$id1 = $cache->put('bar/foo/folder', [
'storage_mtime' => $baseTime,
'mtime' => $baseTime,
'mimetype' => \OCP\Files\FileInfo::MIMETYPE_FOLDER,
'size' => 3,
- 'permissions' => 0
+ 'permissions' => 0,
]);
$id2 = $cache->put('bar/foo/folder/bar.txt', [
'storage_mtime' => $baseTime,
@@ -882,7 +834,7 @@ class FolderTest extends NodeTest {
'mimetype' => 'text/plain',
'size' => 3,
'parent' => $id1,
- 'permissions' => \OCP\Constants::PERMISSION_ALL
+ 'permissions' => Constants::PERMISSION_ALL,
]);
$id3 = $cache->put('bar/foo/folder/asd.txt', [
'storage_mtime' => $baseTime - 100,
@@ -890,10 +842,10 @@ class FolderTest extends NodeTest {
'mimetype' => 'text/plain',
'size' => 3,
'parent' => $id1,
- 'permissions' => \OCP\Constants::PERMISSION_ALL
+ 'permissions' => Constants::PERMISSION_ALL,
]);
- $node = new \OC\Files\Node\Folder($root, $view, $folderPath, $folderInfo);
+ $node = new Folder($root, $view, $folderPath, $folderInfo);
$nodes = $node->getRecent(5);
@@ -905,51 +857,55 @@ class FolderTest extends NodeTest {
$this->assertEquals($baseTime - 100, $nodes[1]->getMTime());
}
- public function testRecentJail() {
+ public function testRecentJail(): void {
$manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
- /**
- * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
- */
- $view = $this->createMock(View::class);
+ $view = $this->getRootViewMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getUser', 'getMountsIn', 'getMount'])
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
+ ->onlyMethods(['getUser', 'getMountsIn', 'getMount'])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
+ /** @var \PHPUnit\Framework\MockObject\MockObject|FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()->getMock();
- $baseTime = 1000;
+ $baseTime = time();
$storage = new Temporary();
$jail = new Jail([
'storage' => $storage,
- 'root' => 'folder'
+ 'root' => 'folder',
]);
$mount = new MountPoint($jail, '/bar/foo');
$folderInfo->expects($this->any())
->method('getMountPoint')
->willReturn($mount);
+ $root->method('getMount')
+ ->willReturn($mount);
+ $root->method('getMountsIn')
+ ->willReturn([]);
$cache = $storage->getCache();
+ $cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('folder', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$id1 = $cache->put('folder/inside.txt', [
'storage_mtime' => $baseTime,
'mtime' => $baseTime,
'mimetype' => 'text/plain',
'size' => 3,
- 'permissions' => \OCP\Constants::PERMISSION_ALL
+ 'permissions' => Constants::PERMISSION_ALL,
]);
+
$cache->put('outside.txt', [
'storage_mtime' => $baseTime - 100,
'mtime' => $baseTime - 100,
'mimetype' => 'text/plain',
- 'size' => 3
+ 'size' => 3,
]);
- $node = new \OC\Files\Node\Folder($root, $view, $folderPath, $folderInfo);
+ $node = new Folder($root, $view, $folderPath, $folderInfo);
$nodes = $node->getRecent(5);
$ids = array_map(function (Node $node) {
@@ -957,4 +913,132 @@ class FolderTest extends NodeTest {
}, $nodes);
$this->assertEquals([$id1], $ids);
}
+
+ public static function offsetLimitProvider(): array {
+ return [
+ [0, 10, ['/bar/foo/foo1', '/bar/foo/foo2', '/bar/foo/foo3', '/bar/foo/foo4', '/bar/foo/sub1/foo5', '/bar/foo/sub1/foo6', '/bar/foo/sub2/foo7', '/bar/foo/sub2/foo8'], []],
+ [0, 5, ['/bar/foo/foo1', '/bar/foo/foo2', '/bar/foo/foo3', '/bar/foo/foo4', '/bar/foo/sub1/foo5'], []],
+ [0, 2, ['/bar/foo/foo1', '/bar/foo/foo2'], []],
+ [3, 2, ['/bar/foo/foo4', '/bar/foo/sub1/foo5'], []],
+ [3, 5, ['/bar/foo/foo4', '/bar/foo/sub1/foo5', '/bar/foo/sub1/foo6', '/bar/foo/sub2/foo7', '/bar/foo/sub2/foo8'], []],
+ [5, 2, ['/bar/foo/sub1/foo6', '/bar/foo/sub2/foo7'], []],
+ [6, 2, ['/bar/foo/sub2/foo7', '/bar/foo/sub2/foo8'], []],
+ [7, 2, ['/bar/foo/sub2/foo8'], []],
+ [10, 2, [], []],
+ [0, 5, ['/bar/foo/sub2/foo7', '/bar/foo/foo1', '/bar/foo/sub1/foo5', '/bar/foo/foo2', '/bar/foo/foo3'], [new SearchOrder(ISearchOrder::DIRECTION_ASCENDING, 'mtime')]],
+ [3, 2, ['/bar/foo/foo2', '/bar/foo/foo3'], [new SearchOrder(ISearchOrder::DIRECTION_ASCENDING, 'mtime')]],
+ [0, 5, ['/bar/foo/sub1/foo5', '/bar/foo/sub1/foo6', '/bar/foo/sub2/foo7', '/bar/foo/foo1', '/bar/foo/foo2'], [
+ new SearchOrder(ISearchOrder::DIRECTION_DESCENDING, 'size'),
+ new SearchOrder(ISearchOrder::DIRECTION_ASCENDING, 'mtime')
+ ]],
+ ];
+ }
+
+ /**
+ * @param int $offset
+ * @param int $limit
+ * @param string[] $expectedPaths
+ * @param ISearchOrder[] $ordering
+ * @throws NotFoundException
+ * @throws InvalidPathException
+ */
+ #[\PHPUnit\Framework\Attributes\DataProvider('offsetLimitProvider')]
+ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array $expectedPaths, array $ordering): void {
+ if (!$ordering) {
+ $ordering = [new SearchOrder(ISearchOrder::DIRECTION_ASCENDING, 'fileid')];
+ }
+
+ $manager = $this->createMock(Manager::class);
+ $view = $this->getRootViewMock();
+ $root = $this->getMockBuilder(Root::class)
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
+ ->getMock();
+ $root->expects($this->any())
+ ->method('getUser')
+ ->willReturn($this->user);
+ $storage = $this->createMock(IStorage::class);
+ $storage->method('getId')->willReturn('test::1');
+ $cache = new Cache($storage);
+ $subStorage1 = $this->createMock(IStorage::class);
+ $subStorage1->method('getId')->willReturn('test::2');
+ $subCache1 = new Cache($subStorage1);
+ $subMount1 = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([Temporary::class, ''])->getMock();
+ $subStorage2 = $this->createMock(IStorage::class);
+ $subStorage2->method('getId')->willReturn('test::3');
+ $subCache2 = new Cache($subStorage2);
+ $subMount2 = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([Temporary::class, ''])->getMock();
+
+ $mount = $this->createMock(IMountPoint::class);
+ $mount->method('getStorage')
+ ->willReturn($storage);
+ $mount->method('getInternalPath')
+ ->willReturn('foo');
+
+ $subMount1->method('getStorage')
+ ->willReturn($subStorage1);
+
+ $subMount1->method('getMountPoint')
+ ->willReturn('/bar/foo/sub1/');
+
+ $storage->method('getCache')
+ ->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
+
+ $subStorage1->method('getCache')
+ ->willReturn($subCache1);
+ $subStorage1->method('getOwner')
+ ->willReturn('owner');
+
+ $subMount2->method('getStorage')
+ ->willReturn($subStorage2);
+
+ $subMount2->method('getMountPoint')
+ ->willReturn('/bar/foo/sub2/');
+
+ $subStorage2->method('getCache')
+ ->willReturn($subCache2);
+ $subStorage2->method('getOwner')
+ ->willReturn('owner');
+
+
+ $cache->insert('', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('foo', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $cache->insert('foo/foo1', ['size' => 200, 'mtime' => 10, 'mimetype' => 'text/plain']);
+ $cache->insert('foo/foo2', ['size' => 200, 'mtime' => 20, 'mimetype' => 'text/plain']);
+ $cache->insert('foo/foo3', ['size' => 200, 'mtime' => 30, 'mimetype' => 'text/plain']);
+ $cache->insert('foo/foo4', ['size' => 200, 'mtime' => 40, 'mimetype' => 'text/plain']);
+
+ $subCache1->insert('', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $subCache1->insert('foo5', ['size' => 300, 'mtime' => 15, 'mimetype' => 'text/plain']);
+ $subCache1->insert('foo6', ['size' => 300, 'mtime' => 50, 'mimetype' => 'text/plain']);
+
+ $subCache2->insert('', ['size' => 0, 'mtime' => 10, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $subCache2->insert('foo7', ['size' => 200, 'mtime' => 5, 'mimetype' => 'text/plain']);
+ $subCache2->insert('foo8', ['size' => 200, 'mtime' => 60, 'mimetype' => 'text/plain']);
+
+ $root->method('getMountsIn')
+ ->with('/bar/foo')
+ ->willReturn([$subMount1, $subMount2]);
+
+ $root->method('getMount')
+ ->with('/bar/foo')
+ ->willReturn($mount);
+
+ $node = new Folder($root, $view, '/bar/foo');
+ $comparison = new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%foo%');
+ $operator = new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [
+ $comparison,
+ new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_NOT, [new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE)]),
+ ]);
+ $query = new SearchQuery($operator, $limit, $offset, $ordering);
+ $result = $node->search($query);
+ $cache->clear();
+ $subCache1->clear();
+ $subCache2->clear();
+ $ids = array_map(function (Node $info) {
+ return $info->getPath();
+ }, $result);
+ $this->assertEquals($expectedPaths, $ids);
+ }
}