‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪CropVariantTest extends UnitTestCase
26 {
27  private static array ‪$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(): void
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 
81  #[Test]
82  public function ‪createFromTcaWorks(): void
83  {
84  $cropVariant = ‪CropVariant::createFromConfiguration(self::$expectedConfig['id'], ‪self::$tca);
85  self::assertInstanceOf(CropVariant::class, $cropVariant);
86  self::assertSame(self::$expectedConfig, $cropVariant->asArray());
87  }
88 
89  #[Test]
90  public function ‪selectedRatioCanBeNull(): void
91  {
93  unset(‪$tca['selectedRatio']);
94  self::assertInstanceOf(CropVariant::class, ‪CropVariant::createFromConfiguration(self::$expectedConfig['id'], ‪$tca));
95  }
96 
97  #[Test]
99  {
101  $this->expectException(InvalidConfigurationException::class);
102  ‪$tca['allowedAspectRatios'][0]['value'] = '1.77777777';
103  ‪CropVariant::createFromConfiguration(self::$expectedConfig['id'], ‪$tca);
104  }
105 }
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation
Definition: AreaTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\createFromTcaWorks
‪createFromTcaWorks()
Definition: CropVariantTest.php:82
‪TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariant
Definition: CropVariant.php:23
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\throwsExceptionOnTypeMismatchInRatio
‪throwsExceptionOnTypeMismatchInRatio()
Definition: CropVariantTest.php:98
‪TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariant\createFromConfiguration
‪static createFromConfiguration(string $id, array $config)
Definition: CropVariant.php:88
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\$expectedConfig
‪static $expectedConfig
Definition: CropVariantTest.php:70
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\selectedRatioCanBeNull
‪selectedRatioCanBeNull()
Definition: CropVariantTest.php:90
‪TYPO3\CMS\Core\Imaging\ImageManipulation\InvalidConfigurationException
Definition: InvalidConfigurationException.php:23
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\$tca
‪static array $tca
Definition: CropVariantTest.php:27
‪$tca
‪$tca
Definition: sys_file_metadata.php:5
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest
Definition: CropVariantTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\Imaging\ImageManipulation\CropVariantTest\setUpBeforeClass
‪static setUpBeforeClass()
Definition: CropVariantTest.php:72