2b724c62b38e6d580b54fc04fbcb21398e4f168e
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Controller / Wizard / SuggestWizardControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Controller\Wizard;
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 Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Controller\Wizard\SuggestWizardController;
20 use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Test case
25 */
26 class SuggestWizardControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
28 /**
29 * Subject is not notice free, disable E_NOTICES
30 */
31 protected static $suppressNotices = true;
32
33 /**
34 * @test
35 */
36 public function getFlexFieldConfigurationThrowsExceptionIfSimpleFlexFieldIsNotFound()
37 {
38 $responseProphecy = $this->prophesize(ResponseInterface::class);
39 $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
40 $serverRequestProphecy->getParsedBody()->willReturn([
41 'value' => 'theSearchValue',
42 'table' => 'aTable',
43 'field' => 'aField',
44 'uid' => 'aUid',
45 'pid' => 'aPid',
46 'dataStructureIdentifier' => ['anIdentifier'],
47 'flexFormSheetName' => 'sDb',
48 'flexFormFieldName' => 'aField',
49 'flexFormContainerName' => '',
50 'flexFormContainerFieldName' => '',
51 ]);
52
53 $dataStructure = [
54 'sheets' => [
55 'sDb' => [
56 'ROOT' => [
57 'el' => [
58 'differentField' => [
59 'TCEforms' => [
60 'config' => [
61 'Sublevel field configuration',
62 ],
63 ],
64 ],
65 ],
66 ],
67 ],
68 ],
69 ];
70 $flexFormToolsProphecy = $this->prophesize(FlexFormTools::class);
71 GeneralUtility::addInstance(FlexFormTools::class, $flexFormToolsProphecy->reveal());
72 $flexFormToolsProphecy->parseDataStructureByIdentifier(json_encode(['anIdentifier']))->willReturn($dataStructure);
73
74 $this->expectException(\RuntimeException::class);
75 $this->expectExceptionCode(1480609491);
76 (new SuggestWizardController())->searchAction($serverRequestProphecy->reveal(), $responseProphecy->reveal());
77 }
78
79 /**
80 * @test
81 */
82 public function getFlexFieldConfigurationThrowsExceptionIfSectionContainerFlexFieldIsNotFound()
83 {
84 $responseProphecy = $this->prophesize(ResponseInterface::class);
85 $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
86 $serverRequestProphecy->getParsedBody()->willReturn([
87 'value' => 'theSearchValue',
88 'table' => 'aTable',
89 'field' => 'aField',
90 'uid' => 'aUid',
91 'pid' => 'aPid',
92 'dataStructureIdentifier' => ['anIdentifier'],
93 'flexFormSheetName' => 'sDb',
94 'flexFormFieldName' => 'aField',
95 'flexFormContainerName' => 'aContainer',
96 'flexFormContainerFieldName' => 'aContainerFieldName',
97 ]);
98
99 $dataStructure = [
100 'sheets' => [
101 'sDb' => [
102 'ROOT' => [
103 'el' => [
104 'notTheFieldYouAreLookingFor' => [
105 'TCEforms' => [
106 'config' => [
107 'Sublevel field configuration',
108 ],
109 ],
110 ],
111 ],
112 ],
113 ],
114 ],
115 ];
116 $flexFormToolsProphecy = $this->prophesize(FlexFormTools::class);
117 GeneralUtility::addInstance(FlexFormTools::class, $flexFormToolsProphecy->reveal());
118 $flexFormToolsProphecy->parseDataStructureByIdentifier(json_encode(['anIdentifier']))->willReturn($dataStructure);
119
120 $this->expectException(\RuntimeException::class);
121 $this->expectExceptionCode(1480611208);
122 (new SuggestWizardController())->searchAction($serverRequestProphecy->reveal(), $responseProphecy->reveal());
123 }
124
125 /**
126 * @test
127 * @dataProvider isTableHiddenIsProperlyRetrievedDataProvider
128 */
129 public function isTableHiddenIsProperlyRetrieved($expected, $array)
130 {
131 $subject = $this->getAccessibleMock(SuggestWizardController::class, ['dummy'], [], '', false);
132 $this->assertEquals($expected, $subject->_call('isTableHidden', $array));
133 }
134
135 public function isTableHiddenIsProperlyRetrievedDataProvider()
136 {
137 return [
138 'notSetValue' => [false, ['ctrl' => ['hideTable' => null]]],
139 'true' => [true, ['ctrl' => ['hideTable' => true]]],
140 'false' => [false, ['ctrl' => ['hideTable' => false]]],
141 'string with true' => [true, ['ctrl' => ['hideTable' => '1']]],
142 'string with false' => [false, ['ctrl' => ['hideTable' => '0']]],
143 ];
144 }
145 }