‪TYPO3CMS  9.5
CropVariantTest.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 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
22 class ‪CropVariantTest extends UnitTestCase
23 {
27  private static ‪$tca = [
28  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.crop_variant.default',
29  'cropArea' => [
30  'x' => 0.0,
31  'y' => 0.0,
32  'width' => 1.0,
33  'height' => 1.0,
34  ],
35  'allowedAspectRatios' => [
36  '16:9' => [
37  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.16_9',
38  'value' => 1.777777777777777
39  ],
40  '4:3' => [
41  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
42  'value' => 1.333333333333333
43  ],
44  '1:1' => [
45  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.1_1',
46  'value' => 1.0
47  ],
48  'free' => [
49  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.free',
50  'value' => 0.0
51  ],
52  ],
53  'selectedRatio' => '16:9',
54  'focusArea' => [
55  'x' => 0.4,
56  'y' => 0.4,
57  'width' => 0.6,
58  'height' => 0.6,
59  ],
60  'coverAreas' => [
61  [
62  'x' => 0.0,
63  'y' => 0.8,
64  'width' => 1.0,
65  'height' => 0.2,
66  ]
67  ],
68  ];
69 
70  private static ‪$expectedConfig = [];
71 
72  public static function ‪setUpBeforeClass()
73  {
74  parent::setUpBeforeClass();
75  self::$expectedConfig = array_merge(['id' => 'default'], ‪self::$tca);
76  foreach (self::$expectedConfig['allowedAspectRatios'] as $id => &$allowedAspectRatio) {
77  $allowedAspectRatio = array_merge(['id' => $id], $allowedAspectRatio);
78  }
79  }
80 
84  public function ‪createFromTcaWorks()
85  {
86  $cropVariant = ‪CropVariant::createFromConfiguration(self::$expectedConfig['id'], ‪self::$tca);
87  $this->assertInstanceOf(CropVariant::class, $cropVariant);
88  $this->assertSame(self::$expectedConfig, $cropVariant->asArray());
89  }
90 
94  public function ‪selectedRatioCanBeNull()
95  {
97  unset(‪$tca['selectedRatio']);
98  $this->assertInstanceOf(CropVariant::class, ‪CropVariant::createFromConfiguration(self::$expectedConfig['id'], ‪$tca));
99  }
100 
105  {
107  $this->expectException(InvalidConfigurationException::class);
108  ‪$tca['allowedAspectRatios'][0]['value'] = '1.77777777';
109  ‪CropVariant::createFromConfiguration(self::$expectedConfig['id'], ‪$tca);
110  }
111 }
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation
Definition: AreaTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\createFromTcaWorks
‪createFromTcaWorks()
Definition: CropVariantTest.php:83
‪TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariant
Definition: CropVariant.php:21
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\throwsExceptionOnTypeMismatchInRatio
‪throwsExceptionOnTypeMismatchInRatio()
Definition: CropVariantTest.php:103
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\$expectedConfig
‪static $expectedConfig
Definition: CropVariantTest.php:69
‪TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariant\createFromConfiguration
‪static CropVariant createFromConfiguration(string $id, array $config)
Definition: CropVariant.php:92
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\selectedRatioCanBeNull
‪selectedRatioCanBeNull()
Definition: CropVariantTest.php:93
‪TYPO3\CMS\Core\Imaging\ImageManipulation\InvalidConfigurationException
Definition: InvalidConfigurationException.php:22
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\$tca
‪static array $tca
Definition: CropVariantTest.php:26
‪$tca
‪$tca
Definition: sys_file_metadata.php:4
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest
Definition: CropVariantTest.php:23
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\setUpBeforeClass
‪static setUpBeforeClass()
Definition: CropVariantTest.php:71