summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2022-10-14 12:19:31 +0200
committerVincent Petry <vincent@nextcloud.com>2022-10-14 16:18:40 +0200
commitd77e8322239754ef68f9dfe8c3687a39f94cc881 (patch)
treebfec4e1003e0fe5fc77298094e36d246898b78d5
parentac21c631a61fbc7042c787a5feb0cb9aa489af91 (diff)
downloadnextcloud-server-d77e8322239754ef68f9dfe8c3687a39f94cc881.tar.gz
nextcloud-server-d77e8322239754ef68f9dfe8c3687a39f94cc881.zip
Fix tests
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
-rw-r--r--apps/theming/tests/ImageManagerTest.php32
-rw-r--r--lib/public/Files/SimpleFS/ISimpleFolder.php17
-rw-r--r--tests/lib/Files/SimpleFS/SimpleFolderTest.php19
3 files changed, 57 insertions, 11 deletions
diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php
index ead9ca113e6..ffb023c970f 100644
--- a/apps/theming/tests/ImageManagerTest.php
+++ b/apps/theming/tests/ImageManagerTest.php
@@ -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)
diff --git a/lib/public/Files/SimpleFS/ISimpleFolder.php b/lib/public/Files/SimpleFS/ISimpleFolder.php
index 3c8e6e88ab3..ca60cc4c418 100644
--- a/lib/public/Files/SimpleFS/ISimpleFolder.php
+++ b/lib/public/Files/SimpleFS/ISimpleFolder.php
@@ -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;
}
diff --git a/tests/lib/Files/SimpleFS/SimpleFolderTest.php b/tests/lib/Files/SimpleFS/SimpleFolderTest.php
index 50714b8356e..9710b6f438b 100644
--- a/tests/lib/Files/SimpleFS/SimpleFolderTest.php
+++ b/tests/lib/Files/SimpleFS/SimpleFolderTest.php
@@ -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'));
+ }
}