Skip to content
Snippets Groups Projects
Commit 79c01f89 authored by Nikita Hovratov's avatar Nikita Hovratov Committed by Stefan Bürk
Browse files

[TASK] Replace prophecy in EXT:core/Tests/Unit/Imaging/*

Resolves: #98755
Resolves: #98756
Releases: main
Change-Id: If8484ba37f25cceb7a2d35dfc22717d95c122716
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76576


Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarOliver Klee <typo3-coding@oliverklee.de>
Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: default avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
parent c8a0ed4b
Branches
Tags
No related merge requests found
......@@ -17,10 +17,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Tests\Unit\Imaging;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Cache\Frontend\NullFrontend;
use TYPO3\CMS\Core\Exception;
use TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider;
use TYPO3\CMS\Core\Imaging\IconProviderInterface;
......@@ -30,30 +27,12 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
class IconRegistryTest extends UnitTestCase
{
use ProphecyTrait;
/**
* @var string
*/
protected string $notRegisteredIconIdentifier = 'my-super-unregistered-identifier';
/** @var ObjectProphecy<FrontendInterface> */
protected ObjectProphecy $cacheFrontendProphecy;
public function setUp(): void
{
parent::setUp();
$this->cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
$this->cacheFrontendProphecy->get(Argument::cetera())->willReturn(false);
$this->cacheFrontendProphecy->set(Argument::cetera())->willReturn(null);
}
/**
* @test
*/
public function getDefaultIconIdentifierReturnsTheCorrectDefaultIconIdentifierString(): void
{
$result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getDefaultIconIdentifier();
$result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getDefaultIconIdentifier();
self::assertEquals('default-not-found', $result);
}
......@@ -62,7 +41,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function isRegisteredReturnsTrueForRegisteredIcon(): void
{
$subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons');
$subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons');
$result = $subject->isRegistered($subject->getDefaultIconIdentifier());
self::assertTrue($result);
}
......@@ -72,7 +51,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function isRegisteredReturnsFalseForNotRegisteredIcon(): void
{
$result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->isRegistered($this->notRegisteredIconIdentifier);
$result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->isRegistered('my-super-unregistered-identifier');
self::assertFalse($result);
}
......@@ -82,7 +61,7 @@ class IconRegistryTest extends UnitTestCase
public function registerIconAddNewIconToRegistry(): void
{
$unregisteredIcon = 'foo-bar-unregistered';
$subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons');
$subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons');
self::assertFalse($subject->isRegistered($unregisteredIcon));
$subject->registerIcon($unregisteredIcon, BitmapIconProvider::class, [
'name' => 'pencil',
......@@ -99,7 +78,7 @@ class IconRegistryTest extends UnitTestCase
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1437425803);
(new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->registerIcon($this->notRegisteredIconIdentifier, GeneralUtility::class);
(new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->registerIcon('my-super-unregistered-identifier', GeneralUtility::class);
}
/**
......@@ -110,7 +89,7 @@ class IconRegistryTest extends UnitTestCase
$this->expectException(Exception::class);
$this->expectExceptionCode(1437425804);
(new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconConfigurationByIdentifier($this->notRegisteredIconIdentifier);
(new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconConfigurationByIdentifier('my-super-unregistered-identifier');
}
/**
......@@ -118,7 +97,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function getIconConfigurationByIdentifierReturnsCorrectConfiguration(): void
{
$result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconConfigurationByIdentifier('default-not-found');
$result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconConfigurationByIdentifier('default-not-found');
// result must contain at least provider and options array
self::assertArrayHasKey('provider', $result);
self::assertArrayHasKey('options', $result);
......@@ -131,7 +110,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function getAllRegisteredIconIdentifiersReturnsAnArrayWithIconIdentifiers(): void
{
self::assertIsArray((new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getAllRegisteredIconIdentifiers());
self::assertIsArray((new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getAllRegisteredIconIdentifiers());
}
/**
......@@ -139,7 +118,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function getAllRegisteredIconIdentifiersReturnsArrayWithAllRegisteredIconIdentifiers(): void
{
$result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getAllRegisteredIconIdentifiers();
$result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getAllRegisteredIconIdentifiers();
self::assertIsArray($result);
self::assertContains('default-not-found', $result);
}
......@@ -149,7 +128,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForEmptyFileExtension(): void
{
$result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconIdentifierForFileExtension('');
$result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconIdentifierForFileExtension('');
self::assertEquals('mimetypes-other-other', $result);
}
......@@ -158,7 +137,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForUnknownFileExtension(): void
{
$result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconIdentifierForFileExtension('xyz');
$result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconIdentifierForFileExtension('xyz');
self::assertEquals('mimetypes-other-other', $result);
}
......@@ -167,7 +146,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function getIconIdentifierForFileExtensionReturnsImageIconIdentifierForImageFileExtension(): void
{
$result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconIdentifierForFileExtension('jpg');
$result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconIdentifierForFileExtension('jpg');
self::assertEquals('mimetypes-media-image', $result);
}
......@@ -176,7 +155,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function registerFileExtensionRegisterAnIcon(): void
{
$subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons');
$subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons');
$subject->registerFileExtension('abc', 'xyz');
$result = $subject->getIconIdentifierForFileExtension('abc');
self::assertEquals('xyz', $result);
......@@ -187,7 +166,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function registerFileExtensionOverwriteAnExistingIcon(): void
{
$subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons');
$subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons');
$subject->registerFileExtension('jpg', 'xyz');
$result = $subject->getIconIdentifierForFileExtension('jpg');
self::assertEquals('xyz', $result);
......@@ -198,7 +177,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function registerMimeTypeIconRegisterAnIcon(): void
{
$subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons');
$subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons');
$subject->registerMimeTypeIcon('foo/bar', 'mimetype-foo-bar');
$result = $subject->getIconIdentifierForMimeType('foo/bar');
self::assertEquals('mimetype-foo-bar', $result);
......@@ -209,7 +188,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function registerMimeTypeIconOverwriteAnExistingIcon(): void
{
$subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons');
$subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons');
$subject->registerMimeTypeIcon('video/*', 'mimetype-foo-bar');
$result = $subject->getIconIdentifierForMimeType('video/*');
self::assertEquals('mimetype-foo-bar', $result);
......@@ -220,7 +199,7 @@ class IconRegistryTest extends UnitTestCase
*/
public function getIconIdentifierForMimeTypeWithUnknownMimeTypeReturnNull(): void
{
$result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconIdentifierForMimeType('bar/foo');
$result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconIdentifierForMimeType('bar/foo');
self::assertNull($result);
}
}
......@@ -17,11 +17,9 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Tests\Unit\Imaging;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Cache\Frontend\NullFrontend;
use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconRegistry;
......@@ -30,25 +28,16 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
class IconTest extends UnitTestCase
{
use ProphecyTrait;
protected ?Icon $subject;
protected string $iconIdentifier = 'actions-close';
protected string $overlayIdentifier = 'overlay-readonly';
/**
* Set up
*/
protected function setUp(): void
{
parent::setUp();
$cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
$cacheFrontendProphecy->get(Argument::cetera())->willReturn(false);
$cacheFrontendProphecy->set(Argument::cetera())->willReturn(null);
$eventDispatcherProphecy = $this->prophesize(EventDispatcherInterface::class);
$containerProphecy = $this->prophesize(ContainerInterface::class);
$containerProphecy->has(Argument::cetera())->willReturn(false);
$iconFactory = new IconFactory($eventDispatcherProphecy->reveal(), new IconRegistry($cacheFrontendProphecy->reveal(), 'BackendIcons'), $containerProphecy->reveal());
$containerMock = $this->createMock(ContainerInterface::class);
$containerMock->method('has')->with(self::anything())->willReturn(false);
$iconFactory = new IconFactory(new NoopEventDispatcher(), new IconRegistry(new NullFrontend('test'), 'BackendIcons'), $containerMock);
$this->subject = $iconFactory->getIcon($this->iconIdentifier, Icon::SIZE_SMALL, $this->overlayIdentifier, IconState::cast(IconState::STATE_DISABLED));
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment