Fix tests

Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ 2022-10-14 12:19:31 +02:00 committed by Vincent Petry
parent 98a95fb986
commit 3b076350d1
No known key found for this signature in database
GPG key ID: E055D6A4D513575C
3 changed files with 57 additions and 11 deletions

View 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)

View 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;
}

View 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'));
}
}