‪TYPO3CMS  9.5
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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪SvgIconProviderTest extends UnitTestCase
26 {
30  protected ‪$subject;
31 
35  protected ‪$icon;
36 
40  protected function ‪setUp()
41  {
42  $this->subject = new \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider();
43  $this->icon = GeneralUtility::makeInstance(Icon::class);
44  $this->icon->setIdentifier('foo');
45  $this->icon->setSize(‪Icon::SIZE_SMALL);
46  }
47 
52  {
53  $this->subject->prepareIconMarkup($this->icon, ['source' => 'fileadmin/foo.svg']);
54  $this->assertEquals('<img src="fileadmin/foo.svg" width="16" height="16" />', $this->icon->getMarkup());
55  }
56 
61  {
62  $this->subject->prepareIconMarkup($this->icon, ['source' => '/fileadmin/foo.svg']);
63  $this->assertEquals('<img src="/fileadmin/foo.svg" width="16" height="16" />', $this->icon->getMarkup());
64  }
65 
70  {
71  $this->subject->prepareIconMarkup($this->icon, ['source' => 'EXT:core/Resources/Public/Images/foo.svg']);
72  $this->assertEquals('<img src="typo3/sysext/core/Resources/Public/Images/foo.svg" width="16" height="16" />', $this->icon->getMarkup());
73  }
74 
79  {
80  $testFile = GeneralUtility::tempnam(uniqid('svg_') . '.svg');
81  $this->testFilesToDelete[] = $testFile;
82  $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>';
83  file_put_contents($testFile, $svgTestFileContent);
84  $this->testFilesToDelete[] = GeneralUtility::tempnam(uniqid('svg_') . '.svg');
85  $this->subject->prepareIconMarkup($this->icon, ['source' => $testFile]);
86  $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));
87  }
88 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\prepareIconMarkupWithRelativeSourceReturnsInstanceOfIconWithCorrectMarkup
‪prepareIconMarkupWithRelativeSourceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgIconProviderTest.php:49
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\getIconWithInlineOptionReturnsCleanSvgMarkup
‪getIconWithInlineOptionReturnsCleanSvgMarkup()
Definition: SvgIconProviderTest.php:76
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\setUp
‪setUp()
Definition: SvgIconProviderTest.php:38
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\$icon
‪Icon $icon
Definition: SvgIconProviderTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup
‪getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgIconProviderTest.php:67
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest
Definition: SvgIconProviderTest.php:26
‪TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider\MARKUP_IDENTIFIER_INLINE
‪const MARKUP_IDENTIFIER_INLINE
Definition: SvgIconProvider.php:27
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup
‪prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgIconProviderTest.php:58
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\$subject
‪TYPO3 CMS Core Imaging IconProvider SvgIconProvider $subject
Definition: SvgIconProviderTest.php:29
‪TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider
Definition: SvgIconProvider.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider
Definition: BitmapIconProviderTest.php:2