‪TYPO3CMS  ‪main
IconViewHelperTest.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;
23 use TYPO3\CMS\Core\Imaging\IconSize;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 use TYPO3Fluid\Fluid\View\TemplateView;
29 
30 final class ‪IconViewHelperTest extends FunctionalTestCase
31 {
32  protected bool ‪$initializeDatabase = false;
33 
34  #[Test]
36  {
37  $iconFactoryMock = $this->createMock(IconFactory::class);
38  GeneralUtility::addInstance(IconFactory::class, $iconFactoryMock);
39  $iconMock = $this->createMock(Icon::class);
40  $iconFactoryMock->expects(self::atLeastOnce())->method('getIcon')
41  ->with('myIdentifier', IconSize::SMALL, null, IconState::STATE_DEFAULT)
42  ->willReturn($iconMock);
43  $iconMock->expects(self::atLeastOnce())->method('render')->willReturn('htmlFoo');
44 
45  $context = $this->get(RenderingContextFactory::class)->create();
46  $context->getTemplatePaths()->setTemplateSource('<core:icon identifier="myIdentifier" size="small" state="default" />');
47  self::assertSame('htmlFoo', (new TemplateView($context))->render());
48  }
49 
50  #[Test]
52  {
53  $iconFactoryMock = $this->createMock(IconFactory::class);
54  GeneralUtility::addInstance(IconFactory::class, $iconFactoryMock);
55  $iconMock = $this->createMock(Icon::class);
56  $iconFactoryMock->expects(self::atLeastOnce())->method('getIcon')
57  ->with('myIdentifier', IconSize::LARGE, null, IconState::STATE_DEFAULT)
58  ->willReturn($iconMock);
59  $iconMock->expects(self::atLeastOnce())->method('render')->willReturn('htmlFoo');
60 
61  $context = $this->get(RenderingContextFactory::class)->create();
62  $context->getTemplatePaths()->setTemplateSource('<core:icon identifier="myIdentifier" size="large" state="default" />');
63  self::assertSame('htmlFoo', (new TemplateView($context))->render());
64  }
65 
66  #[Test]
68  {
69  $iconFactoryMock = $this->createMock(IconFactory::class);
70  GeneralUtility::addInstance(IconFactory::class, $iconFactoryMock);
71  $iconMock = $this->createMock(Icon::class);
72  $iconFactoryMock->expects(self::atLeastOnce())->method('getIcon')
73  ->with('myIdentifier', IconSize::SMALL, null, ‪IconState::STATE_DISABLED)
74  ->willReturn($iconMock);
75  $iconMock->expects(self::atLeastOnce())->method('render')->willReturn('htmlFoo');
76 
77  $context = $this->get(RenderingContextFactory::class)->create();
78  $context->getTemplatePaths()->setTemplateSource('<core:icon identifier="myIdentifier" size="small" state="disabled" />');
79  self::assertSame('htmlFoo', (new TemplateView($context))->render());
80  }
81 
82  #[Test]
84  {
85  $iconFactoryMock = $this->createMock(IconFactory::class);
86  GeneralUtility::addInstance(IconFactory::class, $iconFactoryMock);
87  $iconMock = $this->createMock(Icon::class);
88  $iconFactoryMock->expects(self::atLeastOnce())->method('getIcon')
89  ->with('myIdentifier', self::anything(), 'overlayString', IconState::STATE_DEFAULT)
90  ->willReturn($iconMock);
91  $iconMock->expects(self::atLeastOnce())->method('render')->willReturn('htmlFoo');
92 
93  $context = $this->get(RenderingContextFactory::class)->create();
94  $context->getTemplatePaths()->setTemplateSource('<core:icon identifier="myIdentifier" size="large" state="default" overlay="overlayString" />');
95  self::assertSame('htmlFoo', (new TemplateView($context))->render());
96  }
97 
98  #[Test]
100  {
101  $iconFactoryMock = $this->createMock(IconFactory::class);
102  GeneralUtility::addInstance(IconFactory::class, $iconFactoryMock);
103  $iconMock = $this->createMock(Icon::class);
104  $iconFactoryMock->expects(self::atLeastOnce())->method('getIcon')
105  ->with('myIdentifier', self::anything(), null, IconState::STATE_DEFAULT)
106  ->willReturn($iconMock);
107  $iconMock->expects(self::atLeastOnce())->method('setTitle')->with('myTitle')->willReturn($iconMock);
108  $iconMock->expects(self::atLeastOnce())->method('render')->willReturn('htmlFoo');
109 
110  $context = $this->get(RenderingContextFactory::class)->create();
111  $context->getTemplatePaths()->setTemplateSource('<core:icon identifier="myIdentifier" size="large" state="default" title="myTitle" />');
112  self::assertSame('htmlFoo', (new TemplateView($context))->render());
113  }
114 }
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:27
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\Tests\Functional\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithDefaultSizeAndDefaultStateAndReturnsResult
‪renderCallsIconFactoryWithDefaultSizeAndDefaultStateAndReturnsResult()
Definition: IconViewHelperTest.php:35
‪TYPO3\CMS\Core\Tests\Functional\ViewHelpers\IconViewHelperTest
Definition: IconViewHelperTest.php:31
‪TYPO3\CMS\Core\Tests\Functional\ViewHelpers
Definition: IconForRecordViewHelperTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithGivenOverlayAndReturnsResult
‪renderCallsIconFactoryWithGivenOverlayAndReturnsResult()
Definition: IconViewHelperTest.php:83
‪TYPO3\CMS\Core\Tests\Functional\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithGivenSizeAndReturnsResult
‪renderCallsIconFactoryWithGivenSizeAndReturnsResult()
Definition: IconViewHelperTest.php:51
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Core\Imaging\IconState
‪IconState
Definition: IconState.php:24
‪TYPO3\CMS\Core\Tests\Functional\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithGivenStateAndReturnsResult
‪renderCallsIconFactoryWithGivenStateAndReturnsResult()
Definition: IconViewHelperTest.php:67
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Functional\ViewHelpers\IconViewHelperTest\titleIsPassedFromViewhelperToIconClass
‪titleIsPassedFromViewhelperToIconClass()
Definition: IconViewHelperTest.php:99
‪TYPO3\CMS\Core\Imaging\STATE_DISABLED
‪@ STATE_DISABLED
Definition: IconState.php:26
‪TYPO3\CMS\Core\Tests\Functional\ViewHelpers\IconViewHelperTest\$initializeDatabase
‪bool $initializeDatabase
Definition: IconViewHelperTest.php:32