TYPO3 CMS  TYPO3_8-7
IconViewHelperTest.php
Go to the documentation of this file.
1 <?php
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 
24 
28 class IconViewHelperTest extends ViewHelperBaseTestcase
29 {
33  protected $viewHelper;
34 
35  protected function setUp()
36  {
37  parent::setUp();
38  $this->viewHelper = $this->getAccessibleMock(IconViewHelper::class, ['renderChildren']);
39  $this->injectDependenciesIntoViewHelper($this->viewHelper);
40  $this->viewHelper->initializeArguments();
41  }
42 
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->viewHelper->setArguments([
56  'identifier' => 'myIdentifier',
57  'size' => Icon::SIZE_SMALL
58  ]);
59 
60  $this->assertSame('htmlFoo', $this->viewHelper->render());
61  }
62 
67  {
68  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
69  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
70  $iconProphecy = $this->prophesize(Icon::class);
71 
72  $iconFactoryProphecy->getIcon('myIdentifier', Icon::SIZE_LARGE, null, IconState::cast(IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
73  $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
74 
75  $this->viewHelper->setArguments([
76  'identifier' => 'myIdentifier',
77  'size' => Icon::SIZE_LARGE
78  ]);
79 
80  $this->assertSame('htmlFoo', $this->viewHelper->render());
81  }
82 
87  {
88  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
89  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
90  $iconProphecy = $this->prophesize(Icon::class);
91 
92  $iconFactoryProphecy->getIcon('myIdentifier', Icon::SIZE_SMALL, null, IconState::cast(IconState::STATE_DISABLED))->shouldBeCalled()->willReturn($iconProphecy->reveal());
93  $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
94 
95  $this->viewHelper->setArguments([
96  'identifier' => 'myIdentifier',
97  'size' => Icon::SIZE_SMALL,
98  'overlay' => null,
100  ]);
101 
102  $this->assertSame('htmlFoo', $this->viewHelper->render());
103  }
104 
109  {
110  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
111  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
112  $iconProphecy = $this->prophesize(Icon::class);
113 
114  $iconFactoryProphecy->getIcon('myIdentifier', Argument::any(), 'overlayString', IconState::cast(IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
115  $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
116 
117  $this->viewHelper->setArguments([
118  'identifier' => 'myIdentifier',
119  'size' => Icon::SIZE_LARGE,
120  'overlay' => 'overlayString'
121  ]);
122  $this->assertSame('htmlFoo', $this->viewHelper->render());
123  }
124 }
static addInstance($className, $instance)