diff options
Diffstat (limited to 'apps/theming/tests/IconBuilderTest.php')
-rw-r--r-- | apps/theming/tests/IconBuilderTest.php | 113 |
1 files changed, 34 insertions, 79 deletions
diff --git a/apps/theming/tests/IconBuilderTest.php b/apps/theming/tests/IconBuilderTest.php index a365f653e4c..d881e4eb75c 100644 --- a/apps/theming/tests/IconBuilderTest.php +++ b/apps/theming/tests/IconBuilderTest.php @@ -1,29 +1,9 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jan-Christoph Borchardt <hey@jancborchardt.net> - * @author Joas Schilling <coding@schilljs.com> - * @author Julius Haertl <jus@bitgrid.net> - * @author Julius Härtl <jus@bitgrid.net> - * @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; @@ -35,25 +15,18 @@ use OCA\Theming\Util; use OCP\App\IAppManager; use OCP\Files\NotFoundException; use OCP\IConfig; -use PHPUnit\Framework\Error\Warning; +use OCP\ServerVersion; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class IconBuilderTest extends TestCase { - - /** @var IConfig */ - protected $config; - /** @var AppData */ - protected $appData; - /** @var ThemingDefaults */ - protected $themingDefaults; - /** @var Util */ - protected $util; - /** @var ImageManager */ - protected $imageManager; - /** @var IconBuilder */ - protected $iconBuilder; - /** @var IAppManager */ - protected $appManager; + protected IConfig&MockObject $config; + protected AppData&MockObject $appData; + protected ThemingDefaults&MockObject $themingDefaults; + protected ImageManager&MockObject $imageManager; + protected IAppManager&MockObject $appManager; + protected Util $util; + protected IconBuilder $iconBuilder; protected function setUp(): void { parent::setUp(); @@ -63,7 +36,7 @@ class IconBuilderTest extends TestCase { $this->themingDefaults = $this->createMock(ThemingDefaults::class); $this->appManager = $this->createMock(IAppManager::class); $this->imageManager = $this->createMock(ImageManager::class); - $this->util = new Util($this->config, $this->appManager, $this->appData); + $this->util = new Util($this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->appData, $this->imageManager); $this->iconBuilder = new IconBuilder($this->themingDefaults, $this->util, $this->imageManager); } @@ -80,7 +53,7 @@ class IconBuilderTest extends TestCase { } } - public function dataRenderAppIcon() { + public static function dataRenderAppIcon(): array { return [ ['core', '#0082c9', 'touch-original.png'], ['core', '#FF0000', 'touch-core-red.png'], @@ -90,23 +63,18 @@ class IconBuilderTest extends TestCase { ]; } - /** - * @dataProvider dataRenderAppIcon - * @param $app - * @param $color - * @param $file - */ - public function testRenderAppIcon($app, $color, $file) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataRenderAppIcon')] + public function testRenderAppIcon(string $app, string $color, string $file): void { $this->checkImagick(); $this->themingDefaults->expects($this->once()) ->method('getColorPrimary') ->willReturn($color); $this->appData->expects($this->once()) ->method('getFolder') - ->with('images') + ->with('global/images') ->willThrowException(new NotFoundException()); - $expectedIcon = new \Imagick(realpath(dirname(__FILE__)). "/data/" . $file); + $expectedIcon = new \Imagick(realpath(__DIR__) . '/data/' . $file); $icon = $this->iconBuilder->renderAppIcon($app, 512); $this->assertEquals(true, $icon->valid()); @@ -119,23 +87,18 @@ class IconBuilderTest extends TestCase { // cloud be something like $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1]) } - /** - * @dataProvider dataRenderAppIcon - * @param $app - * @param $color - * @param $file - */ - public function testGetTouchIcon($app, $color, $file) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataRenderAppIcon')] + public function testGetTouchIcon(string $app, string $color, string $file): void { $this->checkImagick(); $this->themingDefaults->expects($this->once()) ->method('getColorPrimary') ->willReturn($color); $this->appData->expects($this->once()) ->method('getFolder') - ->with('images') + ->with('global/images') ->willThrowException(new NotFoundException()); - $expectedIcon = new \Imagick(realpath(dirname(__FILE__)). "/data/" . $file); + $expectedIcon = new \Imagick(realpath(__DIR__) . '/data/' . $file); $icon = new \Imagick(); $icon->readImageBlob($this->iconBuilder->getTouchIcon($app)); @@ -149,13 +112,8 @@ class IconBuilderTest extends TestCase { // cloud be something like $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1]) } - /** - * @dataProvider dataRenderAppIcon - * @param $app - * @param $color - * @param $file - */ - public function testGetFavicon($app, $color, $file) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataRenderAppIcon')] + public function testGetFavicon(string $app, string $color, string $file): void { $this->checkImagick(); $this->imageManager->expects($this->once()) ->method('shouldReplaceIcons') @@ -165,10 +123,10 @@ class IconBuilderTest extends TestCase { ->willReturn($color); $this->appData->expects($this->once()) ->method('getFolder') - ->with('images') + ->with('global/images') ->willThrowException(new NotFoundException()); - $expectedIcon = new \Imagick(realpath(dirname(__FILE__)). "/data/" . $file); + $expectedIcon = new \Imagick(realpath(__DIR__) . '/data/' . $file); $actualIcon = $this->iconBuilder->getFavicon($app); $icon = new \Imagick(); @@ -184,10 +142,9 @@ class IconBuilderTest extends TestCase { // cloud be something like $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1]) } - public function testGetFaviconNotFound() { + public function testGetFaviconNotFound(): void { $this->checkImagick(); - $this->expectException(Warning::class); - $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock(); + $util = $this->createMock(Util::class); $iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager); $this->imageManager->expects($this->once()) ->method('shouldReplaceIcons') @@ -198,10 +155,9 @@ class IconBuilderTest extends TestCase { $this->assertFalse($iconBuilder->getFavicon('noapp')); } - public function testGetTouchIconNotFound() { + public function testGetTouchIconNotFound(): void { $this->checkImagick(); - $this->expectException(Warning::class); - $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock(); + $util = $this->createMock(Util::class); $iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager); $util->expects($this->once()) ->method('getAppIcon') @@ -209,14 +165,13 @@ class IconBuilderTest extends TestCase { $this->assertFalse($iconBuilder->getTouchIcon('noapp')); } - public function testColorSvgNotFound() { + public function testColorSvgNotFound(): void { $this->checkImagick(); - $this->expectException(Warning::class); - $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock(); + $util = $this->createMock(Util::class); $iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager); $util->expects($this->once()) ->method('getAppImage') ->willReturn('notexistingfile'); - $this->assertFalse($iconBuilder->colorSvg('noapp','noimage')); + $this->assertFalse($iconBuilder->colorSvg('noapp', 'noimage')); } } |