‪TYPO3CMS  9.5
ImageInfoTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use org\bovigo\vfs\vfsStream;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪ImageInfoTest extends UnitTestCase
29 {
30 
35  {
36  $className = \TYPO3\CMS\Core\Type\File\ImageInfo::class;
37  $classInstance = new \TYPO3\CMS\Core\Type\File\ImageInfo('FooFileName');
38  $this->assertInstanceOf($className, $classInstance);
39  }
40 
45  {
46  return [
47  ['Invalid XML.', 0, 0],
48  [
49  '<?xml version="1.0" encoding="utf-8"?>
50  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
51  <!ENTITY ns_a "http://ns.typo3.com/test/a/1.0/">
52  <!ENTITY ns_b "http://ns.typo3.com/test/b/1.0/">
53  ]>
54  <svg version="1.0"
55  xmlns:x="&ns_a;"
56  xmlns="http://www.w3.org/2000/svg"
57  xmlns:xlink="http://www.w3.org/1999/xlink"
58  xml:space="preserve"
59  x="0px" y="0px" viewBox="0 0 436 177">
60  <metadata>
61  <sfw xmlns="&ns_b;">
62  <slices></slices>
63  </sfw>
64  </metadata>
65  </svg>',
66  436,
67  177
68  ],
69  ];
70  }
71 
79  public function ‪doesNotBreakOnImageInfoWithInvalidSvg($svg, $width, $height)
80  {
81  $this->resetSingletonInstances = true;
82 
83  $root = vfsStream::setup('root');
84  $testFile = 'test.svg';
85  vfsStream::newFile($testFile)->at($root)->setContent($svg);
86 
87  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['fileExtensionToMimeType'] = [
88  'svg' => 'image/svg+xml',
89  'youtube' => 'video/youtube',
90  'vimeo' => 'video/vimeo',
91  ];
92 
93  $graphicalFunctionsProphecy = $this->prophesize(GraphicalFunctions::class);
94  $graphicalFunctionsProphecy->imageMagickIdentify($root->url() . '/' . $testFile)->willReturn(null);
95  GeneralUtility::addInstance(GraphicalFunctions::class, $graphicalFunctionsProphecy->reveal());
96 
97  $loggerProphecy = $this->prophesize(Logger::class);
98 
99  $imageInfo = new ‪ImageInfo($root->url() . '/' . $testFile);
100  $imageInfo->setLogger($loggerProphecy->reveal());
101 
102  $this->assertSame($width, $imageInfo->getWidth());
103  $this->assertSame($height, $imageInfo->getHeight());
104 
105  GeneralUtility::makeInstance(GraphicalFunctions::class);
106  }
107 
111  public function ‪canDetectImageSizesDataProvider(): array
112  {
113  return [
114  'svg' => ['test.svg', 80, 80],
115  'jpg' => ['test.jpg', 600, 388],
116  'png' => ['test.png', 600, 388],
117  ];
118  }
119 
127  public function ‪canDetectImageSizes($file, $width, $height)
128  {
129  $logger = $this->prophesize(Logger::class)->reveal();
130  $imageInfo = new ‪ImageInfo(__DIR__ . '/../Fixture/' . $file);
131  $imageInfo->setLogger($logger);
132 
133  $this->assertSame($width, $imageInfo->getWidth());
134  $this->assertSame($height, $imageInfo->getHeight());
135  }
136 }
‪TYPO3\CMS\Core\Tests\Unit\Type\File\ImageInfoTest\doesNotBreakOnImageInfoWithInvalidSvg
‪doesNotBreakOnImageInfoWithInvalidSvg($svg, $width, $height)
Definition: ImageInfoTest.php:79
‪TYPO3\CMS\Core\Tests\Unit\Type\File\ImageInfoTest
Definition: ImageInfoTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Type\File
Definition: FileInfoTest.php:2
‪TYPO3\CMS\Core\Imaging\GraphicalFunctions
Definition: GraphicalFunctions.php:35
‪TYPO3\CMS\Core\Tests\Unit\Type\File\ImageInfoTest\doesNotBreakOnImageInfoWithInvalidSvgDataProvider
‪array doesNotBreakOnImageInfoWithInvalidSvgDataProvider()
Definition: ImageInfoTest.php:44
‪TYPO3\CMS\Core\Tests\Unit\Type\File\ImageInfoTest\canDetectImageSizes
‪canDetectImageSizes($file, $width, $height)
Definition: ImageInfoTest.php:127
‪TYPO3\CMS\Core\Type\File\ImageInfo
Definition: ImageInfo.php:25
‪TYPO3\CMS\Core\Tests\Unit\Type\File\ImageInfoTest\classImageInfoCanBeInstantiated
‪classImageInfoCanBeInstantiated()
Definition: ImageInfoTest.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Log\Logger
Definition: Logger.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Type\File\ImageInfoTest\canDetectImageSizesDataProvider
‪array canDetectImageSizesDataProvider()
Definition: ImageInfoTest.php:111