[TASK] Fix CGL errors
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / ViewHelpers / IconViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\ViewHelpers;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Prophecy\Argument;
18 use TYPO3\CMS\Core\Imaging\Icon;
19 use TYPO3\CMS\Core\Imaging\IconFactory;
20 use TYPO3\CMS\Core\Type\Icon\IconState;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Core\ViewHelpers\IconViewHelper;
23 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
24
25 /**
26 * Test case
27 */
28 class IconViewHelperTest extends ViewHelperBaseTestcase
29 {
30 /**
31 * @var IconViewHelper
32 */
33 protected $viewHelper;
34
35 protected function setUp()
36 {
37 parent::setUp();
38 $this->viewHelper = $this->getAccessibleMock(IconViewHelper::class, array('renderChildren'));
39 $this->injectDependenciesIntoViewHelper($this->viewHelper);
40 $this->viewHelper->initializeArguments();
41 }
42
43 /**
44 * @test
45 */
46 public function renderCallsIconFactoryWithDefaultSizeAndDefaultStateAndReturnsResult()
47 {
48 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
49 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
50 $iconProphecy = $this->prophesize(Icon::class);
51
52 $iconFactoryProphecy->getIcon('myIdentifier', Icon::SIZE_SMALL, null, IconState::cast(IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
53 $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
54
55 $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier'));
56 }
57
58 /**
59 * @test
60 */
61 public function renderCallsIconFactoryWithGivenSizeAndReturnsResult()
62 {
63 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
64 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
65 $iconProphecy = $this->prophesize(Icon::class);
66
67 $iconFactoryProphecy->getIcon('myIdentifier', Icon::SIZE_LARGE, null, IconState::cast(IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
68 $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
69
70 $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier', Icon::SIZE_LARGE));
71 }
72
73 /**
74 * @test
75 */
76 public function renderCallsIconFactoryWithGivenStateAndReturnsResult()
77 {
78 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
79 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
80 $iconProphecy = $this->prophesize(Icon::class);
81
82 $iconFactoryProphecy->getIcon('myIdentifier', Icon::SIZE_SMALL, null, IconState::cast(IconState::STATE_DISABLED))->shouldBeCalled()->willReturn($iconProphecy->reveal());
83 $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
84
85 $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier', Icon::SIZE_SMALL, null, IconState::cast(IconState::STATE_DISABLED)));
86 }
87
88 /**
89 * @test
90 */
91 public function renderCallsIconFactoryWithGivenOverlayAndReturnsResult()
92 {
93 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
94 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
95 $iconProphecy = $this->prophesize(Icon::class);
96
97 $iconFactoryProphecy->getIcon('myIdentifier', Argument::any(), 'overlayString', IconState::cast(IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
98 $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
99
100 $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier', Icon::SIZE_LARGE, 'overlayString'));
101 }
102 }