[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Imaging / IconProvider / SvgIconProviderTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider;
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\Core\Imaging\Icon;
18 use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Testcase for \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider
23 */
24 class SvgIconProviderTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
25 {
26 /**
27 * @var \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider
28 */
29 protected $subject = null;
30
31 /**
32 * @var Icon
33 */
34 protected $icon = null;
35
36 /**
37 * @var string
38 */
39 protected $testFileName;
40
41 /**
42 * Set up
43 *
44 * @return void
45 */
46 protected function setUp()
47 {
48 $this->subject = new \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider();
49 $this->icon = GeneralUtility::makeInstance(Icon::class);
50 $this->icon->setIdentifier('foo');
51 $this->icon->setSize(Icon::SIZE_SMALL);
52
53 $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>';
54 $this->testFileName = GeneralUtility::tempnam(uniqid('svg_') . '.svg');
55 file_put_contents($this->testFileName, $svgTestFileContent);
56 }
57
58 /**
59 * Tear down
60 */
61 protected function tearDown()
62 {
63 unlink($this->testFileName);
64 }
65
66 /**
67 * @test
68 */
69 public function prepareIconMarkupWithRelativeSourceReturnsInstanceOfIconWithCorrectMarkup()
70 {
71 $this->subject->prepareIconMarkup($this->icon, ['source' => 'fileadmin/foo.svg']);
72 $this->assertEquals('<img src="fileadmin/foo.svg" width="16" height="16" />', $this->icon->getMarkup());
73 }
74
75 /**
76 * @test
77 */
78 public function prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup()
79 {
80 $this->subject->prepareIconMarkup($this->icon, ['source' => '/fileadmin/foo.svg']);
81 $this->assertEquals('<img src="/fileadmin/foo.svg" width="16" height="16" />', $this->icon->getMarkup());
82 }
83
84 /**
85 * @test
86 */
87 public function getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup()
88 {
89 $this->subject->prepareIconMarkup($this->icon, ['source' => 'EXT:core/Resources/Public/Images/foo.svg']);
90 $this->assertEquals('<img src="typo3/sysext/core/Resources/Public/Images/foo.svg" width="16" height="16" />', $this->icon->getMarkup());
91 }
92
93 /**
94 * @test
95 */
96 public function getIconWithInlineOptionReturnsCleanSvgMarkup()
97 {
98 $this->subject->prepareIconMarkup($this->icon, ['source' => $this->testFileName]);
99 $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));
100 }
101 }