[TASK] Make AreaTest notice free
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Imaging / ImageManipulation / AreaTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation;
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
18 use TYPO3\CMS\Core\Imaging\ImageManipulation\Area;
19 use TYPO3\CMS\Core\Imaging\ImageManipulation\Ratio;
20 use TYPO3\CMS\Core\Resource\File;
21 use TYPO3\CMS\Core\Resource\ResourceStorage;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23
24 class AreaTest extends UnitTestCase
25 {
26 /**
27 * @test
28 */
29 public function makeRelativeToFileReducesSizes(): void
30 {
31 $imageArea = new Area(50.0, 50.0, 100.0, 100.0);
32 $imageFixture = new File(
33 [],
34 $this->getMockBuilder(ResourceStorage::class)->disableOriginalConstructor()->getMock(),
35 ['width' => 100, 'height' => 200]
36 );
37 $relativeArea = $imageArea->makeRelativeBasedOnFile($imageFixture);
38 $expectedResult = [
39 'x' => 0.5,
40 'y' => 0.25,
41 'width' => 1.0,
42 'height' => 0.5,
43 ];
44 $this->assertSame($expectedResult, $relativeArea->asArray());
45 }
46
47 public function applyRatioRestrictsAreaToRespectRatioDataProvider(): array
48 {
49 return [
50 [
51 [0.0, 0.0, 1, 1],
52 4 / 3
53 ],
54 [
55 [0.0, 0.0, 1, 1],
56 3 / 4
57 ],
58 [
59 [0.1, 0.1, 0.2, 0.4],
60 4 / 3,
61 ],
62 [
63 [0.1, 0.1, 0.4, 0.2],
64 1.0
65 ],
66 ];
67 }
68
69 /**
70 * @param array $areaSize
71 * @param $ratio
72 * @test
73 * @dataProvider applyRatioRestrictsAreaToRespectRatioDataProvider
74 */
75 public function applyRatioRestrictsAreaToRespectRatio(array $areaSize, $ratio): void
76 {
77 $area = new Area(...$areaSize);
78 $ratioFixture = new Ratio('dummy', 'dummy', $ratio);
79 $areaData = $area->applyRatioRestriction($ratioFixture)->asArray();
80 $this->assertSame($areaData['width'] / $areaData['height'], $ratio);
81 }
82
83 /**
84 * @test
85 */
86 public function applyRatioDoesNothingForFreeRatio(): void
87 {
88 $area = new Area(0.1, 0.1, 0.2, 0.4);
89 $ratioFixture = new Ratio('dummy', 'dummy', 0.0);
90 $croppedArea = $area->applyRatioRestriction($ratioFixture);
91 $this->assertSame($area, $croppedArea);
92 }
93 }