[FEATURE] Add new ViewHelper for record icons
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / ViewHelpers / IconForRecordViewHelperTest.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 Prophecy\Prophecy\ObjectProphecy;
19 use TYPO3\CMS\Core\Imaging\Icon;
20 use TYPO3\CMS\Core\Imaging\IconFactory;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Core\ViewHelpers\IconForRecordViewHelper;
23 use TYPO3\CMS\Core\ViewHelpers\IconViewHelper;
24 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
25 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
26
27 /**
28 * Test case
29 */
30 class IconForRecordViewHelperTest extends ViewHelperBaseTestcase
31 {
32 /**
33 * @var Icon|ObjectProphecy
34 */
35 protected $iconProphecy;
36
37 /**
38 * @var IconFactory|ObjectProphecy
39 */
40 protected $iconFactoryProphecy;
41
42 /**
43 * @var IconViewHelper
44 */
45 protected $viewHelper;
46
47 protected function setUp()
48 {
49 parent::setUp();
50 $this->iconProphecy = $this->prophesize(Icon::class);
51 $this->iconProphecy->render(Argument::any())->willReturn('icon html');
52 $this->iconFactoryProphecy = $this->prophesize(IconFactory::class);
53 $this->iconFactoryProphecy->getIconForRecord(Argument::cetera())->willReturn($this->iconProphecy->reveal());
54 GeneralUtility::addInstance(IconFactory::class, $this->iconFactoryProphecy->reveal());
55 }
56
57 /**
58 * @test
59 * @return void
60 */
61 public function renderRendersIconByWayOfTheIconFactoryAccordingToGivenArguments()
62 {
63 $renderingContextProphecy = $this->prophesize(RenderingContextInterface::class);
64
65 $row = ['uid' => 123];
66 $arguments = [
67 'table' => 'tt_content',
68 'row' => $row,
69 'size' => Icon::SIZE_LARGE,
70 'alternativeMarkupIdentifier' => 'inline'
71 ];
72 $iconForRecordViewHelper = new IconForRecordViewHelper();
73 $iconForRecordViewHelper->setRenderingContext($renderingContextProphecy->reveal());
74 $iconForRecordViewHelper->setArguments($arguments);
75 $iconForRecordViewHelper->render();
76
77 $this->iconFactoryProphecy->getIconForRecord('tt_content', $row, Icon::SIZE_LARGE)->shouldHaveBeenCalled();
78 $this->iconProphecy->render('inline')->shouldHaveBeenCalled();
79 }
80 }