diff options
Diffstat (limited to 'apps/theming/tests/ImageManagerTest.php')
-rw-r--r-- | apps/theming/tests/ImageManagerTest.php | 135 |
1 files changed, 50 insertions, 85 deletions
diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php index 8d42e892448..0c4d555cc00 100644 --- a/apps/theming/tests/ImageManagerTest.php +++ b/apps/theming/tests/ImageManagerTest.php @@ -1,33 +1,14 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Julius Haertl <jus@bitgrid.net> - * @author Julius Härtl <jus@bitgrid.net> - * @author Michael Weimann <mail@michael-weimann.eu> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Theming\Tests; use OCA\Theming\ImageManager; +use OCA\Theming\Service\BackgroundService; use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; @@ -41,22 +22,14 @@ use Psr\Log\LoggerInterface; use Test\TestCase; class ImageManagerTest extends TestCase { - /** @var IConfig|MockObject */ - protected $config; - /** @var IAppData|MockObject */ - protected $appData; - /** @var ImageManager */ - protected $imageManager; - /** @var IURLGenerator|MockObject */ - private $urlGenerator; - /** @var ICacheFactory|MockObject */ - private $cacheFactory; - /** @var LoggerInterface|MockObject */ - private $logger; - /** @var ITempManager|MockObject */ - private $tempManager; - /** @var ISimpleFolder|MockObject */ - private $rootFolder; + protected IConfig&MockObject $config; + protected IAppData&MockObject $appData; + private IURLGenerator&MockObject $urlGenerator; + private ICacheFactory&MockObject $cacheFactory; + private LoggerInterface&MockObject $logger; + private ITempManager&MockObject $tempManager; + private ISimpleFolder&MockObject $rootFolder; + protected ImageManager $imageManager; protected function setUp(): void { parent::setUp(); @@ -67,13 +40,15 @@ class ImageManagerTest extends TestCase { $this->logger = $this->createMock(LoggerInterface::class); $this->tempManager = $this->createMock(ITempManager::class); $this->rootFolder = $this->createMock(ISimpleFolder::class); + $backgroundService = $this->createMock(BackgroundService::class); $this->imageManager = new ImageManager( $this->config, $this->appData, $this->urlGenerator, $this->cacheFactory, $this->logger, - $this->tempManager + $this->tempManager, + $backgroundService, ); $this->appData ->expects($this->any()) @@ -109,13 +84,10 @@ class ImageManagerTest extends TestCase { ->willReturn(file_get_contents(__DIR__ . '/../../../tests/data/testimage.png')); $folder->expects($this->exactly(2)) ->method('fileExists') - ->withConsecutive( - ['logo'], - ['logo.png'], - )->willReturnOnConsecutiveCalls( - true, - false, - ); + ->willReturnMap([ + ['logo', true], + ['logo.png', false], + ]); $folder->expects($this->once()) ->method('getFile') ->with('logo') @@ -134,30 +106,27 @@ class ImageManagerTest extends TestCase { } } - public function testGetImageUrl() { + public function testGetImageUrl(): void { $this->checkImagick(); - $file = $this->createMock(ISimpleFile::class); $this->config->expects($this->exactly(2)) ->method('getAppValue') - ->withConsecutive( - ['theming', 'cachebuster', '0'], - ['theming', 'logoMime', ''] - ) - ->willReturn(0); + ->willReturnMap([ + ['theming', 'cachebuster', '0', '0'], + ['theming', 'logoMime', '', '0'], + ]); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') ->willReturn('url-to-image'); $this->assertEquals('url-to-image?v=0', $this->imageManager->getImageUrl('logo', false)); } - public function testGetImageUrlDefault() { + public function testGetImageUrlDefault(): void { $this->config->expects($this->exactly(2)) ->method('getAppValue') - ->withConsecutive( - ['theming', 'cachebuster', '0'], - ['theming', 'logoMime', ''] - ) - ->willReturnOnConsecutiveCalls(0, ''); + ->willReturnMap([ + ['theming', 'cachebuster', '0', '0'], + ['theming', 'logoMime', '', ''], + ]); $this->urlGenerator->expects($this->once()) ->method('imagePath') ->with('core', 'logo/logo.png') @@ -165,23 +134,21 @@ class ImageManagerTest extends TestCase { $this->assertEquals('logo/logo.png?v=0', $this->imageManager->getImageUrl('logo')); } - public function testGetImageUrlAbsolute() { + public function testGetImageUrlAbsolute(): void { $this->checkImagick(); - $file = $this->createMock(ISimpleFile::class); $this->config->expects($this->exactly(2)) ->method('getAppValue') - ->withConsecutive( - ['theming', 'cachebuster', '0'], - ['theming', 'logoMime', ''] - ) - ->willReturnOnConsecutiveCalls(0, 0); + ->willReturnMap([ + ['theming', 'cachebuster', '0', '0'], + ['theming', 'logoMime', '', ''], + ]); $this->urlGenerator->expects($this->any()) ->method('getAbsoluteUrl') ->willReturn('url-to-image-absolute?v=0'); $this->assertEquals('url-to-image-absolute?v=0', $this->imageManager->getImageUrlAbsolute('logo', false)); } - public function testGetImage() { + public function testGetImage(): void { $this->checkImagick(); $this->config->expects($this->once()) ->method('getAppValue')->with('theming', 'logoMime', false) @@ -192,8 +159,8 @@ class ImageManagerTest extends TestCase { } - public function testGetImageUnset() { - $this->expectException(\OCP\Files\NotFoundException::class); + public function testGetImageUnset(): void { + $this->expectException(NotFoundException::class); $this->config->expects($this->once()) ->method('getAppValue')->with('theming', 'logoMime', false) @@ -201,7 +168,7 @@ class ImageManagerTest extends TestCase { $this->imageManager->getImage('logo'); } - public function testGetCacheFolder() { + public function testGetCacheFolder(): void { $folder = $this->createMock(ISimpleFolder::class); $this->config->expects($this->once()) ->method('getAppValue') @@ -213,7 +180,7 @@ class ImageManagerTest extends TestCase { ->willReturn($folder); $this->assertEquals($folder, $this->imageManager->getCacheFolder()); } - public function testGetCacheFolderCreate() { + public function testGetCacheFolderCreate(): void { $folder = $this->createMock(ISimpleFolder::class); $this->config->expects($this->exactly(2)) ->method('getAppValue') @@ -236,7 +203,7 @@ class ImageManagerTest extends TestCase { $this->assertEquals($folder, $this->imageManager->getCacheFolder()); } - public function testGetCachedImage() { + public function testGetCachedImage(): void { $expected = $this->createMock(ISimpleFile::class); $folder = $this->setupCacheFolder(); $folder->expects($this->once()) @@ -247,18 +214,18 @@ class ImageManagerTest extends TestCase { } - public function testGetCachedImageNotFound() { - $this->expectException(\OCP\Files\NotFoundException::class); + public function testGetCachedImageNotFound(): void { + $this->expectException(NotFoundException::class); $folder = $this->setupCacheFolder(); $folder->expects($this->once()) ->method('getFile') ->with('filename') - ->will($this->throwException(new \OCP\Files\NotFoundException())); + ->willThrowException(new NotFoundException()); $image = $this->imageManager->getCachedImage('filename'); } - public function testSetCachedImage() { + public function testSetCachedImage(): void { $folder = $this->setupCacheFolder(); $file = $this->createMock(ISimpleFile::class); $folder->expects($this->once()) @@ -275,7 +242,7 @@ class ImageManagerTest extends TestCase { $this->assertEquals($file, $this->imageManager->setCachedImage('filename', 'filecontent')); } - public function testSetCachedImageCreate() { + public function testSetCachedImageCreate(): void { $folder = $this->setupCacheFolder(); $file = $this->createMock(ISimpleFile::class); $folder->expects($this->once()) @@ -305,7 +272,7 @@ class ImageManagerTest extends TestCase { return $folder; } - public function testCleanup() { + public function testCleanup(): void { $folders = [ $this->createMock(ISimpleFolder::class), $this->createMock(ISimpleFolder::class), @@ -334,7 +301,7 @@ class ImageManagerTest extends TestCase { } - public function dataUpdateImage() { + public static function dataUpdateImage(): array { return [ ['background', __DIR__ . '/../../../tests/data/testimage.png', true, false], ['background', __DIR__ . '/../../../tests/data/testimage.png', false, false], @@ -346,10 +313,8 @@ class ImageManagerTest extends TestCase { ]; } - /** - * @dataProvider dataUpdateImage - */ - public function testUpdateImage($key, $tmpFile, $folderExists, $shouldConvert) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateImage')] + public function testUpdateImage(string $key, string $tmpFile, bool $folderExists, bool $shouldConvert): void { $file = $this->createMock(ISimpleFile::class); $folder = $this->createMock(ISimpleFolder::class); $oldFile = $this->createMock(ISimpleFile::class); |