‪TYPO3CMS  11.5
CropVariantCollectionTest.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 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 class ‪CropVariantCollectionTest extends UnitTestCase
27 {
28  private static array ‪$tca = [
29  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.crop_variant.default',
30  'cropArea' => [
31  'x' => 0.0,
32  'y' => 0.0,
33  'width' => 1.0,
34  'height' => 1.0,
35  ],
36  'allowedAspectRatios' => [
37  '16:9' => [
38  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.16_9',
39  'value' => 1.777777777777777,
40  ],
41  '4:3' => [
42  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
43  'value' => 1.333333333333333,
44  ],
45  '1:1' => [
46  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.1_1',
47  'value' => 1.0,
48  ],
49  'free' => [
50  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.free',
51  'value' => 0.0,
52  ],
53  ],
54  'selectedRatio' => '16:9',
55  'focusArea' => [
56  'x' => 0.4,
57  'y' => 0.4,
58  'width' => 0.6,
59  'height' => 0.6,
60  ],
61  'coverAreas' => [
62  [
63  'x' => 0.0,
64  'y' => 0.8,
65  'width' => 1.0,
66  'height' => 0.2,
67  ],
68  ],
69  ];
70 
74  public function ‪createFromJsonWorks(): void
75  {
76  $cropVariant1 = ‪self::$tca;
77  $cropVariant2 = ‪self::$tca;
78  $cropVariantCollection = ‪CropVariantCollection::create(json_encode(['default' => $cropVariant1, 'Second' => $cropVariant2]));
79  self::assertInstanceOf(CropVariantCollection::class, $cropVariantCollection);
80 
81  $assertSameValues = function ($expected, $actual) use (&$assertSameValues) {
82  if (is_array($expected)) {
83  foreach ($expected as $key => $value) {
84  $this->assertArrayHasKey($key, $actual);
85  $assertSameValues($expected[$key], $actual[$key]);
86  }
87  } else {
88  $this->assertSame($expected, $actual);
89  }
90  };
91  // assertSame does not work here, because the fuzz for float is not applied for array values
92  $assertSameValues(['default' => $cropVariant1, 'Second' => $cropVariant2], $cropVariantCollection->asArray());
93  }
94 
98  public function ‪duplicateIdThrowsException(): void
99  {
100  $this->expectException(InvalidConfigurationException::class);
101  $cropVariant1 = new ‪CropVariant('foo', 'title 1', new ‪Area(0.0, 0.0, 1.0, 1.0));
102  $cropVariant2 = new ‪CropVariant('foo', 'title 2', new ‪Area(0.0, 0.0, 0.5, 0.5));
103  new ‪CropVariantCollection([$cropVariant1, $cropVariant2]);
104  }
105 
109  public function ‪createEmptyWorks(): void
110  {
111  self::assertTrue(‪CropVariantCollection::create('')->getCropArea()->isEmpty());
112  }
113 
118  {
119  $variants = new ‪CropVariantCollection([]);
120  self::assertSame('[]', (string)$variants);
121  }
122 }
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation
Definition: AreaTest.php:18
‪TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariant
Definition: CropVariant.php:23
‪TYPO3\CMS\Core\Imaging\ImageManipulation\Area
Definition: Area.php:23
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantCollectionTest\castToStringReturnsJsonArrayOnEmptyInput
‪castToStringReturnsJsonArrayOnEmptyInput()
Definition: CropVariantCollectionTest.php:117
‪TYPO3\CMS\Core\Imaging\ImageManipulation\InvalidConfigurationException
Definition: InvalidConfigurationException.php:23
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantCollectionTest\createEmptyWorks
‪createEmptyWorks()
Definition: CropVariantCollectionTest.php:109
‪TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection
Definition: CropVariantCollection.php:23
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantCollectionTest\duplicateIdThrowsException
‪duplicateIdThrowsException()
Definition: CropVariantCollectionTest.php:98
‪TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection\create
‪static CropVariantCollection create(string $jsonString, array $tcaConfig=[])
Definition: CropVariantCollection.php:42
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantCollectionTest\createFromJsonWorks
‪createFromJsonWorks()
Definition: CropVariantCollectionTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantCollectionTest\$tca
‪static array $tca
Definition: CropVariantCollectionTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantCollectionTest
Definition: CropVariantCollectionTest.php:27