‪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 PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
22 use Psr\Container\ContainerInterface;
28 use TYPO3\CMS\Core\Imaging\IconSize;
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
32 final class ‪IconTest extends UnitTestCase
33 {
34  protected ?‪Icon ‪$subject;
35  protected string ‪$iconIdentifier = 'actions-close';
36  protected string ‪$overlayIdentifier = 'overlay-readonly';
37 
38  protected function ‪setUp(): void
39  {
40  parent::setUp();
41  $containerMock = $this->createMock(ContainerInterface::class);
42  $containerMock->method('has')->with(self::anything())->willReturn(false);
43  $iconFactory = new ‪IconFactory(new ‪NoopEventDispatcher(), new ‪IconRegistry(new ‪NullFrontend('test'), 'BackendIcons'), $containerMock);
44  $this->subject = $iconFactory->getIcon($this->iconIdentifier, IconSize::SMALL, $this->overlayIdentifier, ‪IconState::cast(‪IconState::STATE_DISABLED));
45  }
46 
47  #[Test]
49  {
50  self::assertEquals($this->subject->render(), (string)$this->subject);
51  }
52 
53  #[Test]
55  {
56  self::assertEquals($this->iconIdentifier, $this->subject->getIdentifier());
57  }
58 
59  #[Test]
61  {
62  self::assertEquals($this->overlayIdentifier, $this->subject->getOverlayIcon()->getIdentifier());
63  }
64 
65  #[Test]
67  {
68  self::assertEquals(IconSize::SMALL->value, $this->subject->getSize());
69  }
70 
71  public static function ‪setSizeSetsExpectedValuesDataProvider(): \Generator
72  {
73  yield 'SIZE_DEFAULT' => [
75  [16, 16],
76  ];
77  yield 'SIZE_SMALL' => [
79  [16, 16],
80  ];
81  yield 'SIZE_OVERLAY' => [
83  [16, 16],
84  ];
85  yield 'SIZE_MEDIUM' => [
87  [32, 32],
88  ];
89  yield 'SIZE_LARGE' => [
91  [48, 48],
92  ];
93  yield 'SIZE_MEGA' => [
95  [64, 64],
96  ];
97  }
98 
99  #[DataProvider('setSizeSetsExpectedValuesDataProvider')]
100  #[Test]
101  public function ‪setSizeSetsExpectedValues(string $size, array $expectedDimensions): void
102  {
103  $icon = new ‪Icon();
104  $icon->setSize($size);
105 
106  [$width, $height] = $expectedDimensions;
107 
108  self::assertSame($width, $icon->getDimension()->getWidth());
109  self::assertSame($height, $icon->getDimension()->getHeight());
110  }
111 }
‪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:71
‪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:35
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\getIdentifierReturnsCorrectIdentifier
‪getIdentifierReturnsCorrectIdentifier()
Definition: IconTest.php:54
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:190
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\getSizeIdentifierReturnsCorrectIdentifier
‪getSizeIdentifierReturnsCorrectIdentifier()
Definition: IconTest.php:66
‪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:60
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest
Definition: IconTest.php:33
‪TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher
Definition: NoopEventDispatcher.php:29
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\$subject
‪Icon $subject
Definition: IconTest.php:34
‪TYPO3\CMS\Core\Imaging\IconState
‪IconState
Definition: IconState.php:24
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\setUp
‪setUp()
Definition: IconTest.php:38
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Imaging\IconTest\$overlayIdentifier
‪string $overlayIdentifier
Definition: IconTest.php:36
‪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:101