‪TYPO3CMS  9.5
FieldControlTest.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 
17 use Prophecy\Argument;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪FieldControlTest extends UnitTestCase
31 {
36  {
37  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
38  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
39  $iconProphecy = $this->prophesize(Icon::class);
40  $iconProphecy->render()->shouldBeCalled()->willReturn('');
41  $iconFactoryProphecy->getIcon(Argument::cetera())->shouldBeCalled()->willReturn($iconProphecy->reveal());
42 
43  $languageServiceProphecy = $this->prophesize(LanguageService::class);
44  $languageServiceProphecy->sL(Argument::cetera())->willReturnArgument(0);
45  ‪$GLOBALS['LANG'] = $languageServiceProphecy->reveal();
46 
47  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
48  $data = [
49  'renderData' => [
50  'fieldControl' => [
51  'aControl' => [
52  'renderType' => 'aControl',
53  ],
54  'anotherControl' => [
55  'renderType' => 'anotherControl',
56  'after' => [ 'aControl' ],
57  ],
58  ],
59  ],
60  ];
61 
62  $aControlProphecy = $this->prophesize(AbstractNode::class);
63  $aControlProphecy->render()->willReturn(
64  [
65  'iconIdentifier' => 'actions-open',
66  'title' => 'aTitle',
67  'linkAttributes' => [ 'href' => '' ],
68  'additionalJavaScriptPost' => [ 'someJavaScript' ],
69  'requireJsModules' => [
70  'aModule',
71  ],
72  ]
73  );
74  $aControlNodeFactoryInput = $data;
75  $aControlNodeFactoryInput['renderData']['fieldControlOptions'] = [];
76  $aControlNodeFactoryInput['renderType'] = 'aControl';
77  $nodeFactoryProphecy->create($aControlNodeFactoryInput)->willReturn($aControlProphecy->reveal());
78 
79  $anotherControlProphecy = $this->prophesize(AbstractNode::class);
80  $anotherControlProphecy->render()->willReturn(
81  [
82  'iconIdentifier' => 'actions-close',
83  'title' => 'aTitle',
84  'linkAttributes' => [ 'href' => '' ],
85  'requireJsModules' => [
86  'anotherModule',
87  ],
88  ]
89  );
90  $anotherControlNodeFactoryInput = $data;
91  $anotherControlNodeFactoryInput['renderData']['fieldControlOptions'] = [];
92  $anotherControlNodeFactoryInput['renderType'] = 'anotherControl';
93  $nodeFactoryProphecy->create($anotherControlNodeFactoryInput)->willReturn($anotherControlProphecy->reveal());
94 
95  $expected = [
96  'additionalJavaScriptPost' => [
97  'someJavaScript',
98  ],
99  'additionalJavaScriptSubmit' => [],
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  $this->assertEquals($expected, $result);
115  }
116 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeExpansion\FieldControlTest
Definition: FieldControlTest.php:31
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Backend\Form\NodeExpansion\FieldControl
Definition: FieldControl.php:39
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeExpansion\FieldControlTest\renderMergesResultOfSingleControls
‪renderMergesResultOfSingleControls()
Definition: FieldControlTest.php:35
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeExpansion
Definition: FieldControlTest.php:2
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45