Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv authored and PVince81 committed Oct 14, 2022
commit d77e8322239754ef68f9dfe8c3687a39f94cc881
32 changes: 21 additions & 11 deletions apps/theming/tests/ImageManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -65,6 +67,7 @@ protected function setUp(): void {
$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,
Expand All @@ -73,6 +76,11 @@ protected function setUp(): void {
$this->logger,
$this->tempManager
);
$this->appData
->expects($this->any())
->method('getFolder')
->with('global')
->willReturn($this->rootFolder);
}

private function checkImagick() {
Expand Down Expand Up @@ -120,7 +128,7 @@ public function mockGetImage($key, $file) {
->willReturn($newFile);
$newFile->expects($this->once())
->method('putContent');
$this->appData->expects($this->once())
$this->rootFolder->expects($this->once())
->method('getFolder')
->with('images')
->willReturn($folder);
Expand Down Expand Up @@ -200,7 +208,7 @@ public function testGetCacheFolder() {
->method('getAppValue')
->with('theming', 'cachebuster', '0')
->willReturn('0');
$this->appData->expects($this->once())
$this->rootFolder->expects($this->once())
->method('getFolder')
->with('0')
->willReturn($folder);
Expand All @@ -212,18 +220,18 @@ public function testGetCacheFolderCreate() {
->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());
Expand Down Expand Up @@ -291,7 +299,7 @@ private function setupCacheFolder() {
->method('getAppValue')
->with('theming', 'cachebuster', '0')
->willReturn('0');
$this->appData->expects($this->once())
$this->rootFolder->expects($this->once())
->method('getFolder')
->with('0')
->willReturn($folder);
Expand All @@ -316,10 +324,10 @@ public function testCleanup() {
->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]);
Expand All @@ -346,24 +354,26 @@ public function testUpdateImage($key, $tmpFile, $folderExists, $shouldConvert) {
$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)
Expand Down
17 changes: 17 additions & 0 deletions lib/public/Files/SimpleFS/ISimpleFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,21 @@ public function delete(): void;
* @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;
}
19 changes: 19 additions & 0 deletions tests/lib/Files/SimpleFS/SimpleFolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;

Expand Down Expand Up @@ -109,4 +110,22 @@ public function testGetDirectoryListing() {
$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'));
}
}