]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix tests
authorJohn Molakvoæ <skjnldsv@protonmail.com>
Fri, 14 Oct 2022 10:19:31 +0000 (12:19 +0200)
committerVincent Petry <vincent@nextcloud.com>
Fri, 14 Oct 2022 14:18:40 +0000 (16:18 +0200)
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
apps/theming/tests/ImageManagerTest.php
lib/public/Files/SimpleFS/ISimpleFolder.php
tests/lib/Files/SimpleFS/SimpleFolderTest.php

index ead9ca113e6f94dab07350dc79fa9ebce17d934b..ffb023c970fc24a50221df458eaffcb77e2afec8 100644 (file)
@@ -56,6 +56,8 @@ class ImageManagerTest extends TestCase {
        private $logger;
        /** @var ITempManager|MockObject */
        private $tempManager;
+       /** @var ISimpleFolder|MockObject */
+       private $rootFolder;
 
        protected function setUp(): void {
                parent::setUp();
@@ -65,6 +67,7 @@ class ImageManagerTest extends TestCase {
                $this->cacheFactory = $this->createMock(ICacheFactory::class);
                $this->logger = $this->createMock(ILogger::class);
                $this->tempManager = $this->createMock(ITempManager::class);
+               $this->rootFolder = $this->createMock(ISimpleFolder::class);
                $this->imageManager = new ImageManager(
                        $this->config,
                        $this->appData,
@@ -73,6 +76,11 @@ class ImageManagerTest extends TestCase {
                        $this->logger,
                        $this->tempManager
                );
+               $this->appData
+                       ->expects($this->any())
+                       ->method('getFolder')
+                       ->with('global')
+                       ->willReturn($this->rootFolder);
        }
 
        private function checkImagick() {
@@ -120,7 +128,7 @@ class ImageManagerTest extends TestCase {
                                ->willReturn($newFile);
                        $newFile->expects($this->once())
                                ->method('putContent');
-                       $this->appData->expects($this->once())
+                       $this->rootFolder->expects($this->once())
                                ->method('getFolder')
                                ->with('images')
                                ->willReturn($folder);
@@ -200,7 +208,7 @@ class ImageManagerTest extends TestCase {
                        ->method('getAppValue')
                        ->with('theming', 'cachebuster', '0')
                        ->willReturn('0');
-               $this->appData->expects($this->once())
+               $this->rootFolder->expects($this->once())
                        ->method('getFolder')
                        ->with('0')
                        ->willReturn($folder);
@@ -212,18 +220,18 @@ class ImageManagerTest extends TestCase {
                        ->method('getAppValue')
                        ->with('theming', 'cachebuster', '0')
                        ->willReturn('0');
-               $this->appData->expects($this->exactly(2))
+               $this->rootFolder->expects($this->exactly(2))
                        ->method('getFolder')
                        ->with('0')
                        ->willReturnOnConsecutiveCalls(
                                $this->throwException(new NotFoundException()),
                                $folder,
                        );
-               $this->appData->expects($this->once())
+               $this->rootFolder->expects($this->once())
                        ->method('newFolder')
                        ->with('0')
                        ->willReturn($folder);
-               $this->appData->expects($this->once())
+               $this->rootFolder->expects($this->once())
                        ->method('getDirectoryListing')
                        ->willReturn([]);
                $this->assertEquals($folder, $this->imageManager->getCacheFolder());
@@ -291,7 +299,7 @@ class ImageManagerTest extends TestCase {
                        ->method('getAppValue')
                        ->with('theming', 'cachebuster', '0')
                        ->willReturn('0');
-               $this->appData->expects($this->once())
+               $this->rootFolder->expects($this->once())
                        ->method('getFolder')
                        ->with('0')
                        ->willReturn($folder);
@@ -316,10 +324,10 @@ class ImageManagerTest extends TestCase {
                        ->method('getAppValue')
                        ->with('theming','cachebuster','0')
                        ->willReturn('2');
-               $this->appData->expects($this->once())
+               $this->rootFolder->expects($this->once())
                        ->method('getDirectoryListing')
                        ->willReturn($folders);
-               $this->appData->expects($this->once())
+               $this->rootFolder->expects($this->once())
                        ->method('getFolder')
                        ->with('2')
                        ->willReturn($folders[2]);
@@ -346,24 +354,26 @@ class ImageManagerTest extends TestCase {
                $folder->expects($this->any())
                        ->method('getFile')
                        ->willReturn($oldFile);
+
                if ($folderExists) {
-                       $this->appData
+                       $this->rootFolder
                                ->expects($this->any())
                                ->method('getFolder')
                                ->with('images')
                                ->willReturn($folder);
                } else {
-                       $this->appData
+                       $this->rootFolder
                                ->expects($this->any())
                                ->method('getFolder')
                                ->with('images')
                                ->willThrowException(new NotFoundException());
-                       $this->appData
+                       $this->rootFolder
                                ->expects($this->any())
                                ->method('newFolder')
                                ->with('images')
                                ->willReturn($folder);
                }
+
                $folder->expects($this->once())
                        ->method('newFile')
                        ->with($key)
index 3c8e6e88ab3586bed9346012880d9aacb5dd9db1..ca60cc4c418cb712e9bfc340f52b961d10a2bba2 100644 (file)
@@ -80,4 +80,21 @@ interface ISimpleFolder {
         * @since 11.0.0
         */
        public function getName(): string;
+
+       /**
+        * Get the folder named $name from the current folder
+        *
+        * @throws NotFoundException
+        * @since 25.0.0
+        */
+       public function getFolder(string $name): ISimpleFolder;
+
+       /**
+        * Creates a new folder with $name in the current folder
+        *
+        * @param string|resource|null $content @since 19.0.0
+        * @throws NotPermittedException
+        * @since 25.0.0
+        */
+       public function newFolder(string $path): ISimpleFolder;
 }
index 50714b8356efb0f03f8d3656e5bd3ec62830bc60..9710b6f438b97fc3bb04b94d7ef89218284760e7 100644 (file)
@@ -28,6 +28,7 @@ use OC\Files\Storage\Temporary;
 use OCP\Files\Folder;
 use OCP\Files\NotFoundException;
 use OCP\Files\SimpleFS\ISimpleFile;
+use OCP\Files\SimpleFS\ISimpleFolder;
 use Test\Traits\MountProviderTrait;
 use Test\Traits\UserTrait;
 
@@ -109,4 +110,22 @@ class SimpleFolderTest extends \Test\TestCase {
                $this->assertInstanceOf(ISimpleFile::class, $result[0]);
                $this->assertInstanceOf(ISimpleFile::class, $result[1]);
        }
+
+       public function testGetFolder() {
+               $this->folder->newFolder('exists');
+
+               $result = $this->simpleFolder->getFolder('exists');
+               $this->assertInstanceOf(ISimpleFolder::class, $result);
+
+               $this->expectException(NotFoundException::class);
+               $this->simpleFolder->getFolder('not-exists');
+       }
+
+       public function testNewFolder() {
+               $result = $this->simpleFolder->newFolder('folder');
+               $this->assertInstanceOf(ISimpleFolder::class, $result);
+               $result->newFile('file');
+
+               $this->assertTrue($this->folder->nodeExists('folder'));
+       }
 }