‪TYPO3CMS  ‪main
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 PHPUnit\Framework\Attributes\Test;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
31 final class ‪FieldControlTest extends UnitTestCase
32 {
33  #[Test]
34  public function ‪renderMergesResultOfSingleControls(): void
35  {
36  $iconFactoryMock = $this->createMock(IconFactory::class);
37  $iconMock = $this->createMock(Icon::class);
38  $iconMock->expects(self::atLeastOnce())->method('setTitle')->willReturn($iconMock);
39  $iconMock->expects(self::atLeastOnce())->method('render')->willReturn('');
40  $iconFactoryMock->expects(self::atLeastOnce())->method('getIcon')->with(self::anything())->willReturn($iconMock);
41 
42  $languageServiceMock = $this->createMock(LanguageService::class);
43  $languageServiceMock->method('sL')->with(self::anything())->willReturnArgument(0);
44  ‪$GLOBALS['LANG'] = $languageServiceMock;
45 
46  $nodeFactoryMock = $this->createMock(NodeFactory::class);
47  $data = [
48  'renderData' => [
49  'fieldControl' => [
50  'aControl' => [
51  'renderType' => 'aControl',
52  ],
53  'anotherControl' => [
54  'renderType' => 'anotherControl',
55  'after' => [ 'aControl' ],
56  ],
57  ],
58  ],
59  ];
60 
61  $aControlMock = $this->createMock(AbstractNode::class);
62  $aControlMock->method('render')->willReturn(
63  [
64  'iconIdentifier' => 'actions-open',
65  'title' => 'aTitle',
66  'linkAttributes' => [ 'href' => '' ],
67  'javaScriptModules' => [
68  'aModule',
69  ],
70  ]
71  );
72  $aControlNodeFactoryInput = $data;
73  $aControlNodeFactoryInput['renderData']['fieldControlOptions'] = [];
74  $aControlNodeFactoryInput['renderType'] = 'aControl';
75 
76  $anotherControlMock = $this->createMock(AbstractNode::class);
77  $anotherControlMock->method('render')->willReturn(
78  [
79  'iconIdentifier' => 'actions-close',
80  'title' => 'aTitle',
81  'linkAttributes' => [ 'href' => '' ],
82  'javaScriptModules' => [
83  'anotherModule',
84  ],
85  ]
86  );
87  $anotherControlNodeFactoryInput = $data;
88  $anotherControlNodeFactoryInput['renderData']['fieldControlOptions'] = [];
89  $anotherControlNodeFactoryInput['renderType'] = 'anotherControl';
90 
91  $series = [
92  [$aControlNodeFactoryInput, $aControlMock],
93  [$anotherControlNodeFactoryInput, $anotherControlMock],
94  ];
95  $nodeFactoryMock->method('create')->willReturnCallback(function (array $data) use (&$series): ‪NodeInterface {
96  [$expectedArgs, $return] = array_shift($series);
97  self::assertSame($expectedArgs, $data);
98  return $return;
99  });
100 
101  $expected = [
102  'additionalHiddenFields' => [],
103  'additionalInlineLanguageLabelFiles' => [],
104  'stylesheetFiles' => [],
105  'javaScriptModules' => [
106  'aModule',
107  'anotherModule',
108  ],
109  'inlineData' => [],
110  'html' => '\n<a class="btn btn-default">\n...>\n</a>',
111  ];
112  $subject = new ‪FieldControl($nodeFactoryMock, $iconFactoryMock, new ‪DependencyOrderingService());
113  $subject->setData($data);
114  $result = $subject->render();
115  // We're not interested in testing the html merge here
116  $expected['html'] = $result['html'];
117 
118  self::assertEquals($expected, $result);
119  }
120 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeExpansion\FieldControlTest
Definition: FieldControlTest.php:32
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:27
‪TYPO3\CMS\Backend\Form\NodeExpansion\FieldControl
Definition: FieldControl.php:42
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeExpansion\FieldControlTest\renderMergesResultOfSingleControls
‪renderMergesResultOfSingleControls()
Definition: FieldControlTest.php:34
‪TYPO3\CMS\Backend\Form\NodeInterface
Definition: NodeInterface.php:22
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:40
‪$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:46
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29