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