‪TYPO3CMS  ‪main
AreaTest.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;
23 use TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 final class ‪AreaTest extends UnitTestCase
29 {
30  #[Test]
31  public function ‪makeRelativeToFileReducesSizes(): void
32  {
33  $imageArea = new ‪Area(50.0, 50.0, 100.0, 100.0);
34  $imageFixture = new ‪File(
35  [],
36  $this->getMockBuilder(ResourceStorage::class)->disableOriginalConstructor()->getMock(),
37  ['width' => 100, 'height' => 200]
38  );
39  $relativeArea = $imageArea->makeRelativeBasedOnFile($imageFixture);
40  $expectedResult = [
41  'x' => 0.5,
42  'y' => 0.25,
43  'width' => 1.0,
44  'height' => 0.5,
45  ];
46  self::assertSame($expectedResult, $relativeArea->asArray());
47  }
48 
50  {
51  return [
52  [
53  [0.0, 0.0, 1, 1],
54  4 / 3,
55  ],
56  [
57  [0.0, 0.0, 1, 1],
58  3 / 4,
59  ],
60  [
61  [0.1, 0.1, 0.2, 0.4],
62  4 / 3,
63  ],
64  [
65  [0.1, 0.1, 0.4, 0.2],
66  1.0,
67  ],
68  ];
69  }
70 
71  #[DataProvider('applyRatioRestrictsAreaToRespectRatioDataProvider')]
72  #[Test]
73  public function ‪applyRatioRestrictsAreaToRespectRatio(array $areaSize, float $ratio): void
74  {
75  $area = new ‪Area(...$areaSize);
76  $ratioFixture = new Ratio('dummy', 'dummy', $ratio);
77  $areaData = $area->applyRatioRestriction($ratioFixture)->asArray();
78  self::assertSame($areaData['width'] / $areaData['height'], $ratio);
79  }
80 
81  #[Test]
82  public function ‪applyRatioDoesNothingForFreeRatio(): void
83  {
84  $area = new ‪Area(0.1, 0.1, 0.2, 0.4);
85  $ratioFixture = new Ratio('dummy', 'dummy', 0.0);
86  $croppedArea = $area->applyRatioRestriction($ratioFixture);
87  self::assertSame($area, $croppedArea);
88  }
89 }
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation
Definition: AreaTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\AreaTest\applyRatioDoesNothingForFreeRatio
‪applyRatioDoesNothingForFreeRatio()
Definition: AreaTest.php:82
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\AreaTest\applyRatioRestrictsAreaToRespectRatio
‪applyRatioRestrictsAreaToRespectRatio(array $areaSize, float $ratio)
Definition: AreaTest.php:73
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Area
Definition: Area.php:23
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\AreaTest
Definition: AreaTest.php:29
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\AreaTest\makeRelativeToFileReducesSizes
‪makeRelativeToFileReducesSizes()
Definition: AreaTest.php:31
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:129
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\AreaTest\applyRatioRestrictsAreaToRespectRatioDataProvider
‪static applyRatioRestrictsAreaToRespectRatioDataProvider()
Definition: AreaTest.php:49