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