aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Node
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Node')
-rw-r--r--tests/lib/Files/Node/FileTest.php140
-rw-r--r--tests/lib/Files/Node/FolderTest.php268
-rw-r--r--tests/lib/Files/Node/HookConnectorTest.php105
-rw-r--r--tests/lib/Files/Node/IntegrationTest.php34
-rw-r--r--tests/lib/Files/Node/NodeTestCase.php (renamed from tests/lib/Files/Node/NodeTest.php)212
-rw-r--r--tests/lib/Files/Node/RootTest.php84
6 files changed, 487 insertions, 356 deletions
diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php
index 218e2531727..eec34d156ad 100644
--- a/tests/lib/Files/Node/FileTest.php
+++ b/tests/lib/Files/Node/FileTest.php
@@ -1,13 +1,18 @@
<?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;
+use OC\Files\Node\File;
+use OC\Files\Node\Root;
+use OCP\Constants;
+use OCP\Files\NotPermittedException;
+
/**
* Class FileTest
*
@@ -15,12 +20,12 @@ namespace Test\Files\Node;
*
* @package Test\Files\Node
*/
-class FileTest extends NodeTest {
+class FileTest extends NodeTestCase {
protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) {
if ($data || $internalPath || $storage) {
- return new \OC\Files\Node\File($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
+ return new File($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
} else {
- return new \OC\Files\Node\File($root, $view, $path);
+ return new File($root, $view, $path);
}
}
@@ -36,13 +41,13 @@ class FileTest extends NodeTest {
return 'unlink';
}
- public function testGetContent() {
+ public function testGetContent(): void {
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
+ $root = $this->getMockBuilder(Root::class)
+ ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $hook = function ($file) {
+ $hook = function ($file): void {
throw new \Exception('Hooks are not supposed to be called');
};
@@ -57,19 +62,19 @@ class FileTest extends NodeTest {
$this->view->expects($this->once())
->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\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$this->assertEquals('bar', $node->getContent());
}
- public function testGetContentNotPermitted() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testGetContentNotPermitted(): void {
+ $this->expectException(NotPermittedException::class);
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
+ $root = $this->getMockBuilder(Root::class)
+ ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
@@ -81,14 +86,14 @@ class FileTest extends NodeTest {
->with('/bar/foo')
->willReturn($this->getFileInfo(['permissions' => 0]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->getContent();
}
- public function testPutContent() {
+ public function testPutContent(): void {
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
+ $root = $this->getMockBuilder(Root::class)
+ ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
@@ -98,39 +103,39 @@ class FileTest extends NodeTest {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$this->view->expects($this->once())
->method('file_put_contents')
->with('/bar/foo', 'bar')
->willReturn(true);
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->putContent('bar');
}
- public function testPutContentNotPermitted() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testPutContentNotPermitted(): void {
+ $this->expectException(NotPermittedException::class);
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
+ $root = $this->getMockBuilder(Root::class)
+ ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$this->view->expects($this->once())
->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\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->putContent('bar');
}
- public function testGetMimeType() {
+ public function testGetMimeType(): void {
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
+ $root = $this->getMockBuilder(Root::class)
+ ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$this->view->expects($this->once())
@@ -138,26 +143,27 @@ class FileTest extends NodeTest {
->with('/bar/foo')
->willReturn($this->getFileInfo(['mimetype' => 'text/plain']));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$this->assertEquals('text/plain', $node->getMimeType());
}
- public function testFOpenRead() {
+ public function testFOpenRead(): void {
$stream = fopen('php://memory', 'w+');
fwrite($stream, 'bar');
rewind($stream);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
- $hook = function ($file) {
+ $hook = function ($file): void {
throw new \Exception('Hooks are not supposed to be called');
};
@@ -172,28 +178,29 @@ class FileTest extends NodeTest {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$fh = $node->fopen('r');
$this->assertEquals($stream, $fh);
$this->assertEquals('bar', fread($fh, 3));
}
- public function testFOpenWrite() {
+ public function testFOpenWrite(): void {
$stream = fopen('php://memory', 'w+');
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
$hooksCalled = 0;
- $hook = function ($file) use (&$hooksCalled) {
+ $hook = function ($file) use (&$hooksCalled): void {
$hooksCalled++;
};
@@ -208,9 +215,9 @@ class FileTest extends NodeTest {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$fh = $node->fopen('w');
$this->assertEquals($stream, $fh);
fwrite($fh, 'bar');
@@ -220,19 +227,20 @@ class FileTest extends NodeTest {
}
- public function testFOpenReadNotPermitted() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testFOpenReadNotPermitted(): void {
+ $this->expectException(NotPermittedException::class);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
- $hook = function ($file) {
+ $hook = function ($file): void {
throw new \Exception('Hooks are not supposed to be called');
};
@@ -241,59 +249,61 @@ class FileTest extends NodeTest {
->with('/bar/foo')
->willReturn($this->getFileInfo(['permissions' => 0]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->fopen('r');
}
- public function testFOpenReadWriteNoReadPermissions() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testFOpenReadWriteNoReadPermissions(): void {
+ $this->expectException(NotPermittedException::class);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
- $hook = function () {
+ $hook = function (): void {
throw new \Exception('Hooks are not supposed to be called');
};
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_UPDATE]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_UPDATE]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->fopen('w');
}
- public function testFOpenReadWriteNoWritePermissions() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testFOpenReadWriteNoWritePermissions(): void {
+ $this->expectException(NotPermittedException::class);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
- $hook = function () {
+ $hook = function (): void {
throw new \Exception('Hooks are not supposed to be called');
};
$this->view->expects($this->once())
->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\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->fopen('w');
}
}
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index 0bcf69c5c13..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,7 +46,7 @@ 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')
@@ -62,13 +70,13 @@ 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
*/
$root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $this->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')
@@ -97,11 +105,11 @@ class FolderTest extends NodeTest {
$this->assertEquals(3, $children[1]->getId());
}
- public function testGet() {
+ public function testGet(): void {
$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])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
@@ -116,11 +124,11 @@ class FolderTest extends NodeTest {
self::assertEquals($node, $parentNode->get('asd'));
}
- public function testNodeExists() {
+ public function testNodeExists(): void {
$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])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
@@ -136,11 +144,11 @@ class FolderTest extends NodeTest {
$this->assertTrue($node->nodeExists('asd'));
}
- public function testNodeExistsNotExists() {
+ public function testNodeExistsNotExists(): void {
$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])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
@@ -148,17 +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);
$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')
@@ -166,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')
@@ -178,11 +186,11 @@ class FolderTest extends NodeTest {
$this->assertEquals($child, $result);
}
- public function testNewFolderDeepParent() {
+ public function testNewFolderDeepParent(): void {
$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])
+ ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
->method('getUser')
@@ -190,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')
@@ -203,30 +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);
$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);
$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')
@@ -234,43 +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);
$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);
$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);
@@ -283,28 +291,36 @@ class FolderTest extends NodeTest {
$this->assertEquals(100, $node->getFreeSpace());
}
- public function testSearch() {
+ public function testSearch(): void {
$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])
+ ->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']);
@@ -323,18 +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);
$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);
@@ -346,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']);
@@ -364,15 +383,15 @@ class FolderTest extends NodeTest {
$this->assertEquals('/foo', $result[0]->getPath());
}
- public function testSearchInStorageRoot() {
+ public function testSearchInStorageRoot(): void {
$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])
+ ->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);
@@ -384,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']);
@@ -404,19 +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);
$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();
@@ -435,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']);
@@ -462,7 +490,7 @@ class FolderTest extends NodeTest {
$this->assertEquals(2, count($result));
}
- public function testIsSubNode() {
+ public function testIsSubNode(): void {
$rootFolderMock = $this->createMock(IRootFolder::class);
$file = new Node($rootFolderMock, $this->view, '/foo/bar');
$folder = new Folder($rootFolderMock, $this->view, '/foo');
@@ -473,14 +501,14 @@ class FolderTest extends NodeTest {
$this->assertFalse($folder->isSubNode($file));
}
- public function testGetById() {
+ public function testGetById(): void {
$manager = $this->createMock(Manager::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();
@@ -489,6 +517,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -520,14 +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);
$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();
@@ -536,6 +566,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -563,14 +595,14 @@ class FolderTest extends NodeTest {
$this->assertEquals('/bar', $result[0]->getPath());
}
- public function testGetByIdOutsideFolder() {
+ public function testGetByIdOutsideFolder(): void {
$manager = $this->createMock(Manager::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();
@@ -579,6 +611,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->expects($this->any())
->method('getMountsForFileId')
@@ -605,14 +639,14 @@ class FolderTest extends NodeTest {
$this->assertEquals(0, count($result));
}
- public function testGetByIdMultipleStorages() {
+ public function testGetByIdMultipleStorages(): void {
$manager = $this->createMock(Manager::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('');
@@ -622,6 +656,8 @@ class FolderTest extends NodeTest {
$storage->method('getCache')
->willReturn($cache);
+ $storage->method('getOwner')
+ ->willReturn('owner');
$this->userMountCache->method('getMountsForFileId')
->with(1)
@@ -637,9 +673,6 @@ class FolderTest extends NodeTest {
),
]);
- $storage->method('getCache')
- ->willReturn($cache);
-
$cache->method('get')
->with(1)
->willReturn($fileInfo);
@@ -654,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'],
@@ -663,16 +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';
$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())
@@ -696,10 +727,10 @@ class FolderTest extends NodeTest {
$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();
@@ -717,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,
@@ -742,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);
@@ -755,16 +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';
$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();
@@ -783,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,
@@ -796,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,
@@ -804,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);
@@ -819,16 +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';
$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();
@@ -850,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,
@@ -873,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'], []],
@@ -894,15 +935,15 @@ 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')];
}
@@ -910,19 +951,19 @@ class FolderTest extends NodeTest {
$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])
+ ->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();
@@ -941,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);
@@ -953,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']);
@@ -975,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();
diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php
index 0501c175a5f..3f3957bab1d 100644
--- a/tests/lib/Files/Node/HookConnectorTest.php
+++ b/tests/lib/Files/Node/HookConnectorTest.php
@@ -1,9 +1,9 @@
<?php
+
/**
- * Copyright (c) 2015 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;
@@ -13,8 +13,10 @@ use OC\Files\Node\HookConnector;
use OC\Files\Node\Root;
use OC\Files\Storage\Temporary;
use OC\Files\View;
+use OC\Memcache\ArrayCache;
use OCP\EventDispatcher\GenericEvent as APIGenericEvent;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Config\IUserMountCache;
use OCP\Files\Events\Node\AbstractNodeEvent;
use OCP\Files\Events\Node\AbstractNodesEvent;
use OCP\Files\Events\Node\BeforeNodeCopiedEvent;
@@ -30,7 +32,9 @@ use OCP\Files\Events\Node\NodeRenamedEvent;
use OCP\Files\Events\Node\NodeTouchedEvent;
use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\Node;
+use OCP\ICacheFactory;
use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
@@ -48,9 +52,11 @@ class HookConnectorTest extends TestCase {
use UserTrait;
use MountProviderTrait;
- /** @var IEventDispatcher */
+ /** @var IEventDispatcher */
protected $eventDispatcher;
+ private LoggerInterface $logger;
+
/** @var View */
private $view;
@@ -67,17 +73,24 @@ class HookConnectorTest extends TestCase {
// this will setup the FS
$this->loginAsUser($this->userId);
$this->registerMount($this->userId, new Temporary(), '/' . $this->userId . '/files/');
+ $cacheFactory = $this->createMock(ICacheFactory::class);
+ $cacheFactory->method('createLocal')
+ ->willReturnCallback(function () {
+ return new ArrayCache();
+ });
$this->view = new View();
$this->root = new Root(
Filesystem::getMountManager(),
$this->view,
- \OC::$server->getUserManager()->get($this->userId),
- \OC::$server->getUserMountCache(),
+ Server::get(IUserManager::class)->get($this->userId),
+ Server::get(IUserMountCache::class),
$this->createMock(LoggerInterface::class),
$this->createMock(IUserManager::class),
- $this->createMock(IEventDispatcher::class)
+ $this->createMock(IEventDispatcher::class),
+ $cacheFactory,
);
- $this->eventDispatcher = \OC::$server->query(IEventDispatcher::class);
+ $this->eventDispatcher = Server::get(IEventDispatcher::class);
+ $this->logger = Server::get(LoggerInterface::class);
}
protected function tearDown(): void {
@@ -86,51 +99,51 @@ class HookConnectorTest extends TestCase {
\OC_Util::tearDownFS();
}
- public function viewToNodeProvider() {
+ public static function viewToNodeProvider(): array {
return [
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'preWrite', '\OCP\Files::preWrite', BeforeNodeWrittenEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'postWrite', '\OCP\Files::postWrite', NodeWrittenEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'preCreate', '\OCP\Files::preCreate', BeforeNodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'postCreate', '\OCP\Files::postCreate', NodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::mkdir('test.txt');
}, 'preCreate', '\OCP\Files::preCreate', BeforeNodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::mkdir('test.txt');
}, 'postCreate', '\OCP\Files::postCreate', NodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::touch('test.txt');
}, 'preTouch', '\OCP\Files::preTouch', BeforeNodeTouchedEvent::class],
- [function () {
+ [function (): void {
Filesystem::touch('test.txt');
}, 'postTouch', '\OCP\Files::postTouch', NodeTouchedEvent::class],
- [function () {
+ [function (): void {
Filesystem::touch('test.txt');
}, 'preCreate', '\OCP\Files::preCreate', BeforeNodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::touch('test.txt');
}, 'postCreate', '\OCP\Files::postCreate', NodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
Filesystem::unlink('test.txt');
}, 'preDelete', '\OCP\Files::preDelete', BeforeNodeDeletedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
Filesystem::unlink('test.txt');
}, 'postDelete', '\OCP\Files::postDelete', NodeDeletedEvent::class],
- [function () {
+ [function (): void {
Filesystem::mkdir('test.txt');
Filesystem::rmdir('test.txt');
}, 'preDelete', '\OCP\Files::preDelete', BeforeNodeDeletedEvent::class],
- [function () {
+ [function (): void {
Filesystem::mkdir('test.txt');
Filesystem::rmdir('test.txt');
}, 'postDelete', '\OCP\Files::postDelete', NodeDeletedEvent::class],
@@ -140,16 +153,16 @@ class HookConnectorTest extends TestCase {
/**
* @param callable $operation
* @param string $expectedHook
- * @dataProvider viewToNodeProvider
*/
- public function testViewToNode(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent) {
- $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher);
+ #[\PHPUnit\Framework\Attributes\DataProvider('viewToNodeProvider')]
+ public function testViewToNode(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent): void {
+ $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher, $this->logger);
$connector->viewToNode();
$hookCalled = false;
/** @var Node $hookNode */
$hookNode = null;
- $this->root->listen('\OC\Files', $expectedHook, function ($node) use (&$hookNode, &$hookCalled) {
+ $this->root->listen('\OC\Files', $expectedHook, function ($node) use (&$hookNode, &$hookCalled): void {
$hookCalled = true;
$hookNode = $node;
});
@@ -157,7 +170,7 @@ class HookConnectorTest extends TestCase {
$dispatcherCalled = false;
/** @var Node $dispatcherNode */
$dispatcherNode = null;
- $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherCalled, &$dispatcherNode) {
+ $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherCalled, &$dispatcherNode): void {
/** @var GenericEvent|APIGenericEvent $event */
$dispatcherCalled = true;
$dispatcherNode = $event->getSubject();
@@ -165,7 +178,7 @@ class HookConnectorTest extends TestCase {
$newDispatcherCalled = false;
$newDispatcherNode = null;
- $this->eventDispatcher->addListener($expectedEvent, function ($event) use ($expectedEvent, &$newDispatcherCalled, &$newDispatcherNode) {
+ $this->eventDispatcher->addListener($expectedEvent, function ($event) use ($expectedEvent, &$newDispatcherCalled, &$newDispatcherNode): void {
if ($event instanceof $expectedEvent) {
/** @var AbstractNodeEvent $event */
$newDispatcherCalled = true;
@@ -185,21 +198,21 @@ class HookConnectorTest extends TestCase {
$this->assertEquals('/' . $this->userId . '/files/test.txt', $newDispatcherNode->getPath());
}
- public function viewToNodeProviderCopyRename() {
+ public static function viewToNodeProviderCopyRename(): array {
return [
- [function () {
+ [function (): void {
Filesystem::file_put_contents('source', 'asd');
Filesystem::rename('source', 'target');
}, 'preRename', '\OCP\Files::preRename', BeforeNodeRenamedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('source', 'asd');
Filesystem::rename('source', 'target');
}, 'postRename', '\OCP\Files::postRename', NodeRenamedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('source', 'asd');
Filesystem::copy('source', 'target');
}, 'preCopy', '\OCP\Files::preCopy', BeforeNodeCopiedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('source', 'asd');
Filesystem::copy('source', 'target');
}, 'postCopy', '\OCP\Files::postCopy', NodeCopiedEvent::class],
@@ -209,10 +222,10 @@ class HookConnectorTest extends TestCase {
/**
* @param callable $operation
* @param string $expectedHook
- * @dataProvider viewToNodeProviderCopyRename
*/
- public function testViewToNodeCopyRename(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent) {
- $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher);
+ #[\PHPUnit\Framework\Attributes\DataProvider('viewToNodeProviderCopyRename')]
+ public function testViewToNodeCopyRename(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent): void {
+ $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher, $this->logger);
$connector->viewToNode();
$hookCalled = false;
/** @var Node $hookSourceNode */
@@ -220,7 +233,7 @@ class HookConnectorTest extends TestCase {
/** @var Node $hookTargetNode */
$hookTargetNode = null;
- $this->root->listen('\OC\Files', $expectedHook, function ($sourceNode, $targetNode) use (&$hookCalled, &$hookSourceNode, &$hookTargetNode) {
+ $this->root->listen('\OC\Files', $expectedHook, function ($sourceNode, $targetNode) use (&$hookCalled, &$hookSourceNode, &$hookTargetNode): void {
$hookCalled = true;
$hookSourceNode = $sourceNode;
$hookTargetNode = $targetNode;
@@ -231,7 +244,7 @@ class HookConnectorTest extends TestCase {
$dispatcherSourceNode = null;
/** @var Node $dispatcherTargetNode */
$dispatcherTargetNode = null;
- $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherSourceNode, &$dispatcherTargetNode, &$dispatcherCalled) {
+ $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherSourceNode, &$dispatcherTargetNode, &$dispatcherCalled): void {
/** @var GenericEvent|APIGenericEvent $event */
$dispatcherCalled = true;
[$dispatcherSourceNode, $dispatcherTargetNode] = $event->getSubject();
@@ -242,7 +255,7 @@ class HookConnectorTest extends TestCase {
$newDispatcherSourceNode = null;
/** @var Node $dispatcherTargetNode */
$newDispatcherTargetNode = null;
- $this->eventDispatcher->addListener($expectedEvent, function ($event) use ($expectedEvent, &$newDispatcherSourceNode, &$newDispatcherTargetNode, &$newDispatcherCalled) {
+ $this->eventDispatcher->addListener($expectedEvent, function ($event) use ($expectedEvent, &$newDispatcherSourceNode, &$newDispatcherTargetNode, &$newDispatcherCalled): void {
if ($event instanceof $expectedEvent) {
/** @var AbstractNodesEvent$event */
$newDispatcherCalled = true;
@@ -266,14 +279,14 @@ class HookConnectorTest extends TestCase {
$this->assertEquals('/' . $this->userId . '/files/target', $newDispatcherTargetNode->getPath());
}
- public function testPostDeleteMeta() {
- $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher);
+ public function testPostDeleteMeta(): void {
+ $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher, $this->logger);
$connector->viewToNode();
$hookCalled = false;
/** @var Node $hookNode */
$hookNode = null;
- $this->root->listen('\OC\Files', 'postDelete', function ($node) use (&$hookNode, &$hookCalled) {
+ $this->root->listen('\OC\Files', 'postDelete', function ($node) use (&$hookNode, &$hookCalled): void {
$hookCalled = true;
$hookNode = $node;
});
@@ -281,7 +294,7 @@ class HookConnectorTest extends TestCase {
$dispatcherCalled = false;
/** @var Node $dispatcherNode */
$dispatcherNode = null;
- $this->eventDispatcher->addListener('\OCP\Files::postDelete', function ($event) use (&$dispatcherCalled, &$dispatcherNode) {
+ $this->eventDispatcher->addListener('\OCP\Files::postDelete', function ($event) use (&$dispatcherCalled, &$dispatcherNode): void {
/** @var GenericEvent|APIGenericEvent $event */
$dispatcherCalled = true;
$dispatcherNode = $event->getSubject();
@@ -290,7 +303,7 @@ class HookConnectorTest extends TestCase {
$newDispatcherCalled = false;
/** @var Node $dispatcherNode */
$newDispatcherNode = null;
- $this->eventDispatcher->addListener(NodeDeletedEvent::class, function ($event) use (&$newDispatcherCalled, &$newDispatcherNode) {
+ $this->eventDispatcher->addListener(NodeDeletedEvent::class, function ($event) use (&$newDispatcherCalled, &$newDispatcherNode): void {
if ($event instanceof NodeDeletedEvent) {
/** @var AbstractNodeEvent $event */
$newDispatcherCalled = true;
diff --git a/tests/lib/Files/Node/IntegrationTest.php b/tests/lib/Files/Node/IntegrationTest.php
index 5ef5a134e1b..f059afa1625 100644
--- a/tests/lib/Files/Node/IntegrationTest.php
+++ b/tests/lib/Files/Node/IntegrationTest.php
@@ -1,19 +1,24 @@
<?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;
use OC\Files\Node\Root;
+use OC\Files\Storage\Storage;
use OC\Files\Storage\Temporary;
use OC\Files\View;
+use OC\Memcache\ArrayCache;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Config\IUserMountCache;
use OCP\Files\Mount\IMountManager;
+use OCP\ICacheFactory;
use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
use Test\Traits\UserTrait;
@@ -33,35 +38,40 @@ class IntegrationTest extends \Test\TestCase {
private $root;
/**
- * @var \OC\Files\Storage\Storage[]
+ * @var Storage[]
*/
private $storages;
/**
- * @var \OC\Files\View $view
+ * @var View $view
*/
private $view;
protected function setUp(): void {
parent::setUp();
- /** @var IMountManager $manager */
- $manager = \OC::$server->get(IMountManager::class);
+ $manager = Server::get(IMountManager::class);
\OC_Hook::clear('OC_Filesystem');
$user = $this->createUser($this->getUniqueID('user'), '');
$this->loginAsUser($user->getUID());
+ $cacheFactory = $this->createMock(ICacheFactory::class);
+ $cacheFactory->method('createLocal')
+ ->willReturnCallback(function () {
+ return new ArrayCache();
+ });
$this->view = new View();
$this->root = new Root(
$manager,
$this->view,
$user,
- \OC::$server->getUserMountCache(),
+ Server::get(IUserMountCache::class),
$this->createMock(LoggerInterface::class),
$this->createMock(IUserManager::class),
- $this->createMock(IEventDispatcher::class)
+ $this->createMock(IEventDispatcher::class),
+ $cacheFactory,
);
$storage = new Temporary([]);
$subStorage = new Temporary([]);
@@ -81,7 +91,7 @@ class IntegrationTest extends \Test\TestCase {
parent::tearDown();
}
- public function testBasicFile() {
+ public function testBasicFile(): void {
$file = $this->root->newFile('/foo.txt');
$this->assertCount(2, $this->root->getDirectoryListing());
$this->assertTrue($this->root->nodeExists('/foo.txt'));
@@ -104,7 +114,7 @@ class IntegrationTest extends \Test\TestCase {
$this->assertEquals('qwerty', $file->getContent());
}
- public function testBasicFolder() {
+ public function testBasicFolder(): void {
$folder = $this->root->newFolder('/foo');
$this->assertTrue($this->root->nodeExists('/foo'));
$file = $folder->newFile('/bar');
diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTestCase.php
index 4f782f28a36..4aecd0fef11 100644
--- a/tests/lib/Files/Node/NodeTest.php
+++ b/tests/lib/Files/Node/NodeTestCase.php
@@ -1,22 +1,33 @@
<?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;
use OC\Files\FileInfo;
use OC\Files\Mount\Manager;
+use OC\Files\Node\File;
+use OC\Files\Node\Folder;
+use OC\Files\Node\Root;
+use OC\Files\Storage\Storage;
use OC\Files\View;
+use OC\Memcache\ArrayCache;
+use OC\User\User;
+use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Config\IUserMountCache;
+use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
-use OCP\Files\Storage;
+use OCP\Files\NotPermittedException;
+use OCP\Files\Storage\IStorage;
+use OCP\ICacheFactory;
use OCP\IUser;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
@@ -26,16 +37,16 @@ use Psr\Log\LoggerInterface;
*
* @package Test\Files\Node
*/
-abstract class NodeTest extends \Test\TestCase {
- /** @var \OC\User\User */
+abstract class NodeTestCase extends \Test\TestCase {
+ /** @var User */
protected $user;
/** @var \OC\Files\Mount\Manager */
protected $manager;
- /** @var \OC\Files\View|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var View|\PHPUnit\Framework\MockObject\MockObject */
protected $view;
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject */
protected $root;
- /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserMountCache|\PHPUnit\Framework\MockObject\MockObject */
protected $userMountCache;
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger;
@@ -43,6 +54,8 @@ abstract class NodeTest extends \Test\TestCase {
protected $userManager;
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
protected $eventDispatcher;
+ /** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
+ protected $cacheFactory;
protected function setUp(): void {
parent::setUp();
@@ -63,13 +76,18 @@ abstract class NodeTest extends \Test\TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
- $this->root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->eventDispatcher])
+ $this->cacheFactory = $this->createMock(ICacheFactory::class);
+ $this->cacheFactory->method('createLocal')
+ ->willReturnCallback(function () {
+ return new ArrayCache();
+ });
+ $this->root = $this->getMockBuilder(Root::class)
+ ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
}
/**
- * @return \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
+ * @return View|\PHPUnit\Framework\MockObject\MockObject $view
*/
protected function getRootViewMock() {
$view = $this->createMock(View::class);
@@ -103,7 +121,7 @@ abstract class NodeTest extends \Test\TestCase {
abstract protected function getViewDeleteMethod();
protected function getMockStorage() {
- $storage = $this->getMockBuilder(Storage::class)
+ $storage = $this->getMockBuilder(IStorage::class)
->disableOriginalConstructor()
->getMock();
$storage->expects($this->any())
@@ -119,7 +137,7 @@ abstract class NodeTest extends \Test\TestCase {
return new FileInfo('', $this->getMockStorage(), $internalPath, $data, $mount);
}
- public function testDelete() {
+ public function testDelete(): void {
$this->root->expects($this->exactly(2))
->method('emit')
->willReturn(true);
@@ -130,7 +148,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$this->view->expects($this->once())
->method($this->getViewDeleteMethod())
@@ -141,13 +159,13 @@ abstract class NodeTest extends \Test\TestCase {
$node->delete();
}
- public function testDeleteHooks() {
+ public function testDeleteHooks(): void {
$test = $this;
$hooksRun = 0;
/**
* @param \OC\Files\Node\File $node
*/
- $preListener = function ($node) use (&$test, &$hooksRun) {
+ $preListener = function ($node) use (&$test, &$hooksRun): void {
$test->assertInstanceOf($this->getNodeClass(), $node);
$test->assertEquals('foo', $node->getInternalPath());
$test->assertEquals('/bar/foo', $node->getPath());
@@ -158,7 +176,7 @@ abstract class NodeTest extends \Test\TestCase {
/**
* @param \OC\Files\Node\File $node
*/
- $postListener = function ($node) use (&$test, &$hooksRun) {
+ $postListener = function ($node) use (&$test, &$hooksRun): void {
$test->assertInstanceOf($this->getNonExistingNodeClass(), $node);
$test->assertEquals('foo', $node->getInternalPath());
$test->assertEquals('/bar/foo', $node->getPath());
@@ -167,14 +185,15 @@ abstract class NodeTest extends \Test\TestCase {
$hooksRun++;
};
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
$root->listen('\OC\Files', 'preDelete', $preListener);
@@ -183,7 +202,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain'], 'foo'));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain'], 'foo'));
$this->view->expects($this->once())
->method($this->getViewDeleteMethod())
@@ -196,8 +215,8 @@ abstract class NodeTest extends \Test\TestCase {
}
- public function testDeleteNotPermitted() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testDeleteNotPermitted(): void {
+ $this->expectException(NotPermittedException::class);
$this->root->expects($this->any())
->method('getUser')
@@ -206,14 +225,14 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
$node->delete();
}
- public function testStat() {
+ public function testStat(): void {
$this->root->expects($this->any())
->method('getUser')
->willReturn($this->user);
@@ -235,7 +254,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->assertEquals($stat, $node->stat());
}
- public function testGetId() {
+ public function testGetId(): void {
$this->root->expects($this->any())
->method('getUser')
->willReturn($this->user);
@@ -256,7 +275,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->assertEquals(1, $node->getId());
}
- public function testGetSize() {
+ public function testGetSize(): void {
$this->root->expects($this->any())
->method('getUser')
->willReturn($this->user);
@@ -278,7 +297,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->assertEquals(100, $node->getSize());
}
- public function testGetEtag() {
+ public function testGetEtag(): void {
$this->root->expects($this->any())
->method('getUser')
->willReturn($this->user);
@@ -299,7 +318,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->assertEquals('qwerty', $node->getEtag());
}
- public function testGetMTime() {
+ public function testGetMTime(): void {
$this->root->expects($this->any())
->method('getUser')
->willReturn($this->user);
@@ -320,12 +339,12 @@ abstract class NodeTest extends \Test\TestCase {
$this->assertEquals(50, $node->getMTime());
}
- public function testGetStorage() {
+ public function testGetStorage(): void {
$this->root->expects($this->any())
->method('getUser')
->willReturn($this->user);
/**
- * @var \OC\Files\Storage\Storage | \PHPUnit\Framework\MockObject\MockObject $storage
+ * @var Storage|\PHPUnit\Framework\MockObject\MockObject $storage
*/
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()
@@ -335,7 +354,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->assertEquals($storage, $node->getStorage());
}
- public function testGetPath() {
+ public function testGetPath(): void {
$this->root->expects($this->any())
->method('getUser')
->willReturn($this->user);
@@ -344,12 +363,12 @@ abstract class NodeTest extends \Test\TestCase {
$this->assertEquals('/bar/foo', $node->getPath());
}
- public function testGetInternalPath() {
+ public function testGetInternalPath(): void {
$this->root->expects($this->any())
->method('getUser')
->willReturn($this->user);
/**
- * @var \OC\Files\Storage\Storage | \PHPUnit\Framework\MockObject\MockObject $storage
+ * @var Storage|\PHPUnit\Framework\MockObject\MockObject $storage
*/
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()
@@ -365,7 +384,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->assertEquals('foo', $node->getInternalPath());
}
- public function testGetName() {
+ public function testGetName(): void {
$this->root->expects($this->any())
->method('getUser')
->willReturn($this->user);
@@ -374,7 +393,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->assertEquals('foo', $node->getName());
}
- public function testTouchSetMTime() {
+ public function testTouchSetMTime(): void {
$this->root->expects($this->any())
->method('getUser')
->willReturn($this->user);
@@ -387,20 +406,20 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
$node->touch(100);
$this->assertEquals(100, $node->getMTime());
}
- public function testTouchHooks() {
+ public function testTouchHooks(): void {
$test = $this;
$hooksRun = 0;
/**
* @param \OC\Files\Node\File $node
*/
- $preListener = function ($node) use (&$test, &$hooksRun) {
+ $preListener = function ($node) use (&$test, &$hooksRun): void {
$test->assertEquals('foo', $node->getInternalPath());
$test->assertEquals('/bar/foo', $node->getPath());
$hooksRun++;
@@ -409,20 +428,21 @@ abstract class NodeTest extends \Test\TestCase {
/**
* @param \OC\Files\Node\File $node
*/
- $postListener = function ($node) use (&$test, &$hooksRun) {
+ $postListener = function ($node) use (&$test, &$hooksRun): void {
$test->assertEquals('foo', $node->getInternalPath());
$test->assertEquals('/bar/foo', $node->getPath());
$hooksRun++;
};
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
$root->listen('\OC\Files', 'preTouch', $preListener);
$root->listen('\OC\Files', 'postTouch', $postListener);
@@ -435,7 +455,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL], 'foo'));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL], 'foo'));
$node = $this->createTestNode($root, $this->view, '/bar/foo');
$node->touch(100);
@@ -443,8 +463,8 @@ abstract class NodeTest extends \Test\TestCase {
}
- public function testTouchNotPermitted() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testTouchNotPermitted(): void {
+ $this->expectException(NotPermittedException::class);
$this->root->expects($this->any())
->method('getUser')
@@ -453,21 +473,21 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
$node->touch(100);
}
- public function testInvalidPath() {
- $this->expectException(\OCP\Files\InvalidPathException::class);
+ public function testInvalidPath(): void {
+ $this->expectException(InvalidPathException::class);
$node = $this->createTestNode($this->root, $this->view, '/../foo');
$node->getFileInfo();
}
- public function testCopySameStorage() {
+ public function testCopySameStorage(): void {
$this->view->expects($this->any())
->method('copy')
->with('/bar/foo', '/bar/asd')
@@ -475,10 +495,10 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 3]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 3]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$newNode = $this->createTestNode($this->root, $this->view, '/bar/asd');
$this->root->method('get')
@@ -493,11 +513,11 @@ abstract class NodeTest extends \Test\TestCase {
}
- public function testCopyNotPermitted() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testCopyNotPermitted(): void {
+ $this->expectException(NotPermittedException::class);
/**
- * @var \OC\Files\Storage\Storage | \PHPUnit\Framework\MockObject\MockObject $storage
+ * @var Storage|\PHPUnit\Framework\MockObject\MockObject $storage
*/
$storage = $this->createMock('\OC\Files\Storage\Storage');
@@ -509,10 +529,10 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ, 'fileid' => 3]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ, 'fileid' => 3]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$this->root->expects($this->once())
->method('get')
@@ -524,8 +544,8 @@ abstract class NodeTest extends \Test\TestCase {
}
- public function testCopyNoParent() {
- $this->expectException(\OCP\Files\NotFoundException::class);
+ public function testCopyNoParent(): void {
+ $this->expectException(NotFoundException::class);
$this->view->expects($this->never())
->method('copy');
@@ -535,20 +555,20 @@ abstract class NodeTest extends \Test\TestCase {
$this->root->expects($this->once())
->method('get')
->with('/bar/asd')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$node->copy('/bar/asd/foo');
}
- public function testCopyParentIsFile() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testCopyParentIsFile(): void {
+ $this->expectException(NotPermittedException::class);
$this->view->expects($this->never())
->method('copy');
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\File($this->root, $this->view, '/bar');
+ $parentNode = new File($this->root, $this->view, '/bar');
$this->root->expects($this->once())
->method('get')
@@ -559,7 +579,7 @@ abstract class NodeTest extends \Test\TestCase {
$node->copy('/bar/asd');
}
- public function testMoveSameStorage() {
+ public function testMoveSameStorage(): void {
$this->view->expects($this->any())
->method('rename')
->with('/bar/foo', '/bar/asd')
@@ -567,10 +587,10 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 1]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$this->root->expects($this->any())
->method('get')
@@ -582,7 +602,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->assertEquals('/bar/asd', $node->getPath());
}
- public function moveOrCopyProvider() {
+ public static function moveOrCopyProvider(): array {
return [
['move', 'rename', 'preRename', 'postRename'],
['copy', 'copy', 'preCopy', 'postCopy'],
@@ -590,17 +610,17 @@ abstract class NodeTest extends \Test\TestCase {
}
/**
- * @dataProvider moveOrCopyProvider
* @param string $operationMethod
* @param string $viewMethod
* @param string $preHookName
* @param string $postHookName
*/
- public function testMoveCopyHooks($operationMethod, $viewMethod, $preHookName, $postHookName) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('moveOrCopyProvider')]
+ public function testMoveCopyHooks($operationMethod, $viewMethod, $preHookName, $postHookName): void {
/** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
- ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
- ->setMethods(['get'])
+ $root = $this->getMockBuilder(Root::class)
+ ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
+ ->onlyMethods(['get'])
->getMock();
$this->view->expects($this->any())
@@ -610,13 +630,13 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 1]));
/**
* @var \OC\Files\Node\File|\PHPUnit\Framework\MockObject\MockObject $node
*/
$node = $this->createTestNode($root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($root, $this->view, '/bar');
+ $parentNode = new Folder($root, $this->view, '/bar');
$targetTestNode = $this->createTestNode($root, $this->view, '/bar/asd');
$root->expects($this->any())
@@ -625,7 +645,7 @@ abstract class NodeTest extends \Test\TestCase {
$hooksRun = 0;
- $preListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node) {
+ $preListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node): void {
$this->assertSame($node, $sourceNode);
$this->assertInstanceOf($this->getNodeClass(), $sourceNode);
$this->assertInstanceOf($this->getNonExistingNodeClass(), $targetNode);
@@ -633,7 +653,7 @@ abstract class NodeTest extends \Test\TestCase {
$hooksRun++;
};
- $postListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node, $targetTestNode) {
+ $postListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node, $targetTestNode): void {
$this->assertSame($node, $sourceNode);
$this->assertNotSame($node, $targetNode);
$this->assertSame($targetTestNode, $targetNode);
@@ -642,13 +662,13 @@ abstract class NodeTest extends \Test\TestCase {
$hooksRun++;
};
- $preWriteListener = function (Node $targetNode) use (&$hooksRun) {
+ $preWriteListener = function (Node $targetNode) use (&$hooksRun): void {
$this->assertInstanceOf($this->getNonExistingNodeClass(), $targetNode);
$this->assertEquals('/bar/asd', $targetNode->getPath());
$hooksRun++;
};
- $postWriteListener = function (Node $targetNode) use (&$hooksRun, $targetTestNode) {
+ $postWriteListener = function (Node $targetNode) use (&$hooksRun, $targetTestNode): void {
$this->assertSame($targetTestNode, $targetNode);
$hooksRun++;
};
@@ -664,18 +684,18 @@ abstract class NodeTest extends \Test\TestCase {
}
- public function testMoveNotPermitted() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testMoveNotPermitted(): void {
+ $this->expectException(NotPermittedException::class);
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
$this->view->expects($this->never())
->method('rename');
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$this->root->expects($this->once())
->method('get')
@@ -686,11 +706,11 @@ abstract class NodeTest extends \Test\TestCase {
}
- public function testMoveNoParent() {
- $this->expectException(\OCP\Files\NotFoundException::class);
+ public function testMoveNoParent(): void {
+ $this->expectException(NotFoundException::class);
/**
- * @var \OC\Files\Storage\Storage | \PHPUnit\Framework\MockObject\MockObject $storage
+ * @var Storage|\PHPUnit\Framework\MockObject\MockObject $storage
*/
$storage = $this->createMock('\OC\Files\Storage\Storage');
@@ -702,20 +722,20 @@ abstract class NodeTest extends \Test\TestCase {
$this->root->expects($this->once())
->method('get')
->with('/bar')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$node->move('/bar/asd');
}
- public function testMoveParentIsFile() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testMoveParentIsFile(): void {
+ $this->expectException(NotPermittedException::class);
$this->view->expects($this->never())
->method('rename');
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\File($this->root, $this->view, '/bar');
+ $parentNode = new File($this->root, $this->view, '/bar');
$this->root->expects($this->once())
->method('get')
@@ -726,8 +746,8 @@ abstract class NodeTest extends \Test\TestCase {
}
- public function testMoveFailed() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testMoveFailed(): void {
+ $this->expectException(NotPermittedException::class);
$this->view->expects($this->any())
->method('rename')
@@ -736,10 +756,10 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 1]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$this->root->expects($this->any())
->method('get')
@@ -749,8 +769,8 @@ abstract class NodeTest extends \Test\TestCase {
}
- public function testCopyFailed() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testCopyFailed(): void {
+ $this->expectException(NotPermittedException::class);
$this->view->expects($this->any())
->method('copy')
@@ -759,10 +779,10 @@ abstract class NodeTest extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 1]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$this->root->expects($this->any())
->method('get')
diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php
index e24283f0931..d90e6a2cc6e 100644
--- a/tests/lib/Files/Node/RootTest.php
+++ b/tests/lib/Files/Node/RootTest.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;
@@ -11,9 +11,18 @@ namespace Test\Files\Node;
use OC\Files\FileInfo;
use OC\Files\Mount\Manager;
use OC\Files\Node\Folder;
+use OC\Files\Node\Root;
+use OC\Files\Storage\Storage;
use OC\Files\View;
+use OC\Memcache\ArrayCache;
+use OC\User\NoUserException;
+use OC\User\User;
use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Config\IUserMountCache;
+use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
+use OCP\ICacheFactory;
use OCP\IUser;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
@@ -24,11 +33,11 @@ use Psr\Log\LoggerInterface;
* @package Test\Files\Node
*/
class RootTest extends \Test\TestCase {
- /** @var \OC\User\User */
+ /** @var User */
private $user;
/** @var \OC\Files\Mount\Manager */
private $manager;
- /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserMountCache|\PHPUnit\Framework\MockObject\MockObject */
private $userMountCache;
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
private $logger;
@@ -36,6 +45,8 @@ class RootTest extends \Test\TestCase {
private $userManager;
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
private $eventDispatcher;
+ /** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
+ protected $cacheFactory;
protected function setUp(): void {
parent::setUp();
@@ -50,10 +61,15 @@ class RootTest extends \Test\TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
+ $this->cacheFactory = $this->createMock(ICacheFactory::class);
+ $this->cacheFactory->method('createLocal')
+ ->willReturnCallback(function () {
+ return new ArrayCache();
+ });
}
/**
- * @return \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
+ * @return View|\PHPUnit\Framework\MockObject\MockObject $view
*/
protected function getRootViewMock() {
$view = $this->createMock(View::class);
@@ -67,22 +83,23 @@ class RootTest extends \Test\TestCase {
return new FileInfo('', null, '', $data, null);
}
- public function testGet() {
+ public function testGet(): void {
/**
- * @var \OC\Files\Storage\Storage $storage
+ * @var Storage $storage
*/
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()
->getMock();
$view = $this->getRootViewMock();
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
$view->expects($this->once())
@@ -97,24 +114,25 @@ class RootTest extends \Test\TestCase {
}
- public function testGetNotFound() {
- $this->expectException(\OCP\Files\NotFoundException::class);
+ public function testGetNotFound(): void {
+ $this->expectException(NotFoundException::class);
/**
- * @var \OC\Files\Storage\Storage $storage
+ * @var Storage $storage
*/
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()
->getMock();
$view = $this->getRootViewMock();
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
$view->expects($this->once())
@@ -127,50 +145,53 @@ class RootTest extends \Test\TestCase {
}
- public function testGetInvalidPath() {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ public function testGetInvalidPath(): void {
+ $this->expectException(NotPermittedException::class);
$view = $this->getRootViewMock();
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
$root->get('/../foo');
}
- public function testGetNoStorages() {
- $this->expectException(\OCP\Files\NotFoundException::class);
+ public function testGetNoStorages(): void {
+ $this->expectException(NotFoundException::class);
$view = $this->getRootViewMock();
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$view,
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
$root->get('/bar/foo');
}
- public function testGetUserFolder() {
- $root = new \OC\Files\Node\Root(
+ public function testGetUserFolder(): void {
+ $root = new Root(
$this->manager,
$this->getRootViewMock(),
$this->user,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
$user = $this->createMock(IUser::class);
$user
@@ -200,18 +221,19 @@ class RootTest extends \Test\TestCase {
}
- public function testGetUserFolderWithNoUserObj() {
- $this->expectException(\OC\User\NoUserException::class);
+ public function testGetUserFolderWithNoUserObj(): void {
+ $this->expectException(NoUserException::class);
$this->expectExceptionMessage('Backends provided no user object');
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->createMock(Manager::class),
$this->getRootViewMock(),
null,
$this->userMountCache,
$this->logger,
$this->userManager,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->cacheFactory,
);
$this->userManager
->expects($this->once())