Skip to content

Commit

Permalink
[BUGFIX] Add missing Icon::SIZE_MEGA constant
Browse files Browse the repository at this point in the history
The Icon API in general knows the icon size "mega", which renders an
icon in the dimensions 64x64. However, the according constant was absent
in the `Icon` class, which is now added.

Resolves: #101431
Releases: main, 12.4
Change-Id: Ib889a1f8862591a4c78453ac24e15ce869781715
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80135
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
  • Loading branch information
andreaskienast committed Jul 25, 2023
1 parent b60bc41 commit 86ce60b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions typo3/sysext/core/Classes/Imaging/Dimension.php
Expand Up @@ -40,6 +40,9 @@ class Dimension
public function __construct($size = Icon::SIZE_MEDIUM)
{
switch ($size) {
case Icon::SIZE_MEGA:
$sizeInPixel = 64;
break;
case Icon::SIZE_LARGE:
$sizeInPixel = 48;
break;
Expand Down
5 changes: 5 additions & 0 deletions typo3/sysext/core/Classes/Imaging/Icon.php
Expand Up @@ -46,6 +46,11 @@ class Icon
*/
public const SIZE_LARGE = 'large'; // 48px

/**
* @var string the mega size
*/
public const SIZE_MEGA = 'mega'; // 64px

/**
* @internal
* @var string the overlay size, which depends on icon size
Expand Down
43 changes: 43 additions & 0 deletions typo3/sysext/core/Tests/Unit/Imaging/IconTest.php
Expand Up @@ -80,4 +80,47 @@ public function getStateReturnsCorrectIdentifier(): void
{
self::assertTrue($this->subject->getState()->equals(IconState::STATE_DISABLED));
}

public static function setSizeSetsExpectedValuesDataProvider(): \Generator
{
yield 'SIZE_DEFAULT' => [
Icon::SIZE_DEFAULT,
[16, 16],
];
yield 'SIZE_SMALL' => [
Icon::SIZE_DEFAULT,
[16, 16],
];
yield 'SIZE_OVERLAY' => [
Icon::SIZE_OVERLAY,
[16, 16],
];
yield 'SIZE_MEDIUM' => [
Icon::SIZE_MEDIUM,
[32, 32],
];
yield 'SIZE_LARGE' => [
Icon::SIZE_LARGE,
[48, 48],
];
yield 'SIZE_MEGA' => [
Icon::SIZE_MEGA,
[64, 64],
];
}

/**
* @test
* @dataProvider setSizeSetsExpectedValuesDataProvider
*/
public function setSizeSetsExpectedValues(string $size, array $expectedDimensions): void
{
$icon = new Icon();
$icon->setSize($size);

[$width, $height] = $expectedDimensions;

self::assertSame($width, $icon->getDimension()->getWidth());
self::assertSame($height, $icon->getDimension()->getHeight());
}
}

0 comments on commit 86ce60b

Please sign in to comment.