‪TYPO3CMS  9.5
IconViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Prophecy\Argument;
24 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
25 
29 class ‪IconViewHelperTest extends ViewHelperBaseTestcase
30 {
34  protected ‪$viewHelper;
35 
36  protected function ‪setUp()
37  {
38  parent::setUp();
39  $this->viewHelper = $this->getAccessibleMock(IconViewHelper::class, ['renderChildren']);
40  $this->injectDependenciesIntoViewHelper($this->viewHelper);
41  $this->viewHelper->initializeArguments();
42  }
43 
48  {
49  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
50  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
51  $iconProphecy = $this->prophesize(Icon::class);
52 
53  $iconFactoryProphecy->getIcon('myIdentifier', ‪Icon::SIZE_SMALL, null, ‪IconState::cast(‪IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
54  $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
55 
56  $this->viewHelper->setArguments([
57  'identifier' => 'myIdentifier',
58  'size' => ‪Icon::SIZE_SMALL,
59  'overlay' => null,
61  'alternativeMarkupIdentifier' => null
62  ]);
63 
64  $this->assertSame('htmlFoo', $this->viewHelper->render());
65  }
66 
71  {
72  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
73  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
74  $iconProphecy = $this->prophesize(Icon::class);
75 
76  $iconFactoryProphecy->getIcon('myIdentifier', ‪Icon::SIZE_LARGE, null, ‪IconState::cast(‪IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
77  $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
78 
79  $this->viewHelper->setArguments([
80  'identifier' => 'myIdentifier',
81  'size' => ‪Icon::SIZE_LARGE,
82  'overlay' => null,
84  'alternativeMarkupIdentifier' => null
85  ]);
86 
87  $this->assertSame('htmlFoo', $this->viewHelper->render());
88  }
89 
94  {
95  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
96  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
97  $iconProphecy = $this->prophesize(Icon::class);
98 
99  $iconFactoryProphecy->getIcon('myIdentifier', ‪Icon::SIZE_SMALL, null, ‪IconState::cast(‪IconState::STATE_DISABLED))->shouldBeCalled()->willReturn($iconProphecy->reveal());
100  $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
101 
102  $this->viewHelper->setArguments([
103  'identifier' => 'myIdentifier',
104  'size' => ‪Icon::SIZE_SMALL,
105  'overlay' => null,
107  'alternativeMarkupIdentifier' => null
108  ]);
109 
110  $this->assertSame('htmlFoo', $this->viewHelper->render());
111  }
112 
117  {
118  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
119  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
120  $iconProphecy = $this->prophesize(Icon::class);
121 
122  $iconFactoryProphecy->getIcon('myIdentifier', Argument::any(), 'overlayString', ‪IconState::cast(‪IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
123  $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
124 
125  $this->viewHelper->setArguments([
126  'identifier' => 'myIdentifier',
127  'size' => ‪Icon::SIZE_LARGE,
128  'overlay' => 'overlayString',
130  'alternativeMarkupIdentifier' => null
131  ]);
132  $this->assertSame('htmlFoo', $this->viewHelper->render());
133  }
134 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithGivenSizeAndReturnsResult
‪renderCallsIconFactoryWithGivenSizeAndReturnsResult()
Definition: IconViewHelperTest.php:69
‪TYPO3\CMS\Core\Type\Icon\IconState\STATE_DISABLED
‪const STATE_DISABLED
Definition: IconState.php:34
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers
Definition: IconForRecordViewHelperTest.php:2
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:182
‪TYPO3\CMS\Core\Type\Icon\IconState\STATE_DEFAULT
‪const STATE_DEFAULT
Definition: IconState.php:29
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest
Definition: IconViewHelperTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\setUp
‪setUp()
Definition: IconViewHelperTest.php:35
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\$viewHelper
‪IconViewHelper $viewHelper
Definition: IconViewHelperTest.php:33
‪TYPO3\CMS\Core\Type\Icon\IconState
Definition: IconState.php:23
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithGivenStateAndReturnsResult
‪renderCallsIconFactoryWithGivenStateAndReturnsResult()
Definition: IconViewHelperTest.php:92
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithDefaultSizeAndDefaultStateAndReturnsResult
‪renderCallsIconFactoryWithDefaultSizeAndDefaultStateAndReturnsResult()
Definition: IconViewHelperTest.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\ViewHelpers\IconViewHelper
Definition: IconViewHelper.php:56
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_LARGE
‪const SIZE_LARGE
Definition: Icon.php:39
‪TYPO3\CMS\Core\Tests\Unit\ViewHelpers\IconViewHelperTest\renderCallsIconFactoryWithGivenOverlayAndReturnsResult
‪renderCallsIconFactoryWithGivenOverlayAndReturnsResult()
Definition: IconViewHelperTest.php:115