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