]> source.dussan.org Git - nextcloud-server.git/commitdiff
tests: Adapt node related unit tests mocks to required root view 38128/head
authorJulius Härtl <jus@bitgrid.net>
Mon, 20 Feb 2023 21:12:00 +0000 (22:12 +0100)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Mon, 8 May 2023 15:21:52 +0000 (15:21 +0000)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
apps/dav/tests/unit/Files/FileSearchBackendTest.php
tests/lib/Files/Node/FileTest.php
tests/lib/Files/Node/FolderTest.php
tests/lib/Files/Node/NodeTest.php
tests/lib/Files/Node/RootTest.php

index 65ae08d67d3f1e88aebfd2aaebd92d307549be77..40c350fbddfe98a5f7a673d369af058362b848e7 100644 (file)
@@ -219,13 +219,13 @@ class DirectoryTest extends \Test\TestCase {
 
                $this->view->expects($this->any())
                        ->method('getRelativePath')
-                       ->willReturnCallback(function($path) {
+                       ->willReturnCallback(function ($path) {
                                return str_replace('/admin/files/', '', $path);
                        });
 
                $this->view->expects($this->any())
                        ->method('getAbsolutePath')
-                       ->willReturnCallback(function($path) {
+                       ->willReturnCallback(function ($path) {
                                return Filesystem::normalizePath('/admin/files' . $path);
                        });
 
index cc4dcb62b75429739f513bf8d44b04fcefca5e84..715130d2faeef7a26cad1184dc27f5a5b59ee990 100644 (file)
@@ -86,9 +86,11 @@ class FileSearchBackendTest extends TestCase {
                        ->disableOriginalConstructor()
                        ->getMock();
 
-               $this->view = $this->getMockBuilder(View::class)
-                       ->disableOriginalConstructor()
-                       ->getMock();
+               $this->view = $this->createMock(View::class);
+
+               $this->view->expects($this->any())
+                       ->method('getRoot')
+                       ->willReturn('');
 
                $this->view->expects($this->any())
                        ->method('getRelativePath')
index 3305f9ac1706576418fd92475e63f1f5698b09d6..218e253172746073e5c2279511b0bd3632bc560d 100644 (file)
@@ -185,7 +185,7 @@ class FileTest extends NodeTest {
 
                $root = new \OC\Files\Node\Root(
                        $this->manager,
-                       new $this->view,
+                       $this->view,
                        $this->user,
                        $this->userMountCache,
                        $this->logger,
@@ -277,7 +277,7 @@ class FileTest extends NodeTest {
 
                $root = new \OC\Files\Node\Root(
                        $this->manager,
-                       new $this->view,
+                       $this->view,
                        $this->user,
                        $this->userMountCache,
                        $this->logger,
index f8573f0214df574db1fe97754d97aaad873d7bb0..d745a05ba17f42832defe756fa6b19573e1f8901 100644 (file)
@@ -23,7 +23,6 @@ use OC\Files\Search\SearchOrder;
 use OC\Files\Search\SearchQuery;
 use OC\Files\Storage\Temporary;
 use OC\Files\Storage\Wrapper\Jail;
-use OC\Files\View;
 use OCP\Files\Cache\ICacheEntry;
 use OCP\Files\Mount\IMountPoint;
 use OCP\Files\NotFoundException;
@@ -40,6 +39,9 @@ use OCP\Files\Storage;
  */
 class FolderTest extends NodeTest {
        protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) {
+               $view->expects($this->any())
+                       ->method('getRoot')
+                       ->willReturn('');
                if ($data || $internalPath || $storage) {
                        return new Folder($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
                } else {
@@ -64,27 +66,26 @@ class FolderTest extends NodeTest {
                /**
                 * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
                 */
-               $view = $this->createMock(View::class);
                $root = $this->getMockBuilder(Root::class)
-                       ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
+                       ->setConstructorArgs([$manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
                $root->expects($this->any())
                        ->method('getUser')
                        ->willReturn($this->user);
 
-               $view->expects($this->any())
+               $this->view->expects($this->any())
                        ->method('getDirectoryContent')
                        ->with('/bar/foo')
                        ->willReturn([
                                new FileInfo('/bar/foo/asd', null, 'foo/asd', ['fileid' => 2, 'path' => '/bar/foo/asd', 'name' => 'asd', 'size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain'], null),
                                new FileInfo('/bar/foo/qwerty', null, 'foo/qwerty', ['fileid' => 3, 'path' => '/bar/foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'httpd/unix-directory'], null),
                        ]);
-               $view->method('getFileInfo')
+               $this->view->method('getFileInfo')
                        ->willReturn($this->createMock(FileInfo::class));
-               $view->method('getRelativePath')
+               $this->view->method('getRelativePath')
                        ->willReturn('/bar/foo');
 
-               $node = new Folder($root, $view, '/bar/foo');
+               $node = new Folder($root, $this->view, '/bar/foo');
                $children = $node->getDirectoryListing();
                $this->assertEquals(2, count($children));
                $this->assertInstanceOf('\OC\Files\Node\File', $children[0]);
@@ -97,10 +98,7 @@ class FolderTest extends NodeTest {
 
        public function testGet() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -119,10 +117,7 @@ class FolderTest extends NodeTest {
 
        public function testNodeExists() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -142,10 +137,7 @@ class FolderTest extends NodeTest {
 
        public function testNodeExistsNotExists() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -163,10 +155,7 @@ class FolderTest extends NodeTest {
 
        public function testNewFolder() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -190,10 +179,7 @@ class FolderTest extends NodeTest {
 
        public function testNewFolderDeepParent() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -220,10 +206,7 @@ class FolderTest extends NodeTest {
                $this->expectException(\OCP\Files\NotPermittedException::class);
 
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -240,10 +223,7 @@ class FolderTest extends NodeTest {
 
        public function testNewFile() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -270,10 +250,7 @@ class FolderTest extends NodeTest {
                $this->expectException(\OCP\Files\NotPermittedException::class);
 
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -290,10 +267,7 @@ class FolderTest extends NodeTest {
 
        public function testGetFreeSpace() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -310,10 +284,7 @@ class FolderTest extends NodeTest {
 
        public function testSearch() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -353,10 +324,7 @@ class FolderTest extends NodeTest {
 
        public function testSearchInRoot() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setMethods(['getUser', 'getMountsIn', 'getMount'])
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
@@ -397,10 +365,7 @@ class FolderTest extends NodeTest {
 
        public function testSearchInStorageRoot() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -440,10 +405,7 @@ class FolderTest extends NodeTest {
 
        public function testSearchSubStorages() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
@@ -500,21 +462,18 @@ class FolderTest extends NodeTest {
        }
 
        public function testIsSubNode() {
-               $file = new Node(null, null, '/foo/bar');
-               $folder = new Folder(null, null, '/foo');
+               $file = new Node(null, $this->view, '/foo/bar');
+               $folder = new Folder(null, $this->view, '/foo');
                $this->assertTrue($folder->isSubNode($file));
                $this->assertFalse($folder->isSubNode($folder));
 
-               $file = new Node(null, null, '/foobar');
+               $file = new Node(null, $this->view, '/foobar');
                $this->assertFalse($folder->isSubNode($file));
        }
 
        public function testGetById() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setMethods(['getMountsIn', 'getMount'])
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
@@ -561,10 +520,7 @@ class FolderTest extends NodeTest {
 
        public function testGetByIdMountRoot() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setMethods(['getMountsIn', 'getMount'])
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
@@ -607,10 +563,7 @@ class FolderTest extends NodeTest {
 
        public function testGetByIdOutsideFolder() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setMethods(['getMountsIn', 'getMount'])
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
@@ -652,10 +605,7 @@ class FolderTest extends NodeTest {
 
        public function testGetByIdMultipleStorages() {
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setMethods(['getMountsIn', 'getMount'])
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
@@ -717,10 +667,7 @@ class FolderTest extends NodeTest {
        public function testGetUniqueName($name, $existingFiles, $expected) {
                $manager = $this->createMock(Manager::class);
                $folderPath = '/bar/foo';
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setMethods(['getUser', 'getMountsIn', 'getMount'])
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
@@ -744,10 +691,7 @@ class FolderTest extends NodeTest {
        public function testRecent(): void {
                $manager = $this->createMock(Manager::class);
                $folderPath = '/bar/foo';
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
                $root = $this->getMockBuilder(Root::class)
                        ->setMethods(['getUser', 'getMountsIn', 'getMount'])
@@ -812,10 +756,7 @@ class FolderTest extends NodeTest {
        public function testRecentFolder() {
                $manager = $this->createMock(Manager::class);
                $folderPath = '/bar/foo';
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
                $root = $this->getMockBuilder(Root::class)
                        ->setMethods(['getUser', 'getMountsIn', 'getMount'])
@@ -879,10 +820,7 @@ class FolderTest extends NodeTest {
        public function testRecentJail() {
                $manager = $this->createMock(Manager::class);
                $folderPath = '/bar/foo';
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
                $root = $this->getMockBuilder(Root::class)
                        ->setMethods(['getUser', 'getMountsIn', 'getMount'])
@@ -968,10 +906,7 @@ class FolderTest extends NodeTest {
                }
 
                $manager = $this->createMock(Manager::class);
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->createMock(View::class);
+               $view = $this->getRootViewMock();
                $root = $this->getMockBuilder(Root::class)
                        ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
                        ->getMock();
index 8c0d4cdb293d2b5d749b1325b722b8293f888ace..b63d287a1913f9cbb0142f62dccbcd7248d886f7 100644 (file)
@@ -54,6 +54,9 @@ abstract class NodeTest extends \Test\TestCase {
                $this->view = $this->getMockBuilder(View::class)
                        ->disableOriginalConstructor()
                        ->getMock();
+               $this->view->expects($this->any())
+                       ->method('getRoot')
+                       ->willReturn('');
                $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -65,6 +68,17 @@ abstract class NodeTest extends \Test\TestCase {
                        ->getMock();
        }
 
+       /**
+        * @return \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
+        */
+       protected function getRootViewMock() {
+               $view = $this->createMock(View::class);
+               $view->expects($this->any())
+                       ->method('getRoot')
+                       ->willReturn('');
+               return $view;
+       }
+
        /**
         * @param IRootFolder $root
         * @param View $view
index 5d8e2a4ac62e3f2cca44bf92cdfcb32997ae6b34..aab658c3c36c661c8c77a6f15d8add7b88ef96ad 100644 (file)
@@ -52,6 +52,17 @@ class RootTest extends \Test\TestCase {
                $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
        }
 
+       /**
+        * @return \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
+        */
+       protected function getRootViewMock() {
+               $view = $this->createMock(View::class);
+               $view->expects($this->any())
+                       ->method('getRoot')
+                       ->willReturn('');
+               return $view;
+       }
+
        protected function getFileInfo($data) {
                return new FileInfo('', null, '', $data, null);
        }
@@ -63,12 +74,7 @@ class RootTest extends \Test\TestCase {
                $storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
                        ->disableOriginalConstructor()
                        ->getMock();
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->getMockBuilder(View::class)
-                       ->disableOriginalConstructor()
-                       ->getMock();
+               $view = $this->getRootViewMock();
                $root = new \OC\Files\Node\Root(
                        $this->manager,
                        $view,
@@ -100,12 +106,7 @@ class RootTest extends \Test\TestCase {
                $storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
                        ->disableOriginalConstructor()
                        ->getMock();
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->getMockBuilder(View::class)
-                       ->disableOriginalConstructor()
-                       ->getMock();
+               $view = $this->getRootViewMock();
                $root = new \OC\Files\Node\Root(
                        $this->manager,
                        $view,
@@ -129,12 +130,7 @@ class RootTest extends \Test\TestCase {
        public function testGetInvalidPath() {
                $this->expectException(\OCP\Files\NotPermittedException::class);
 
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->getMockBuilder(View::class)
-                       ->disableOriginalConstructor()
-                       ->getMock();
+               $view = $this->getRootViewMock();
                $root = new \OC\Files\Node\Root(
                        $this->manager,
                        $view,
@@ -152,12 +148,7 @@ class RootTest extends \Test\TestCase {
        public function testGetNoStorages() {
                $this->expectException(\OCP\Files\NotFoundException::class);
 
-               /**
-                * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
-                */
-               $view = $this->getMockBuilder(View::class)
-                       ->disableOriginalConstructor()
-                       ->getMock();
+               $view = $this->getRootViewMock();
                $root = new \OC\Files\Node\Root(
                        $this->manager,
                        $view,
@@ -174,7 +165,7 @@ class RootTest extends \Test\TestCase {
        public function testGetUserFolder() {
                $root = new \OC\Files\Node\Root(
                        $this->manager,
-                       $this->createMock(View::class),
+                       $this->getRootViewMock(),
                        $this->user,
                        $this->userMountCache,
                        $this->logger,
@@ -215,7 +206,7 @@ class RootTest extends \Test\TestCase {
 
                $root = new \OC\Files\Node\Root(
                        $this->createMock(Manager::class),
-                       $this->createMock(View::class),
+                       $this->getRootViewMock(),
                        null,
                        $this->userMountCache,
                        $this->logger,