‪TYPO3CMS  10.4
GraphicalFunctionsTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
21 class ‪GraphicalFunctionsTest extends UnitTestCase
22 {
23  protected ‪$resetSingletonInstances = true;
24 
31  {
32  return [
33  'Get image scale for a width of 150px' => [
34  [
35  170,
36  136,
37  ],
38  '150',
39  '',
40  [],
41  [
42  'crs' => false,
43  'origW' => 150,
44  'origH' => 0,
45  'max' => 0,
46  0 => 150,
47  1 => (float)120
48  ],
49  ],
50  'Get image scale with a maximum width of 100px' => [
51  [
52  170,
53  136,
54  ],
55  '',
56  '',
57  [
58  'maxW' => 100
59  ],
60  [
61  'crs' => false,
62  'origW' => 100,
63  'origH' => 0,
64  'max' => 1,
65  0 => 100,
66  1 => (float)80
67  ],
68  ],
69  'Get image scale with a minimum width of 200px' => [
70  [
71  170,
72  136,
73  ],
74  '',
75  '',
76  [
77  'minW' => 200
78  ],
79  [
80  'crs' => false,
81  'origW' => 0,
82  'origH' => 0,
83  'max' => 0,
84  0 => 200,
85  1 => (float)136
86  ],
87  ],
88  'No PHP warning for zero in input dimensions when scaling' => [
89  [0, 0],
90  '50',
91  '',
92  [],
93  [
94  'crs' => false,
95  'origW' => 50,
96  'origH' => 0,
97  'max' => 0,
98  0 => 0,
99  1 => 0
100  ],
101  ],
102  ];
103  }
104 
109  public function ‪getScaleForImage($info, $width, $height, $options, $expected)
110  {
111  $result = (new ‪GraphicalFunctions())->getImageScale($info, $width, $height, $options);
112  self::assertEquals($result, $expected);
113  }
114 
119  {
120  $file = 'myImageFile.png';
121  $expected = [
122  '123',
123  '234',
124  'png',
125  'myImageFile.png',
126  'png'
127  ];
128 
129  $subject = $this->getAccessibleMock(GraphicalFunctions::class, ['executeIdentifyCommandForImageFile'], [], '', false);
130  $subject->_set('processorEnabled', true);
131  $subject->expects(self::once())->method('executeIdentifyCommandForImageFile')->with($file)->willReturn('123 234 png PNG');
132  $result = $subject->imageMagickIdentify($file);
133  self::assertEquals($result, $expected);
134  }
135 
140  {
141  $file = 'myImageFile.png';
142  $expected = [
143  '200+0+0',
144  '400+0+0',
145  'png',
146  'myImageFile.png',
147  'png'
148  ];
149 
150  $subject = $this->getAccessibleMock(GraphicalFunctions::class, ['executeIdentifyCommandForImageFile'], [], '', false);
151  $subject->_set('processorEnabled', true);
152  $subject->expects(self::once())->method('executeIdentifyCommandForImageFile')->with($file)->willReturn('200+0+0 400+0+0 png PNG');
153  $result = $subject->imageMagickIdentify($file);
154  self::assertEquals($result, $expected);
155  }
156 }
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest\imageMagickIdentifyReturnsFormattedValues
‪imageMagickIdentifyReturnsFormattedValues()
Definition: GraphicalFunctionsTest.php:118
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest\imageMagickIdentifyReturnsFormattedValuesWithOffset
‪imageMagickIdentifyReturnsFormattedValuesWithOffset()
Definition: GraphicalFunctionsTest.php:139
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest\getScaleForImage
‪getScaleForImage($info, $width, $height, $options, $expected)
Definition: GraphicalFunctionsTest.php:109
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest\getScaleForImageDataProvider
‪array getScaleForImageDataProvider()
Definition: GraphicalFunctionsTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Imaging
Definition: DimensionTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest
Definition: GraphicalFunctionsTest.php:22
‪TYPO3\CMS\Core\Imaging\GraphicalFunctions
Definition: GraphicalFunctions.php:37
‪TYPO3\CMS\Core\Tests\Unit\Imaging\GraphicalFunctionsTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: GraphicalFunctionsTest.php:23