‪TYPO3CMS  10.4
ImageInfoTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
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 = ImageInfo::class;
37  $classInstance = new ‪ImageInfo('FooFileName');
38  self::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  self::assertSame($width, $imageInfo->getWidth());
103  self::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  self::assertSame($width, $imageInfo->getWidth());
134  self::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: ImageInfoTest.php:16
‪TYPO3\CMS\Core\Imaging\GraphicalFunctions
Definition: GraphicalFunctions.php:37
‪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:27
‪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:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\Type\File\ImageInfoTest\canDetectImageSizesDataProvider
‪array canDetectImageSizesDataProvider()
Definition: ImageInfoTest.php:111