[!!!][TASK] Rewrite install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Tool / TestSetup.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller\Action\Tool;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Install\Controller\Action;
28 use TYPO3\CMS\Core\Utility\GeneralUtility;
29
30 /**
31 * Test various system setup settings
32 */
33 class TestSetup extends Action\AbstractAction implements Action\ActionInterface {
34
35 /**
36 * @var string Absolute path to image folder
37 */
38 protected $imageBasePath = '';
39
40 /**
41 * Handle this action
42 *
43 * @return string content
44 */
45 public function handle() {
46 $this->initialize();
47
48 $this->imageBasePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('install') . 'Resources/Public/Images/';
49
50 $actionMessages = array();
51 if (isset($this->postValues['set']['testMail'])) {
52 $actionMessages[] = $this->sendTestMail();
53 }
54
55 if (isset($this->postValues['set']['testTrueTypeFontDpi'])) {
56 $this->view->assign('trueTypeFontDpiTested', TRUE);
57 $actionMessages[] = $this->createTrueTypeFontDpiTestImage();
58 }
59
60 if (isset($this->postValues['set']['testConvertImageFormatsToJpg'])) {
61 $this->view->assign('convertImageFormatsToJpgTested', TRUE);
62 if ($this->isImageMagickEnabledAndConfigured()) {
63 $actionMessages[] = $this->convertImageFormatsToJpg();
64 } else {
65 $actionMessages[] = $this->imageMagickDisabledMessage();
66 }
67 }
68
69 if (isset($this->postValues['set']['testWriteGifAndPng'])) {
70 $this->view->assign('writeGifAndPngTested', TRUE);
71 if ($this->isImageMagickEnabledAndConfigured()) {
72 $actionMessages[] = $this->writeGifAndPng();
73 } else {
74 $actionMessages[] = $this->imageMagickDisabledMessage();
75 }
76 }
77
78 if (isset($this->postValues['set']['testScalingImages'])) {
79 $this->view->assign('scalingImagesTested', TRUE);
80 if ($this->isImageMagickEnabledAndConfigured()) {
81 $actionMessages[] = $this->scaleImages();
82 } else {
83 $actionMessages[] = $this->imageMagickDisabledMessage();
84 }
85 }
86
87 if (isset($this->postValues['set']['testCombiningImages'])) {
88 $this->view->assign('combiningImagesTested', TRUE);
89 if ($this->isImageMagickEnabledAndConfigured()) {
90 $actionMessages[] = $this->combineImages();
91 } else {
92 $actionMessages[] = $this->imageMagickDisabledMessage();
93 }
94 }
95
96 if (isset($this->postValues['set']['testGdlib'])) {
97 $this->view->assign('gdlibTested', TRUE);
98 $actionMessages[] = $this->gdlib();
99 }
100
101 $this->view->assign('actionMessages', $actionMessages);
102
103 $this->view->assign('imageConfiguration', $this->getImageConfiguration());
104
105 return $this->view->render();
106 }
107
108 /**
109 * Send a test mail to specified email address
110 *
111 * @return \TYPO3\CMS\Install\Status\StatusInterface
112 */
113 protected function sendTestMail() {
114 if (
115 !isset($this->postValues['values']['testEmailRecipient'])
116 || !GeneralUtility::validEmail($this->postValues['values']['testEmailRecipient'])
117 ) {
118 /** @var $message \TYPO3\CMS\Install\Status\StatusInterface */
119 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
120 $message->setTitle('Mail not sent');
121 $message->setMessage('Given address is not a valid email address.');
122 } else {
123 $recipient = $this->postValues['values']['testEmailRecipient'];
124 $mailMessage = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
125 $mailMessage
126 ->addTo($recipient)
127 ->addFrom('typo3installtool@example.org', 'TYPO3 CMS install tool')
128 ->setSubject('Test TYPO3 CMS mail delivery')
129 ->setBody('<html><body>html test content</body></html>')
130 ->addPart('TEST CONTENT')
131 ->send();
132 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\OkStatus');
133 $message->setTitle('Test mail sent');
134 $message->setMessage('Recipient: ' . $recipient);
135 }
136 return $message;
137 }
138
139 /**
140 * Create true type font test image
141 *
142 * @return \TYPO3\CMS\Install\Status\StatusInterface
143 */
144 protected function createTrueTypeFontDpiTestImage() {
145 $parseTimeStart = GeneralUtility::milliseconds();
146
147 $image = @imagecreate(200, 50);
148 imagecolorallocate($image, 255, 255, 55);
149 $textColor = imagecolorallocate($image, 233, 14, 91);
150 @imagettftext(
151 $image,
152 GeneralUtility::freetypeDpiComp(20),
153 0,
154 10,
155 20,
156 $textColor,
157 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('install') . 'Resources/Private/Font/vera.ttf',
158 'Testing true type'
159 );
160 $outputFile = PATH_site . 'typo3temp/installTool-createTrueTypeFontDpiTestImage.gif';
161 imagegif($image, $outputFile);
162
163 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
164 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\InfoStatus');
165 $message->setTitle('True type font DPI settings');
166 $message->setMessage(
167 'If the text "Tesing true type" does not fit into the image, set TYPO3_CONF_VARS[GFX][TTFdpi] to 96'
168 );
169
170 $testResults = array();
171 $testResults['ttf'] = array();
172 $testResults['ttf']['message'] = $message;
173 $testResults['ttf']['title'] = '';
174 $testResults['ttf']['outputFile'] = $outputFile;
175 $testResults['ttf']['referenceFile'] = $this->imageBasePath . 'TestReference/Font.gif';
176
177 $this->view->assign('testResults', $testResults);
178 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
179 }
180
181 /**
182 * Create jpg from various image formats using IM / GM
183 *
184 * @return \TYPO3\CMS\Install\Status\StatusInterface
185 */
186 protected function convertImageFormatsToJpg() {
187 $this->setUpDatabaseConnectionMock();
188 $imageProcessor = $this->initializeImageProcessor();
189 $parseTimeStart = GeneralUtility::milliseconds();
190
191 $inputFormatsToTest = array('jpg', 'gif', 'png', 'tif', 'bmp', 'pcx', 'tga', 'pdf', 'ai');
192
193 $testResults = array();
194 foreach ($inputFormatsToTest as $formatToTest) {
195 $result = array();
196 if (!GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $formatToTest)) {
197 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
198 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\WarningStatus');
199 $message->setTitle('Skipped test');
200 $message->setMessage('Handling format ' . $formatToTest . ' must be enabled in TYPO3_CONF_VARS[\'GFX\'][\'imagefile_ext\']');
201 $result['error'] = $message;
202 } else {
203 $imageProcessor->IM_commands = array();
204 $inputFile = $this->imageBasePath . 'TestInput/Test.' . $formatToTest;
205 $imageProcessor->imageMagickConvert_forceFileNameBody = 'read-' . $formatToTest;
206 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'jpg', '170', '', '', '', array(), TRUE);
207 $result['title'] = 'Read ' . $formatToTest;
208 $result['outputFile'] = $imResult[3];
209 $result['referenceFile'] = $this->imageBasePath . 'TestReference/Read-' . $formatToTest . '.jpg';
210 $result['command'] = $imageProcessor->IM_commands;
211 }
212 $testResults[] = $result;
213 }
214
215 $this->view->assign('testResults', $testResults);
216 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
217 }
218
219 /**
220 * Write gif and png test
221 *
222 * @return \TYPO3\CMS\Install\Status\StatusInterface
223 */
224 protected function writeGifAndPng() {
225 $this->setUpDatabaseConnectionMock();
226 $imageProcessor = $this->initializeImageProcessor();
227 $parseTimeStart = GeneralUtility::milliseconds();
228
229 $testResults = array(
230 'gif' => array(),
231 'png' => array(),
232 );
233
234 // Gif
235 $inputFile = $this->imageBasePath . 'TestInput/Test.gif';
236 $imageProcessor->imageMagickConvert_forceFileNameBody = 'write-gif';
237 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'gif', '', '', '', '', array(), TRUE);
238 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gif_compress']) {
239 clearstatcache();
240 $previousSize = GeneralUtility::formatSize(filesize($imResult[3]));
241 $methodUsed = GeneralUtility::gif_compress($imResult[3], '');
242 clearstatcache();
243 $compressedSize = GeneralUtility::formatSize(filesize($imResult[3]));
244 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
245 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\InfoStatus');
246 $message->setTitle('Compressed gif');
247 $message->setMessage(
248 'Method used by compress: ' . $methodUsed . '<br />'
249 . ' Previous filesize: ' . $previousSize . '. Current filesize:' . $compressedSize
250 );
251 } else {
252 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
253 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\InfoStatus');
254 $message->setTitle('Gif compression not enabled by [GFX][gif_compress]');
255 }
256 $testResults['gif']['message'] = $message;
257 $testResults['gif']['title'] = 'Write gif';
258 $testResults['gif']['outputFile'] = $imResult[3];
259 $testResults['gif']['referenceFile'] = $this->imageBasePath . 'TestReference/Write-gif.gif';
260 $testResults['gif']['command'] = $imageProcessor->IM_commands;
261
262 // Png
263 $inputFile = $this->imageBasePath . 'TestInput/Test.png';
264 $imageProcessor->IM_commands = array();
265 $imageProcessor->imageMagickConvert_forceFileNameBody = 'write-png';
266 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'png', '', '', '', '', array(), TRUE);
267 $testResults['png']['title'] = 'Write png';
268 $testResults['png']['outputFile'] = $imResult[3];
269 $testResults['png']['referenceFile'] = $this->imageBasePath . 'TestReference/Write-png.png';
270 $testResults['png']['command'] = $imageProcessor->IM_commands;
271
272 $this->view->assign('testResults', $testResults);
273 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
274 }
275
276 /**
277 * Write gif and png test
278 *
279 * @return \TYPO3\CMS\Install\Status\StatusInterface
280 */
281 protected function scaleImages() {
282 $this->setUpDatabaseConnectionMock();
283 $imageProcessor = $this->initializeImageProcessor();
284 $parseTimeStart = GeneralUtility::milliseconds();
285
286 $testResults = array(
287 'gif-to-gif' => array(),
288 'png-to-png' => array(),
289 'gif-to-jpg' => array(),
290 );
291
292 $imageProcessor->IM_commands = array();
293 $inputFile = $this->imageBasePath . 'TestInput/Transparent.gif';
294 $imageProcessor->imageMagickConvert_forceFileNameBody = 'scale-gif';
295 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'gif', '150', '', '', '', array(), TRUE);
296 $testResults['gif-to-gif']['title'] = 'gif to gif';
297 $testResults['gif-to-gif']['outputFile'] = $imResult[3];
298 $testResults['gif-to-gif']['referenceFile'] = $this->imageBasePath . 'TestReference/Scale-gif.gif';
299 $testResults['gif-to-gif']['command'] = $imageProcessor->IM_commands;
300
301 $imageProcessor->IM_commands = array();
302 $inputFile = $this->imageBasePath . 'TestInput/Transparent.png';
303 $imageProcessor->imageMagickConvert_forceFileNameBody = 'scale-png';
304 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'png', '150', '', '', '', array(), TRUE);
305 $testResults['png-to-png']['title'] = 'png to png';
306 $testResults['png-to-png']['outputFile'] = $imResult[3];
307 $testResults['png-to-png']['referenceFile'] = $this->imageBasePath . 'TestReference/Scale-png.png';
308 $testResults['png-to-png']['command'] = $imageProcessor->IM_commands;
309
310 $imageProcessor->IM_commands = array();
311 $inputFile = $this->imageBasePath . 'TestInput/Transparent.gif';
312 $imageProcessor->imageMagickConvert_forceFileNameBody = 'scale-jpg';
313 $imResult = $imageProcessor->imageMagickConvert($inputFile, 'jpg', '150', '', '', '', array(), TRUE);
314 $testResults['gif-to-jpg']['title'] = 'gif to jpg';
315 $testResults['gif-to-jpg']['outputFile'] = $imResult[3];
316 $testResults['gif-to-jpg']['referenceFile'] = $this->imageBasePath . 'TestReference/Scale-jpg.jpg';
317 $testResults['gif-to-jpg']['command'] = $imageProcessor->IM_commands;
318
319 $this->view->assign('testResults', $testResults);
320 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
321 }
322
323 /**
324 * Combine multiple images into one test
325 *
326 * @return \TYPO3\CMS\Install\Status\StatusInterface
327 */
328 protected function combineImages() {
329 $this->setUpDatabaseConnectionMock();
330 $imageProcessor = $this->initializeImageProcessor();
331 $parseTimeStart = GeneralUtility::milliseconds();
332
333 $testResults = array(
334 'combine1' => array(),
335 'combine2' => array(),
336 );
337
338 $inputFile = $this->imageBasePath . 'TestInput/BackgroundGreen.gif';
339 $overlayFile = $this->imageBasePath . 'TestInput/Test.jpg';
340 $maskFile = $this->imageBasePath . 'TestInput/MaskBlackWhite.gif';
341 $resultFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix
342 . GeneralUtility::shortMD5(($imageProcessor->alternativeOutputKey . 'combine1')) . '.jpg';
343 $imageProcessor->combineExec($inputFile, $overlayFile, $maskFile, $resultFile, TRUE);
344 $result = $imageProcessor->getImageDimensions($resultFile);
345 $testResults['combine1']['title'] = 'Combine using a GIF mask with only black and white';
346 $testResults['combine1']['outputFile'] = $result[3];
347 $testResults['combine1']['referenceFile'] = $this->imageBasePath . 'TestReference/Combine-1.jpg';
348 $testResults['combine1']['command'] = $imageProcessor->IM_commands;
349
350 $imageProcessor->IM_commands = array();
351 $inputFile = $this->imageBasePath . 'TestInput/BackgroundCombine.jpg';
352 $overlayFile = $this->imageBasePath . 'TestInput/Test.jpg';
353 $maskFile = $this->imageBasePath . 'TestInput/MaskCombine.jpg';
354 $resultFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix
355 . GeneralUtility::shortMD5(($imageProcessor->alternativeOutputKey . 'combine2')) . '.jpg';
356 $imageProcessor->combineExec($inputFile, $overlayFile, $maskFile, $resultFile, TRUE);
357 $result = $imageProcessor->getImageDimensions($resultFile);
358 $testResults['combine2']['title'] = 'Combine using a JPG mask with graylevels';
359 $testResults['combine2']['outputFile'] = $result[3];
360 $testResults['combine2']['referenceFile'] = $this->imageBasePath . 'TestReference/Combine-2.jpg';
361 $testResults['combine2']['command'] = $imageProcessor->IM_commands;
362
363 $this->view->assign('testResults', $testResults);
364 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
365 }
366
367 /**
368 * Test gdlib functions
369 *
370 * @return \TYPO3\CMS\Install\Status\StatusInterface
371 */
372 protected function gdlib() {
373 $this->setUpDatabaseConnectionMock();
374 $imageProcessor = $this->initializeImageProcessor();
375 $parseTimeStart = GeneralUtility::milliseconds();
376 $gifOrPng = $imageProcessor->gifExtension;
377 $testResults = array();
378
379 // GD with simple box
380 $imageProcessor->IM_commands = array();
381 $image = imagecreatetruecolor(170, 136);
382 $backgroundColor = imagecolorallocate($image, 0, 0, 0);
383 imagefilledrectangle($image, 0, 0, 170, 136, $backgroundColor);
384 $workArea = array(0, 0, 170, 136);
385 $conf = array(
386 'dimensions' => '10,50,150,36',
387 'color' => 'olive',
388 );
389 $imageProcessor->makeBox($image, $conf, $workArea);
390 $outputFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix
391 . GeneralUtility::shortMD5('gdSimple') . '.' . $gifOrPng;
392 $imageProcessor->ImageWrite($image, $outputFile);
393 $result = $imageProcessor->getImageDimensions($outputFile);
394 $testResults['simple'] = array();
395 $testResults['simple']['title'] = 'Create simple image';
396 $testResults['simple']['outputFile'] = $result[3];
397 $testResults['simple']['referenceFile'] = $this->imageBasePath . 'TestReference/Gdlib-simple.' . $gifOrPng;
398
399 // GD from image with box
400 $imageProcessor->IM_commands = array();
401 $inputFile = $this->imageBasePath . 'TestInput/Test.' . $gifOrPng;
402 $image = $imageProcessor->imageCreateFromFile($inputFile);
403 $workArea = array(0, 0, 170, 136);
404 $conf = array(
405 'dimensions' => '10,50,150,36',
406 'color' => 'olive',
407 );
408 $imageProcessor->makeBox($image, $conf, $workArea);
409 $outputFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix
410 . GeneralUtility::shortMD5('gdBox') . '.' . $gifOrPng;
411 $imageProcessor->ImageWrite($image, $outputFile);
412 $result = $imageProcessor->getImageDimensions($outputFile);
413 $testResults['box'] = array();
414 $testResults['box']['title'] = 'Create image from file';
415 $testResults['box']['outputFile'] = $result[3];
416 $testResults['box']['referenceFile'] = $this->imageBasePath . 'TestReference/Gdlib-box.' . $gifOrPng;
417
418 // GD with text
419 $imageProcessor->IM_commands = array();
420 $image = imagecreatetruecolor(170, 136);
421 $backgroundColor = imagecolorallocate($image, 128, 128, 150);
422 imagefilledrectangle($image, 0, 0, 170, 136, $backgroundColor);
423 $workArea = array(0, 0, 170, 136);
424 $conf = array(
425 'iterations' => 1,
426 'angle' => 0,
427 'antiAlias' => 1,
428 'text' => 'HELLO WORLD',
429 'fontColor' => '#003366',
430 'fontSize' => 18,
431 'fontFile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('install') . 'Resources/Private/Font/vera.ttf',
432 'offset' => '17,40',
433 );
434 $conf['BBOX'] = $imageProcessor->calcBBox($conf);
435 $imageProcessor->makeText($image, $conf, $workArea);
436 $outputFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix .
437 GeneralUtility::shortMD5('gdText') . '.' . $gifOrPng;
438 $imageProcessor->ImageWrite($image, $outputFile);
439 $result = $imageProcessor->getImageDimensions($outputFile);
440 $testResults['text'] = array();
441 $testResults['text']['title'] = 'Render text with TrueType font';
442 $testResults['text']['outputFile'] = $result[3];
443 $testResults['text']['referenceFile'] = $this->imageBasePath . 'TestReference/Gdlib-text.' . $gifOrPng;
444
445 // GD with text, niceText
446 $testResults['niceText'] = array();
447 if ($this->isImageMagickEnabledAndConfigured()) {
448 // Warning: Re-uses $conf from above!
449 $conf['offset'] = '17,65';
450 $conf['niceText'] = 1;
451 $imageProcessor->makeText($image, $conf, $workArea);
452 $outputFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix .
453 GeneralUtility::shortMD5('gdNiceText') . '.' . $gifOrPng;
454 $imageProcessor->ImageWrite($image, $outputFile);
455 $result = $imageProcessor->getImageDimensions($outputFile);
456 $testResults['niceText']['title'] = 'Render text with TrueType font using \'niceText\' option';
457 $testResults['niceText']['outputFile'] = $result[3];
458 $testResults['niceText']['referenceFile'] = $this->imageBasePath . 'TestReference/Gdlib-niceText.' . $gifOrPng;
459 $testResults['niceText']['commands'] = $imageProcessor->IM_commands;
460 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
461 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\InfoStatus');
462 $message->setTitle('Note on \'niceText\'');
463 $message->setMessage(
464 '\'niceText\' is a concept that tries to improve the antialiasing of the rendered type by'
465 . ' actually rendering the textstring in double size on a black/white mask, downscaling the mask'
466 . ' and masking the text onto the image through this mask. This involves'
467 . ' ImageMagick \'combine\'/\'composite\' and \'convert\'.'
468 . ' <br />If the image has another background color than the image above (eg. dark background'
469 . ' color with light text) then you will have to set TYPO3_CONF_VARS[GFX][im_imvMaskState]=1'
470 );
471 $testResults['niceText']['message'] = $message;
472 } else {
473 $result['niceText']['error'] = $this->imageMagickDisabledMessage();
474 }
475
476 // GD with text, niceText, shadow
477 $testResults['shadow'] = array();
478 if ($this->isImageMagickEnabledAndConfigured()) {
479 // Warning: Re-uses $conf from above!
480 $conf['offset'] = '17,90';
481 $conf['niceText'] = 1;
482 $conf['shadow.'] = array(
483 'offset' => '2,2',
484 'blur' => $imageProcessor->V5_EFFECTS ? '20' : '90',
485 'opacity' => '50',
486 'color' => 'black'
487 );
488 // Warning: Re-uses $image from above!
489 $imageProcessor->makeShadow($image, $conf['shadow.'], $workArea, $conf);
490 $imageProcessor->makeText($image, $conf, $workArea);
491 $outputFile = $imageProcessor->tempPath . $imageProcessor->filenamePrefix . GeneralUtility::shortMD5('GDwithText-niceText-shadow') . '.' . $gifOrPng;
492 $imageProcessor->ImageWrite($image, $outputFile);
493 $result = $imageProcessor->getImageDimensions($outputFile);
494 $testResults['shadow']['title'] = 'Render \'niceText\' with a shadow under';
495 $testResults['shadow']['outputFile'] = $result[3];
496 $testResults['shadow']['referenceFile'] = $this->imageBasePath . 'TestReference/Gdlib-shadow.' . $gifOrPng;
497 $testResults['shadow']['commands'] = $imageProcessor->IM_commands;
498 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
499 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\InfoStatus');
500 $message->setTitle('Note on \'shadow\'');
501 $message->setMessage(
502 'This test makes sense only if the above test had a correct output. But if so, you may not see'
503 . ' a soft dropshadow from the third text string as you should. In that case you are most likely'
504 . ' using ImageMagick 5 and should set the flag TYPO3_CONF_VARS[GFX][im_v5effects].'
505 );
506 $testResults['shadow']['message'] = $message;
507 } else {
508 $result['shadow']['error'] = $this->imageMagickDisabledMessage();
509 }
510
511 $this->view->assign('testResults', $testResults);
512 return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart);
513 }
514
515 /**
516 * Create a 'image test was done' message
517 *
518 * @param integer $parseTime Parse time
519 * @return \TYPO3\CMS\Install\Status\StatusInterface
520 */
521 protected function imageTestDoneMessage($parseTime = 0) {
522 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
523 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\OkStatus');
524 $message->setTitle('Executed image tests');
525 $message->setMessage('Parse time: ' . $parseTime . ' ms');
526 return $message;
527 }
528
529 /**
530 * Create a 'imageMagick disabled' message
531 *
532 * @return \TYPO3\CMS\Install\Status\StatusInterface
533 */
534 protected function imageMagickDisabledMessage() {
535 /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */
536 $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\ErrorStatus');
537 $message->setTitle('Tests not executed');
538 $message->setMessage('ImageMagick / GraphicsMagick handling is disabled or not configured.');
539 return $message;
540 }
541
542 /**
543 * Gather image configuration overview
544 *
545 * @return array Result array
546 */
547 protected function getImageConfiguration() {
548 $result = array();
549 $result['imageMagickOrGraphicsMagick'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm' ? 'gm' : 'im';
550 $result['imageMagickEnabled'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'];
551 $result['imageMagickPath'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'];
552 $result['imageMagickVersion'] = $this->determineImageMagickVersion();
553 $result['imageMagick5Effecs'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_v5effects'];
554 $result['imageMagickMaskInvert'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState'];
555 $result['gdlibEnabled'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'];
556 $result['gdlibPng'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'];
557 $result['freeTypeDpi'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['TTFdpi'];
558 $result['fileFormats'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
559 return $result;
560 }
561
562 /**
563 * Initialize image processor
564 *
565 * @return \TYPO3\CMS\Core\Imaging\GraphicalFunctions Initialized image processor
566 */
567 protected function initializeImageProcessor() {
568 /** @var \TYPO3\CMS\Core\Imaging\GraphicalFunctions $imageProcessor */
569 $imageProcessor = $this->objectManager->get('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
570 $imageProcessor->init();
571 $imageProcessor->tempPath = PATH_site . 'typo3temp/';
572 $imageProcessor->dontCheckForExistingTempFile = 1;
573 $imageProcessor->enable_typo3temp_db_tracking = 0;
574 $imageProcessor->filenamePrefix = 'installTool-';
575 $imageProcessor->dontCompress = 1;
576 $imageProcessor->alternativeOutputKey = 'typo3InstallTest';
577 $imageProcessor->noFramePrepended = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_noFramePrepended'];
578 return $imageProcessor;
579 }
580
581 /**
582 * Find out if ImageMagick or GraphicsMagick is enabled and set up
583 *
584 * @return boolean TRUE if enabled and path is set
585 */
586 protected function isImageMagickEnabledAndConfigured() {
587 $enabled = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'];
588 $path = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'];
589 return $enabled && $path;
590 }
591
592 /**
593 * Determine ImageMagick / GraphicsMagick version
594 *
595 * @return string Version
596 */
597 protected function determineImageMagickVersion() {
598 $command = \TYPO3\CMS\Core\Utility\CommandUtility::imageMagickCommand('identify', '-version');
599 \TYPO3\CMS\Core\Utility\CommandUtility::exec($command, $result);
600 $string = $result[0];
601 list(, $version) = explode('Magick', $string);
602 list($version) = explode(' ', trim($version));
603 return trim($version);
604 }
605
606 /**
607 * Instantiate a dummy instance for $GLOBALS['TYPO3_DB'] to
608 * prevent real database calls
609 *
610 * @return void
611 */
612 protected function setUpDatabaseConnectionMock() {
613 $database = $this->objectManager->get('TYPO3\\CMS\\Install\\Database\\DatabaseConnectionMock');
614 $GLOBALS['TYPO3_DB'] = $database;
615 }
616 }
617 ?>