‪TYPO3CMS  10.4
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 Prophecy\Argument;
26 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
27 
31 class ‪IconViewHelperTest extends ViewHelperBaseTestcase
32 {
36  protected ‪$viewHelper;
37 
38  protected function ‪setUp(): void
39  {
40  parent::setUp();
41  $this->viewHelper = $this->getAccessibleMock(IconViewHelper::class, ['renderChildren']);
42  $this->injectDependenciesIntoViewHelper($this->viewHelper);
43  $this->viewHelper->initializeArguments();
44  }
45 
50  {
51  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
52  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
53  $iconProphecy = $this->prophesize(Icon::class);
54 
55  $iconFactoryProphecy->getIcon('myIdentifier', ‪Icon::SIZE_SMALL, null, ‪IconState::cast(‪IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
56  $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
57 
58  $this->viewHelper->setArguments([
59  'identifier' => 'myIdentifier',
60  'size' => ‪Icon::SIZE_SMALL,
61  'overlay' => null,
63  'alternativeMarkupIdentifier' => null
64  ]);
65 
66  self::assertSame('htmlFoo', $this->viewHelper->render());
67  }
68 
73  {
74  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
75  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
76  $iconProphecy = $this->prophesize(Icon::class);
77 
78  $iconFactoryProphecy->getIcon('myIdentifier', ‪Icon::SIZE_LARGE, null, ‪IconState::cast(‪IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
79  $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
80 
81  $this->viewHelper->setArguments([
82  'identifier' => 'myIdentifier',
83  'size' => ‪Icon::SIZE_LARGE,
84  'overlay' => null,
86  'alternativeMarkupIdentifier' => null
87  ]);
88 
89  self::assertSame('htmlFoo', $this->viewHelper->render());
90  }
91 
96  {
97  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
98  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
99  $iconProphecy = $this->prophesize(Icon::class);
100 
101  $iconFactoryProphecy->getIcon('myIdentifier', ‪Icon::SIZE_SMALL, null, ‪IconState::cast(‪IconState::STATE_DISABLED))->shouldBeCalled()->willReturn($iconProphecy->reveal());
102  $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
103 
104  $this->viewHelper->setArguments([
105  'identifier' => 'myIdentifier',
106  'size' => ‪Icon::SIZE_SMALL,
107  'overlay' => null,
109  'alternativeMarkupIdentifier' => null
110  ]);
111 
112  self::assertSame('htmlFoo', $this->viewHelper->render());
113  }
114 
119  {
120  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
121  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
122  $iconProphecy = $this->prophesize(Icon::class);
123 
124  $iconFactoryProphecy->getIcon('myIdentifier', Argument::any(), 'overlayString', ‪IconState::cast(‪IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
125  $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
126 
127  $this->viewHelper->setArguments([
128  'identifier' => 'myIdentifier',
129  'size' => ‪Icon::SIZE_LARGE,
130  'overlay' => 'overlayString',
132  'alternativeMarkupIdentifier' => null
133  ]);
134  self::assertSame('htmlFoo', $this->viewHelper->render());
135  }
136 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithGivenSizeAndReturnsResult
‪renderCallsIconFactoryWithGivenSizeAndReturnsResult()
Definition: IconViewHelperTest.php:71
‪TYPO3\CMS\Core\Type\Icon\IconState\STATE_DISABLED
‪const STATE_DISABLED
Definition: IconState.php:35
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers
Definition: IconForRecordViewHelperTest.php:16
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:186
‪TYPO3\CMS\Core\Type\Icon\IconState\STATE_DEFAULT
‪const STATE_DEFAULT
Definition: IconState.php:30
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest
Definition: IconViewHelperTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\setUp
‪setUp()
Definition: IconViewHelperTest.php:37
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\$viewHelper
‪IconViewHelper $viewHelper
Definition: IconViewHelperTest.php:35
‪TYPO3\CMS\Core\Type\Icon\IconState
Definition: IconState.php:24
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithGivenStateAndReturnsResult
‪renderCallsIconFactoryWithGivenStateAndReturnsResult()
Definition: IconViewHelperTest.php:94
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithDefaultSizeAndDefaultStateAndReturnsResult
‪renderCallsIconFactoryWithDefaultSizeAndDefaultStateAndReturnsResult()
Definition: IconViewHelperTest.php:48
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\ViewHelpers\IconViewHelper
Definition: IconViewHelper.php:57
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_LARGE
‪const SIZE_LARGE
Definition: Icon.php:40
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithGivenOverlayAndReturnsResult
‪renderCallsIconFactoryWithGivenOverlayAndReturnsResult()
Definition: IconViewHelperTest.php:117