‪TYPO3CMS  11.5
GraphicalFunctionsTest.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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
23 class ‪GraphicalFunctionsTest extends UnitTestCase
24 {
25  protected ‪$resetSingletonInstances = true;
26 
32  public function ‪getScaleForImageDataProvider(): array
33  {
34  return [
35  'Get image scale for a width of 150px' => [
36  [
37  170,
38  136,
39  ],
40  '150',
41  '',
42  [],
43  [
44  'crs' => false,
45  'origW' => 150,
46  'origH' => 0,
47  'max' => 0,
48  0 => 150,
49  1 => 120,
50  ],
51  ],
52  'Get image scale with a maximum width of 100px' => [
53  [
54  170,
55  136,
56  ],
57  '',
58  '',
59  [
60  'maxW' => 100,
61  ],
62  [
63  'crs' => false,
64  'origW' => 100,
65  'origH' => 0,
66  'max' => 1,
67  0 => 100,
68  1 => 80,
69  ],
70  ],
71  'Get image scale with a minimum width of 200px' => [
72  [
73  170,
74  136,
75  ],
76  '',
77  '',
78  [
79  'minW' => 200,
80  ],
81  [
82  'crs' => false,
83  'origW' => 0,
84  'origH' => 0,
85  'max' => 0,
86  0 => 200,
87  1 => 136,
88  ],
89  ],
90  'No PHP warning for zero in input dimensions when scaling' => [
91  [0, 0],
92  '50',
93  '',
94  [],
95  [
96  'crs' => false,
97  'origW' => 50,
98  'origH' => 0,
99  'max' => 0,
100  0 => 0,
101  1 => 0,
102  ],
103  ],
104  ];
105  }
106 
111  public function ‪getScaleForImage($info, $width, $height, $options, $expected): void
112  {
113  $result = (new ‪GraphicalFunctions())->getImageScale($info, $width, $height, $options);
114  self::assertSame($result, $expected);
115  }
116 
121  {
122  $file = 'myImageFile.png';
123  $expected = [
124  '123',
125  '234',
126  'png',
127  'myImageFile.png',
128  'png',
129  ];
130 
131  $subject = $this->getAccessibleMock(GraphicalFunctions::class, ['executeIdentifyCommandForImageFile'], [], '', false);
132  $subject->_set('processorEnabled', true);
133  $subject->expects(self::once())->method('executeIdentifyCommandForImageFile')->with($file)->willReturn('123 234 png PNG');
134  $result = $subject->imageMagickIdentify($file);
135  self::assertEquals($result, $expected);
136  }
137 
142  {
143  $file = 'myImageFile.png';
144  $expected = [
145  '200+0+0',
146  '400+0+0',
147  'png',
148  'myImageFile.png',
149  'png',
150  ];
151 
152  $subject = $this->getAccessibleMock(GraphicalFunctions::class, ['executeIdentifyCommandForImageFile'], [], '', false);
153  $subject->_set('processorEnabled', true);
154  $subject->expects(self::once())->method('executeIdentifyCommandForImageFile')->with($file)->willReturn('200+0+0 400+0+0 png PNG');
155  $result = $subject->imageMagickIdentify($file);
156  self::assertEquals($result, $expected);
157  }
158 }
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest\imageMagickIdentifyReturnsFormattedValues
‪imageMagickIdentifyReturnsFormattedValues()
Definition: GraphicalFunctionsTest.php:120
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest\imageMagickIdentifyReturnsFormattedValuesWithOffset
‪imageMagickIdentifyReturnsFormattedValuesWithOffset()
Definition: GraphicalFunctionsTest.php:141
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest\getScaleForImage
‪getScaleForImage($info, $width, $height, $options, $expected)
Definition: GraphicalFunctionsTest.php:111
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest\getScaleForImageDataProvider
‪array getScaleForImageDataProvider()
Definition: GraphicalFunctionsTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Imaging
Definition: DimensionTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest
Definition: GraphicalFunctionsTest.php:24
‪TYPO3\CMS\Core\Imaging\GraphicalFunctions
Definition: GraphicalFunctions.php:37
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: GraphicalFunctionsTest.php:25