TYPO3 CMS  TYPO3_7-6
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 
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->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier'));
56  }
57 
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 
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 
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 }
static addInstance($className, $instance)
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)