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