‪TYPO3CMS  ‪main
SvgSpriteIconProviderTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 use TYPO3\CMS\Core\Imaging\IconSize;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 final class ‪SvgSpriteIconProviderTest extends UnitTestCase
31 {
33 
37  protected ‪$icon;
38 
39  protected function ‪setUp(): void
40  {
41  parent::setUp();
42  $this->subject = new ‪SvgSpriteIconProvider();
43  $this->icon = GeneralUtility::makeInstance(Icon::class);
44  $this->icon->setIdentifier('foo');
45  $this->icon->setSize(IconSize::SMALL);
46  }
47 
52  {
53  $this->subject->prepareIconMarkup($this->icon, [
54  'sprite' => 'fileadmin/sprites/actions.svg#actions-plus',
55  'source' => 'fileadmin/svg/actions-plus.svg',
56  ]);
57  self::assertEquals('<svg class="icon-color"><use xlink:href="fileadmin/sprites/actions.svg#actions-plus" /></svg>', $this->icon->getMarkup());
58  }
59 
64  {
65  $this->subject->prepareIconMarkup($this->icon, [
66  'sprite' => ‪Environment::getPublicPath() . '/fileadmin/sprites/actions.svg#actions-plus',
67  'source' => ‪Environment::getPublicPath() . '/fileadmin/svg/actions-plus.svg',
68  ]);
69  self::assertEquals('<svg class="icon-color"><use xlink:href="fileadmin/sprites/actions.svg#actions-plus" /></svg>', $this->icon->getMarkup());
70  }
71 
76  {
77  $this->subject->prepareIconMarkup($this->icon, [
78  'sprite' => 'EXT:core/Resources/Public/Images/sprites/actions.svg#actions-plus',
79  'source' => 'EXT:core/Resources/Public/Images/svg/actions-plus.svg',
80  ]);
81  self::assertEquals('<svg class="icon-color"><use xlink:href="typo3/sysext/core/Resources/Public/Images/sprites/actions.svg#actions-plus" /></svg>', $this->icon->getMarkup());
82  }
83 
88  {
89  $testFile = GeneralUtility::tempnam('svg_', '.svg');
90  $this->testFilesToDelete[] = $testFile;
91  $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>';
92  file_put_contents($testFile, $svgTestFileContent);
93  $this->testFilesToDelete[] = GeneralUtility::tempnam('svg_', '.svg');
94  $this->subject->prepareIconMarkup($this->icon, [
95  'sprite' => $testFile,
96  'source' => $testFile,
97  ]);
98  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(‪SvgSpriteIconProvider::MARKUP_IDENTIFIER_INLINE));
99  }
100 }
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup
‪getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgSpriteIconProviderTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\prepareIconMarkupWithRelativeSourceReturnsInstanceOfIconWithCorrectMarkup
‪prepareIconMarkupWithRelativeSourceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgSpriteIconProviderTest.php:50
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\MARKUP_IDENTIFIER_INLINE
‪const MARKUP_IDENTIFIER_INLINE
Definition: AbstractSvgIconProvider.php:32
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest
Definition: SvgSpriteIconProviderTest.php:31
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:27
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup
‪prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgSpriteIconProviderTest.php:62
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Core\Imaging\IconProvider\SvgSpriteIconProvider
Definition: SvgSpriteIconProvider.php:30
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\$icon
‪Icon $icon
Definition: SvgSpriteIconProviderTest.php:36
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\$subject
‪SvgSpriteIconProvider $subject
Definition: SvgSpriteIconProviderTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\getIconWithInlineOptionReturnsCleanSvgMarkup
‪getIconWithInlineOptionReturnsCleanSvgMarkup()
Definition: SvgSpriteIconProviderTest.php:86
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\setUp
‪setUp()
Definition: SvgSpriteIconProviderTest.php:38
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider
Definition: BitmapIconProviderTest.php:18