‪TYPO3CMS  10.4
CropVariantTest.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 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
24 class ‪CropVariantTest 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 
72  private static ‪$expectedConfig = [];
73 
74  public static function ‪setUpBeforeClass(): void
75  {
76  parent::setUpBeforeClass();
77  self::$expectedConfig = array_merge(['id' => 'default'], ‪self::$tca);
78  foreach (self::$expectedConfig['allowedAspectRatios'] as $id => &$allowedAspectRatio) {
79  $allowedAspectRatio = array_merge(['id' => $id], $allowedAspectRatio);
80  }
81  }
82 
86  public function ‪createFromTcaWorks()
87  {
88  $cropVariant = ‪CropVariant::createFromConfiguration(self::$expectedConfig['id'], ‪self::$tca);
89  self::assertInstanceOf(CropVariant::class, $cropVariant);
90  self::assertSame(self::$expectedConfig, $cropVariant->asArray());
91  }
92 
96  public function ‪selectedRatioCanBeNull()
97  {
99  unset(‪$tca['selectedRatio']);
100  self::assertInstanceOf(CropVariant::class, ‪CropVariant::createFromConfiguration(self::$expectedConfig['id'], ‪$tca));
101  }
102 
107  {
109  $this->expectException(InvalidConfigurationException::class);
110  ‪$tca['allowedAspectRatios'][0]['value'] = '1.77777777';
111  ‪CropVariant::createFromConfiguration(self::$expectedConfig['id'], ‪$tca);
112  }
113 }
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation
Definition: AreaTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\createFromTcaWorks
‪createFromTcaWorks()
Definition: CropVariantTest.php:85
‪TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariant
Definition: CropVariant.php:23
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\throwsExceptionOnTypeMismatchInRatio
‪throwsExceptionOnTypeMismatchInRatio()
Definition: CropVariantTest.php:105
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\$expectedConfig
‪static $expectedConfig
Definition: CropVariantTest.php:71
‪TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariant\createFromConfiguration
‪static CropVariant createFromConfiguration(string $id, array $config)
Definition: CropVariant.php:94
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\selectedRatioCanBeNull
‪selectedRatioCanBeNull()
Definition: CropVariantTest.php:95
‪TYPO3\CMS\Core\Imaging\ImageManipulation\InvalidConfigurationException
Definition: InvalidConfigurationException.php:24
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\$tca
‪static array $tca
Definition: CropVariantTest.php:28
‪$tca
‪$tca
Definition: sys_file_metadata.php:5
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest
Definition: CropVariantTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\setUpBeforeClass
‪static setUpBeforeClass()
Definition: CropVariantTest.php:73