TYPO3 CMS  TYPO3_8-7
SvgIconProviderTest.php
Go to the documentation of this file.
1 <?php
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 
20 
24 class SvgIconProviderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
25 {
29  protected $subject = null;
30 
34  protected $icon = null;
35 
39  protected function setUp()
40  {
41  $this->subject = new \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider();
42  $this->icon = GeneralUtility::makeInstance(Icon::class);
43  $this->icon->setIdentifier('foo');
44  $this->icon->setSize(Icon::SIZE_SMALL);
45  }
46 
51  {
52  $this->subject->prepareIconMarkup($this->icon, ['source' => 'fileadmin/foo.svg']);
53  $this->assertEquals('<img src="fileadmin/foo.svg" width="16" height="16" />', $this->icon->getMarkup());
54  }
55 
60  {
61  $this->subject->prepareIconMarkup($this->icon, ['source' => '/fileadmin/foo.svg']);
62  $this->assertEquals('<img src="/fileadmin/foo.svg" width="16" height="16" />', $this->icon->getMarkup());
63  }
64 
69  {
70  $this->subject->prepareIconMarkup($this->icon, ['source' => 'EXT:core/Resources/Public/Images/foo.svg']);
71  $this->assertEquals('<img src="typo3/sysext/core/Resources/Public/Images/foo.svg" width="16" height="16" />', $this->icon->getMarkup());
72  }
73 
78  {
79  $testFile = GeneralUtility::tempnam(uniqid('svg_') . '.svg');
80  $this->testFilesToDelete[] = $testFile;
81  $svgTestFileContent = '<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="#CD201F" d="M11 12l3-2v6H2v-6l3 2 3-2 3 2z"></path><script><![CDATA[ function alertMe() {} ]]></script></svg>';
82  file_put_contents($testFile, $svgTestFileContent);
83  $this->testFilesToDelete[] = GeneralUtility::tempnam(uniqid('svg_') . '.svg');
84  $this->subject->prepareIconMarkup($this->icon, ['source' => $testFile]);
85  $this->assertEquals('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="#CD201F" d="M11 12l3-2v6H2v-6l3 2 3-2 3 2z"/></svg>', $this->icon->getMarkup(SvgIconProvider::MARKUP_IDENTIFIER_INLINE));
86  }
87 }
static makeInstance($className,... $constructorArguments)
static tempnam($filePrefix, $fileSuffix='')