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.php397
1 files changed, 196 insertions, 201 deletions
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index 8a604af3846..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;
@@ -18,18 +18,26 @@ 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\NotPermittedException;
+use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOrder;
-use OCP\Files\Storage;
+use OCP\Files\Storage\IStorage;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class FolderTest
@@ -38,8 +46,11 @@ use OCP\Files\Storage;
*
* @package Test\Files\Node
*/
-class FolderTest extends NodeTest {
+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 {
@@ -59,30 +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, $this->eventDispatcher])
+ ->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),
]);
- $view->method('getFileInfo')
+ $this->view->method('getFileInfo')
->willReturn($this->createMock(FileInfo::class));
+ $this->view->method('getRelativePath')
+ ->willReturn('/bar/foo');
- $node = new 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]);
@@ -93,14 +105,11 @@ 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, $this->eventDispatcher])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
@@ -115,14 +124,11 @@ class FolderTest extends NodeTest {
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, $this->eventDispatcher])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
@@ -138,14 +144,11 @@ class FolderTest extends NodeTest {
$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, $this->eventDispatcher])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
@@ -153,20 +156,17 @@ class FolderTest extends NodeTest {
$root->method('get')
->with('/bar/foo/asd')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$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, $this->eventDispatcher])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
@@ -174,7 +174,7 @@ class FolderTest extends NodeTest {
$view->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$view->method('mkdir')
->with('/bar/foo/asd')
@@ -186,14 +186,11 @@ class FolderTest extends NodeTest {
$this->assertEquals($child, $result);
}
- public function testNewFolderDeepParent() {
+ 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, $this->eventDispatcher])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
@@ -201,7 +198,7 @@ class FolderTest extends NodeTest {
$view->method('getFileInfo')
->with('/foobar')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$view->method('mkdir')
->with('/foobar/asd/sdf')
@@ -214,36 +211,30 @@ class FolderTest extends NodeTest {
}
- public function testNewFolderNotPermitted() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testNewFolderNotPermitted(): 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, $this->eventDispatcher])
+ ->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 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, $this->eventDispatcher])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
@@ -251,49 +242,43 @@ class FolderTest extends NodeTest {
$view->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$view->method('touch')
->with('/bar/foo/asd')
->willReturn(true);
$node = new Folder($root, $view, '/bar/foo');
- $child = new \OC\Files\Node\File($root, $view, '/bar/foo/asd', null, $node);
+ $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, $this->eventDispatcher])
+ ->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 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, $this->eventDispatcher])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->method('getUser')
->willReturn($this->user);
@@ -306,31 +291,36 @@ class FolderTest extends NodeTest {
$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, $this->eventDispatcher])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->method('getUser')
->willReturn($this->user);
- /** @var Storage\IStorage $storage */
- $storage = $this->createMock(Storage\IStorage::class);
+ /** @var Storage\IStorage&MockObject $storage */
+ $storage = $this->createMock(IStorage::class);
$storage->method('getId')->willReturn('test::1');
$cache = new Cache($storage);
$storage->method('getCache')
->willReturn($cache);
+ $storage->expects($this->atLeastOnce())
+ ->method('getOwner')
+ ->with('qwerty')
+ ->willReturn(false);
+
$mount = $this->createMock(IMountPoint::class);
- $mount->method('getStorage')
+ $mount->expects($this->atLeastOnce())
+ ->method('getStorage')
->willReturn($storage);
- $mount->method('getInternalPath')
+ $mount->expects($this->atLeastOnce())
+ ->method('getInternalPath')
->willReturn('foo');
+ $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']);
@@ -349,21 +339,18 @@ class FolderTest extends NodeTest {
$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, $this->eventDispatcher])
+ ->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 = $this->createMock(IStorage::class);
$storage->method('getId')->willReturn('test::2');
$cache = new Cache($storage);
@@ -375,7 +362,10 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
+ $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']);
@@ -393,18 +383,15 @@ class FolderTest extends NodeTest {
$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, $this->eventDispatcher])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->method('getUser')
->willReturn($this->user);
- $storage = $this->createMock(Storage::class);
+ $storage = $this->createMock(IStorage::class);
$storage->method('getId')->willReturn('test::1');
$cache = new Cache($storage);
@@ -416,7 +403,10 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
+ $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']);
@@ -436,22 +426,19 @@ class FolderTest extends NodeTest {
$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, $this->eventDispatcher])
+ ->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 = $this->createMock(IStorage::class);
$storage->method('getId')->willReturn('test::1');
$cache = new Cache($storage);
- $subStorage = $this->createMock(Storage::class);
+ $subStorage = $this->createMock(IStorage::class);
$subStorage->method('getId')->willReturn('test::2');
$subCache = new Cache($subStorage);
$subMount = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([Temporary::class, ''])->getMock();
@@ -470,13 +457,19 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$subStorage->method('getCache')
->willReturn($subCache);
+ $subStorage->method('getOwner')
+ ->willReturn('owner');
+ $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->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']);
@@ -497,27 +490,25 @@ class FolderTest extends NodeTest {
$this->assertEquals(2, count($result));
}
- public function testIsSubNode() {
- $file = new Node(null, null, '/foo/bar');
- $folder = new 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, $this->eventDispatcher])
+ ->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();
@@ -526,6 +517,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -557,17 +550,14 @@ class FolderTest extends NodeTest {
$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, $this->eventDispatcher])
+ ->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();
@@ -576,6 +566,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -603,17 +595,14 @@ class FolderTest extends NodeTest {
$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, $this->eventDispatcher])
+ ->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();
@@ -622,6 +611,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -648,17 +639,14 @@ class FolderTest extends NodeTest {
$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, $this->eventDispatcher])
+ ->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('');
@@ -668,6 +656,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->method('getMountsForFileId')
->with(1)
@@ -683,9 +673,6 @@ class FolderTest extends NodeTest {
),
]);
- $storage->method('getCache')
- ->willReturn($cache);
-
$cache->method('get')
->with(1)
->willReturn($fileInfo);
@@ -700,7 +687,7 @@ class FolderTest extends NodeTest {
$this->assertEquals('/bar/foo/asd/foo/qwerty', $result[1]->getPath());
}
- public function uniqueNameProvider() {
+ public static function uniqueNameProvider(): array {
return [
// input, existing, expected
['foo', [], 'foo'],
@@ -709,19 +696,14 @@ class FolderTest extends NodeTest {
];
}
- /**
- * @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, $this->eventDispatcher])
+ ->onlyMethods(['getUser', 'getMountsIn', 'getMount'])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$view->expects($this->any())
@@ -742,16 +724,13 @@ class FolderTest extends NodeTest {
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, $this->eventDispatcher])
+ ->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();
@@ -769,19 +748,23 @@ class FolderTest extends NodeTest {
$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,
@@ -794,7 +777,7 @@ class FolderTest extends NodeTest {
'mtime' => $baseTime - 600,
'mimetype' => 'text/plain',
'size' => 3,
- 'permissions' => \OCP\Constants::PERMISSION_ALL,
+ 'permissions' => Constants::PERMISSION_ALL,
]);
$node = new Folder($root, $view, $folderPath, $folderInfo);
@@ -807,19 +790,16 @@ 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, $this->eventDispatcher])
+ ->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();
@@ -838,6 +818,9 @@ class FolderTest extends NodeTest {
$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,
@@ -851,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,
@@ -859,7 +842,7 @@ class FolderTest extends NodeTest {
'mimetype' => 'text/plain',
'size' => 3,
'parent' => $id1,
- 'permissions' => \OCP\Constants::PERMISSION_ALL,
+ 'permissions' => Constants::PERMISSION_ALL,
]);
$node = new Folder($root, $view, $folderPath, $folderInfo);
@@ -874,19 +857,16 @@ 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, $this->eventDispatcher])
+ ->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();
@@ -908,13 +888,16 @@ class FolderTest extends NodeTest {
$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,
@@ -931,7 +914,7 @@ class FolderTest extends NodeTest {
$this->assertEquals([$id1], $ids);
}
- public function offsetLimitProvider() {
+ 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'], []],
@@ -952,38 +935,35 @@ class FolderTest extends NodeTest {
}
/**
- * @dataProvider offsetLimitProvider
* @param int $offset
* @param int $limit
* @param string[] $expectedPaths
* @param ISearchOrder[] $ordering
* @throws NotFoundException
- * @throws \OCP\Files\InvalidPathException
+ * @throws InvalidPathException
*/
- public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array $expectedPaths, array $ordering) {
+ #[\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);
- /**
- * @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, $this->eventDispatcher])
+ ->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 = $this->createMock(IStorage::class);
$storage->method('getId')->willReturn('test::1');
$cache = new Cache($storage);
- $subStorage1 = $this->createMock(Storage::class);
+ $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(Storage::class);
+ $subStorage2 = $this->createMock(IStorage::class);
$subStorage2->method('getId')->willReturn('test::3');
$subCache2 = new Cache($subStorage2);
$subMount2 = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([Temporary::class, ''])->getMock();
@@ -1002,9 +982,13 @@ class FolderTest extends NodeTest {
$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);
@@ -1014,15 +998,22 @@ class FolderTest extends NodeTest {
$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']);
@@ -1036,7 +1027,11 @@ class FolderTest extends NodeTest {
$node = new Folder($root, $view, '/bar/foo');
$comparison = new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%foo%');
- $query = new SearchQuery($comparison, $limit, $offset, $ordering);
+ $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();