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