‪TYPO3CMS  10.4
FieldControlTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Argument;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪FieldControlTest extends UnitTestCase
32 {
37  {
38  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
39  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
40  $iconProphecy = $this->prophesize(Icon::class);
41  $iconProphecy->render()->shouldBeCalled()->willReturn('');
42  $iconFactoryProphecy->getIcon(Argument::cetera())->shouldBeCalled()->willReturn($iconProphecy->reveal());
43 
44  $languageServiceProphecy = $this->prophesize(LanguageService::class);
45  $languageServiceProphecy->sL(Argument::cetera())->willReturnArgument(0);
46  ‪$GLOBALS['LANG'] = $languageServiceProphecy->reveal();
47 
48  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
49  $data = [
50  'renderData' => [
51  'fieldControl' => [
52  'aControl' => [
53  'renderType' => 'aControl',
54  ],
55  'anotherControl' => [
56  'renderType' => 'anotherControl',
57  'after' => [ 'aControl' ],
58  ],
59  ],
60  ],
61  ];
62 
63  $aControlProphecy = $this->prophesize(AbstractNode::class);
64  $aControlProphecy->render()->willReturn(
65  [
66  'iconIdentifier' => 'actions-open',
67  'title' => 'aTitle',
68  'linkAttributes' => [ 'href' => '' ],
69  'additionalJavaScriptPost' => [ 'someJavaScript' ],
70  'requireJsModules' => [
71  'aModule',
72  ],
73  ]
74  );
75  $aControlNodeFactoryInput = $data;
76  $aControlNodeFactoryInput['renderData']['fieldControlOptions'] = [];
77  $aControlNodeFactoryInput['renderType'] = 'aControl';
78  $nodeFactoryProphecy->create($aControlNodeFactoryInput)->willReturn($aControlProphecy->reveal());
79 
80  $anotherControlProphecy = $this->prophesize(AbstractNode::class);
81  $anotherControlProphecy->render()->willReturn(
82  [
83  'iconIdentifier' => 'actions-close',
84  'title' => 'aTitle',
85  'linkAttributes' => [ 'href' => '' ],
86  'requireJsModules' => [
87  'anotherModule',
88  ],
89  ]
90  );
91  $anotherControlNodeFactoryInput = $data;
92  $anotherControlNodeFactoryInput['renderData']['fieldControlOptions'] = [];
93  $anotherControlNodeFactoryInput['renderType'] = 'anotherControl';
94  $nodeFactoryProphecy->create($anotherControlNodeFactoryInput)->willReturn($anotherControlProphecy->reveal());
95 
96  $expected = [
97  'additionalJavaScriptPost' => [
98  'someJavaScript',
99  ],
100  'additionalHiddenFields' => [],
101  'additionalInlineLanguageLabelFiles' => [],
102  'stylesheetFiles' => [],
103  'requireJsModules' => [
104  'aModule',
105  'anotherModule',
106  ],
107  'inlineData' => [],
108  'html' => '\n<a class="btn btn-default">\n...>\n</a>'
109  ];
110  $result = (new ‪FieldControl($nodeFactoryProphecy->reveal(), $data))->render();
111  // We're not interested in testing the html merge here
112  $expected['html'] = $result['html'];
113 
114  self::assertEquals($expected, $result);
115  }
116 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeExpansion\FieldControlTest
Definition: FieldControlTest.php:32
‪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:33
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeExpansion\FieldControlTest\renderMergesResultOfSingleControls
‪renderMergesResultOfSingleControls()
Definition: FieldControlTest.php:36
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeExpansion
Definition: FieldControlTest.php:16
‪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:46