‪TYPO3CMS  ‪main
SvgIconProviderTest.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 
20 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\CMS\Core\Imaging\IconSize;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 final class ‪SvgIconProviderTest extends UnitTestCase
32 {
34 
38  protected ‪$icon;
39 
40  protected function ‪setUp(): void
41  {
42  parent::setUp();
43  $this->subject = new ‪SvgIconProvider();
44  $this->icon = GeneralUtility::makeInstance(Icon::class);
45  $this->icon->setIdentifier('foo');
46  $this->icon->setSize(IconSize::SMALL);
47  }
48 
49  #[Test]
51  {
52  $this->subject->prepareIconMarkup($this->icon, ['source' => 'fileadmin/foo.svg']);
53  self::assertEquals('<img src="fileadmin/foo.svg" width="16" height="16" alt="" />', $this->icon->getMarkup());
54  }
55 
56  #[Test]
58  {
59  $this->subject->prepareIconMarkup($this->icon, ['source' => ‪Environment::getPublicPath() . '/fileadmin/foo.svg']);
60  self::assertEquals('<img src="fileadmin/foo.svg" width="16" height="16" alt="" />', $this->icon->getMarkup());
61  }
62 
63  #[Test]
65  {
66  $this->subject->prepareIconMarkup($this->icon, ['source' => 'EXT:core/Resources/Public/Images/foo.svg']);
67  self::assertEquals('<img src="typo3/sysext/core/Resources/Public/Images/foo.svg" width="16" height="16" alt="" />', $this->icon->getMarkup());
68  }
69 
70  #[Test]
72  {
73  $testFile = GeneralUtility::tempnam('svg_', '.svg');
74  $this->testFilesToDelete[] = $testFile;
75  $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>';
76  file_put_contents($testFile, $svgTestFileContent);
77  $this->testFilesToDelete[] = GeneralUtility::tempnam('svg_', '.svg');
78  $this->subject->prepareIconMarkup($this->icon, ['source' => $testFile]);
79  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));
80  }
81 }
‪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:70
‪TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\MARKUP_IDENTIFIER_INLINE
‪const MARKUP_IDENTIFIER_INLINE
Definition: AbstractSvgIconProvider.php:32
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:27
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪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:37
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup
‪getIconWithEXTSourceReferenceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgIconProviderTest.php:63
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest
Definition: SvgIconProviderTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup
‪prepareIconMarkupWithAbsoluteSourceReturnsInstanceOfIconWithCorrectMarkup()
Definition: SvgIconProviderTest.php:56
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider\SvgIconProviderTest\$subject
‪SvgIconProvider $subject
Definition: SvgIconProviderTest.php:33
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider
Definition: SvgIconProvider.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Unit\Imaging\IconProvider
Definition: BitmapIconProviderTest.php:18