‪TYPO3CMS  ‪main
IconTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Container\ContainerInterface;
26 use TYPO3\CMS\Core\Imaging\IconSize;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
30 final class ‪IconTest extends UnitTestCase
31 {
32  protected ?‪Icon ‪$subject;
33  protected string ‪$iconIdentifier = 'actions-close';
34  protected string ‪$overlayIdentifier = 'overlay-readonly';
35 
36  protected function ‪setUp(): void
37  {
38  parent::setUp();
39  $containerMock = $this->createMock(ContainerInterface::class);
40  $containerMock->method('has')->with(self::anything())->willReturn(false);
41  $iconFactory = new ‪IconFactory(new ‪NoopEventDispatcher(), new ‪IconRegistry(new ‪NullFrontend('test'), 'BackendIcons'), $containerMock);
42  $this->subject = $iconFactory->getIcon($this->iconIdentifier, IconSize::SMALL, $this->overlayIdentifier, ‪IconState::cast(‪IconState::STATE_DISABLED));
43  }
44 
49  {
50  self::assertEquals($this->subject->render(), (string)$this->subject);
51  }
52 
57  {
58  self::assertEquals($this->iconIdentifier, $this->subject->getIdentifier());
59  }
60 
65  {
66  self::assertEquals($this->overlayIdentifier, $this->subject->getOverlayIcon()->getIdentifier());
67  }
68 
73  {
74  self::assertEquals(IconSize::SMALL->value, $this->subject->getSize());
75  }
76 
77  public static function ‪setSizeSetsExpectedValuesDataProvider(): \Generator
78  {
79  yield 'SIZE_DEFAULT' => [
81  [16, 16],
82  ];
83  yield 'SIZE_SMALL' => [
85  [16, 16],
86  ];
87  yield 'SIZE_OVERLAY' => [
89  [16, 16],
90  ];
91  yield 'SIZE_MEDIUM' => [
93  [32, 32],
94  ];
95  yield 'SIZE_LARGE' => [
97  [48, 48],
98  ];
99  yield 'SIZE_MEGA' => [
101  [64, 64],
102  ];
103  }
104 
109  public function ‪setSizeSetsExpectedValues(string $size, array $expectedDimensions): void
110  {
111  $icon = new ‪Icon();
112  $icon->setSize($size);
113 
114  [$width, $height] = $expectedDimensions;
115 
116  self::assertSame($width, $icon->getDimension()->getWidth());
117  self::assertSame($height, $icon->getDimension()->getHeight());
118  }
119 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_DEFAULT
‪const SIZE_DEFAULT
Definition: Icon.php:32
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\setSizeSetsExpectedValuesDataProvider
‪static setSizeSetsExpectedValuesDataProvider()
Definition: IconTest.php:77
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging
Definition: IconTest.php:18
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:27
‪TYPO3\CMS\Core\Type\Icon\IconState\STATE_DISABLED
‪const STATE_DISABLED
Definition: IconState.php:37
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\Cache\Frontend\NullFrontend
Definition: NullFrontend.php:30
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_OVERLAY
‪const SIZE_OVERLAY
Definition: Icon.php:62
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_MEDIUM
‪const SIZE_MEDIUM
Definition: Icon.php:44
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\$iconIdentifier
‪string $iconIdentifier
Definition: IconTest.php:33
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\getIdentifierReturnsCorrectIdentifier
‪getIdentifierReturnsCorrectIdentifier()
Definition: IconTest.php:56
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:186
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\getSizeIdentifierReturnsCorrectIdentifier
‪getSizeIdentifierReturnsCorrectIdentifier()
Definition: IconTest.php:72
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\renderAndCastToStringReturnsTheSameCode
‪renderAndCastToStringReturnsTheSameCode()
Definition: IconTest.php:48
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_MEGA
‪const SIZE_MEGA
Definition: Icon.php:56
‪TYPO3\CMS\Core\Imaging\IconRegistry
Definition: IconRegistry.php:32
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\getOverlayIdentifierReturnsCorrectIdentifier
‪getOverlayIdentifierReturnsCorrectIdentifier()
Definition: IconTest.php:64
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest
Definition: IconTest.php:31
‪TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher
Definition: NoopEventDispatcher.php:29
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\$subject
‪Icon $subject
Definition: IconTest.php:32
‪TYPO3\CMS\Core\Imaging\IconState
‪IconState
Definition: IconState.php:24
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\setUp
‪setUp()
Definition: IconTest.php:36
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\$overlayIdentifier
‪string $overlayIdentifier
Definition: IconTest.php:34
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_LARGE
‪const SIZE_LARGE
Definition: Icon.php:50
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\setSizeSetsExpectedValues
‪setSizeSetsExpectedValues(string $size, array $expectedDimensions)
Definition: IconTest.php:109