‪TYPO3CMS  11.5
FieldControlTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
34 class ‪FieldControlTest extends UnitTestCase
35 {
36  use ProphecyTrait;
37 
41  public function ‪renderMergesResultOfSingleControls(): void
42  {
43  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
44  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
45  $iconProphecy = $this->prophesize(Icon::class);
46  $iconProphecy->render()->shouldBeCalled()->willReturn('');
47  $iconFactoryProphecy->getIcon(Argument::cetera())->shouldBeCalled()->willReturn($iconProphecy->reveal());
48 
49  $languageServiceProphecy = $this->prophesize(LanguageService::class);
50  $languageServiceProphecy->sL(Argument::cetera())->willReturnArgument(0);
51  ‪$GLOBALS['LANG'] = $languageServiceProphecy->reveal();
52 
53  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
54  $data = [
55  'renderData' => [
56  'fieldControl' => [
57  'aControl' => [
58  'renderType' => 'aControl',
59  ],
60  'anotherControl' => [
61  'renderType' => 'anotherControl',
62  'after' => [ 'aControl' ],
63  ],
64  ],
65  ],
66  ];
67 
68  $aControlProphecy = $this->prophesize(AbstractNode::class);
69  $aControlProphecy->render()->willReturn(
70  [
71  'iconIdentifier' => 'actions-open',
72  'title' => 'aTitle',
73  'linkAttributes' => [ 'href' => '' ],
74  'additionalJavaScriptPost' => [ 'someJavaScript' ],
75  'requireJsModules' => [
76  'aModule',
77  ],
78  ]
79  );
80  $aControlNodeFactoryInput = $data;
81  $aControlNodeFactoryInput['renderData']['fieldControlOptions'] = [];
82  $aControlNodeFactoryInput['renderType'] = 'aControl';
83  $nodeFactoryProphecy->create($aControlNodeFactoryInput)->willReturn($aControlProphecy->reveal());
84 
85  $anotherControlProphecy = $this->prophesize(AbstractNode::class);
86  $anotherControlProphecy->render()->willReturn(
87  [
88  'iconIdentifier' => 'actions-close',
89  'title' => 'aTitle',
90  'linkAttributes' => [ 'href' => '' ],
91  'requireJsModules' => [
92  'anotherModule',
93  ],
94  ]
95  );
96  $anotherControlNodeFactoryInput = $data;
97  $anotherControlNodeFactoryInput['renderData']['fieldControlOptions'] = [];
98  $anotherControlNodeFactoryInput['renderType'] = 'anotherControl';
99  $nodeFactoryProphecy->create($anotherControlNodeFactoryInput)->willReturn($anotherControlProphecy->reveal());
100 
101  $expected = [
102  'additionalJavaScriptPost' => [
103  'someJavaScript',
104  ],
105  'additionalHiddenFields' => [],
106  'additionalInlineLanguageLabelFiles' => [],
107  'stylesheetFiles' => [],
108  'requireJsModules' => [
109  'aModule',
110  'anotherModule',
111  ],
112  'inlineData' => [],
113  'html' => '\n<a class="btn btn-default">\n...>\n</a>',
114  ];
115  $result = (new ‪FieldControl($nodeFactoryProphecy->reveal(), $data))->render();
116  // We're not interested in testing the html merge here
117  $expected['html'] = $result['html'];
118 
119  self::assertEquals($expected, $result);
120  }
121 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeExpansion\FieldControlTest
Definition: FieldControlTest.php:35
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Form\NodeExpansion\FieldControl
Definition: FieldControl.php:41
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeExpansion\FieldControlTest\renderMergesResultOfSingleControls
‪renderMergesResultOfSingleControls()
Definition: FieldControlTest.php:40
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeExpansion
Definition: FieldControlTest.php:18
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50