‪TYPO3CMS  10.4
SvgIconProviderTest.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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪SvgIconProviderTest extends UnitTestCase
27 {
31  protected ‪$subject;
32 
36  protected ‪$icon;
37 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
44  $this->subject = new ‪SvgIconProvider();
45  $this->icon = GeneralUtility::makeInstance(Icon::class);
46  $this->icon->setIdentifier('foo');
47  $this->icon->setSize(‪Icon::SIZE_SMALL);
48  }
49 
54  {
55  $this->subject->prepareIconMarkup($this->icon, ['source' => 'fileadmin/foo.svg']);
56  self::assertEquals('<img src="fileadmin/foo.svg" width="16" height="16" alt="" />', $this->icon->getMarkup());
57  }
58 
63  {
64  $this->subject->prepareIconMarkup($this->icon, ['source' => '/fileadmin/foo.svg']);
65  self::assertEquals('<img src="/fileadmin/foo.svg" width="16" height="16" alt="" />', $this->icon->getMarkup());
66  }
67 
72  {
73  $this->subject->prepareIconMarkup($this->icon, ['source' => 'EXT:core/Resources/Public/Images/foo.svg']);
74  self::assertEquals('<img src="typo3/sysext/core/Resources/Public/Images/foo.svg" width="16" height="16" alt="" />', $this->icon->getMarkup());
75  }
76 
81  {
82  $testFile = GeneralUtility::tempnam('svg_', '.svg');
83  $this->testFilesToDelete[] = $testFile;
84  $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>';
85  file_put_contents($testFile, $svgTestFileContent);
86  $this->testFilesToDelete[] = GeneralUtility::tempnam('svg_', '.svg');
87  $this->subject->prepareIconMarkup($this->icon, ['source' => $testFile]);
88  self::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));
89  }
90 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\prepareIconMarkupWithRelativeSourceReturnsInstanceOfIconWithCorrectMarkup
‪prepareIconMarkupWithRelativeSourceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgIconProviderTest.php:51
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\getIconWithInlineOptionReturnsCleanSvgMarkup
‪getIconWithInlineOptionReturnsCleanSvgMarkup()
Definition: SvgIconProviderTest.php:78
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\MARKUP_IDENTIFIER_INLINE
‪const MARKUP_IDENTIFIER_INLINE
Definition: AbstractSvgIconProvider.php:29
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\setUp
‪setUp()
Definition: SvgIconProviderTest.php:39
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\$icon
‪Icon $icon
Definition: SvgIconProviderTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup
‪getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgIconProviderTest.php:69
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest
Definition: SvgIconProviderTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup
‪prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgIconProviderTest.php:60
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\$subject
‪TYPO3 CMS Core Imaging IconProvider SvgIconProvider $subject
Definition: SvgIconProviderTest.php:30
‪TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider
Definition: SvgIconProvider.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider
Definition: BitmapIconProviderTest.php:16