‪TYPO3CMS  10.4
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\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪SvgSpriteIconProviderTest extends UnitTestCase
29 {
33  protected ‪$subject;
34 
38  protected ‪$icon;
39 
43  protected function ‪setUp(): void
44  {
45  parent::setUp();
46  $this->subject = new ‪SvgSpriteIconProvider();
47  $this->icon = GeneralUtility::makeInstance(Icon::class);
48  $this->icon->setIdentifier('foo');
49  $this->icon->setSize(‪Icon::SIZE_SMALL);
50  }
51 
56  {
57  $this->subject->prepareIconMarkup($this->icon, [
58  'sprite' => 'fileadmin/sprites/actions.svg#actions-add',
59  'source' => 'fileadmin/svg/actions-add.svg',
60  ]);
61  self::assertEquals('<svg class="icon-color" role="img"><use xlink:href="fileadmin/sprites/actions.svg#actions-add" /></svg>', $this->icon->getMarkup());
62  }
63 
68  {
69  $this->subject->prepareIconMarkup($this->icon, [
70  'sprite' => '/fileadmin/sprites/actions.svg#actions-add',
71  'source' => '/fileadmin/svg/actions-add.svg',
72  ]);
73  self::assertEquals('<svg class="icon-color" role="img"><use xlink:href="/fileadmin/sprites/actions.svg#actions-add" /></svg>', $this->icon->getMarkup());
74  }
75 
80  {
81  $this->subject->prepareIconMarkup($this->icon, [
82  'sprite' => 'EXT:core/Resources/Public/Images/sprites/actions.svg#actions-add',
83  'source' => 'EXT:core/Resources/Public/Images/svg/actions-add.svg',
84  ]);
85  self::assertEquals('<svg class="icon-color" role="img"><use xlink:href="typo3/sysext/core/Resources/Public/Images/sprites/actions.svg#actions-add" /></svg>', $this->icon->getMarkup());
86  }
87 
92  {
93  $testFile = GeneralUtility::tempnam('svg_', '.svg');
94  $this->testFilesToDelete[] = $testFile;
95  $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>';
96  file_put_contents($testFile, $svgTestFileContent);
97  $this->testFilesToDelete[] = GeneralUtility::tempnam('svg_', '.svg');
98  $this->subject->prepareIconMarkup($this->icon, [
99  'sprite' => $testFile,
100  'source' => $testFile,
101  ]);
102  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));
103  }
104 }
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup
‪getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgSpriteIconProviderTest.php:77
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\prepareIconMarkupWithRelativeSourceReturnsInstanceOfIconWithCorrectMarkup
‪prepareIconMarkupWithRelativeSourceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgSpriteIconProviderTest.php:53
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\MARKUP_IDENTIFIER_INLINE
‪const MARKUP_IDENTIFIER_INLINE
Definition: AbstractSvgIconProvider.php:29
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest
Definition: SvgSpriteIconProviderTest.php:29
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup
‪prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgSpriteIconProviderTest.php:65
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\$subject
‪TYPO3 CMS Core Imaging IconProvider SvgSpriteIconProvider $subject
Definition: SvgSpriteIconProviderTest.php:32
‪TYPO3\CMS\Core\Imaging\IconProvider\SvgSpriteIconProvider
Definition: SvgSpriteIconProvider.php:31
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\$icon
‪Icon $icon
Definition: SvgSpriteIconProviderTest.php:36
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\getIconWithInlineOptionReturnsCleanSvgMarkup
‪getIconWithInlineOptionReturnsCleanSvgMarkup()
Definition: SvgSpriteIconProviderTest.php:89
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgSpriteIconProviderTest\setUp
‪setUp()
Definition: SvgSpriteIconProviderTest.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider
Definition: BitmapIconProviderTest.php:16