‪TYPO3CMS  11.5
SuggestWizardControllerTest.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\PhpUnit\ProphecyTrait;
21 use Psr\Http\Message\ServerRequestInterface;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪SuggestWizardControllerTest extends UnitTestCase
31 {
32  use ProphecyTrait;
33 
38  {
39  $dataStructureIdentifier = '{"type":"tca","tableName":"tt_content","fieldName":"pi_flexform","dataStructureKey":"blog_example,list"}';
40  $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
41  $serverRequestProphecy->getParsedBody()->willReturn([
42  'value' => 'theSearchValue',
43  'table' => 'aTable',
44  'field' => 'aField',
45  'uid' => 'aUid',
46  'pid' => 'aPid',
47  'dataStructureIdentifier' => $dataStructureIdentifier,
48  'flexFormSheetName' => 'sDb',
49  'flexFormFieldName' => 'aField',
50  'flexFormContainerName' => '',
51  'flexFormContainerFieldName' => '',
52  ]);
53 
54  $dataStructure = [
55  'sheets' => [
56  'sDb' => [
57  'ROOT' => [
58  'el' => [
59  'differentField' => [
60  'TCEforms' => [
61  'config' => [
62  'Sublevel field configuration',
63  ],
64  ],
65  ],
66  ],
67  ],
68  ],
69  ],
70  ];
71  $flexFormToolsProphecy = $this->prophesize(FlexFormTools::class);
72  GeneralUtility::addInstance(FlexFormTools::class, $flexFormToolsProphecy->reveal());
73  $flexFormToolsProphecy->parseDataStructureByIdentifier($dataStructureIdentifier)->willReturn($dataStructure);
74 
75  $this->expectException(\RuntimeException::class);
76  $this->expectExceptionCode(1480609491);
77  (new ‪SuggestWizardController())->searchAction($serverRequestProphecy->reveal());
78  }
79 
84  {
85  $dataStructureIdentifier = '{"type":"tca","tableName":"tt_content","fieldName":"pi_flexform","dataStructureKey":"blog_example,list"}';
86  $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
87  $serverRequestProphecy->getParsedBody()->willReturn([
88  'value' => 'theSearchValue',
89  'table' => 'aTable',
90  'field' => 'aField',
91  'uid' => 'aUid',
92  'pid' => 'aPid',
93  'dataStructureIdentifier' => $dataStructureIdentifier,
94  'flexFormSheetName' => 'sDb',
95  'flexFormFieldName' => 'aField',
96  'flexFormContainerName' => 'aContainer',
97  'flexFormContainerFieldName' => 'aContainerFieldName',
98  ]);
99 
100  $dataStructure = [
101  'sheets' => [
102  'sDb' => [
103  'ROOT' => [
104  'el' => [
105  'notTheFieldYouAreLookingFor' => [
106  'TCEforms' => [
107  'config' => [
108  'Sublevel field configuration',
109  ],
110  ],
111  ],
112  ],
113  ],
114  ],
115  ],
116  ];
117  $flexFormToolsProphecy = $this->prophesize(FlexFormTools::class);
118  GeneralUtility::addInstance(FlexFormTools::class, $flexFormToolsProphecy->reveal());
119  $flexFormToolsProphecy->parseDataStructureByIdentifier($dataStructureIdentifier)->willReturn($dataStructure);
120 
121  $this->expectException(\RuntimeException::class);
122  $this->expectExceptionCode(1480611208);
123  (new ‪SuggestWizardController())->searchAction($serverRequestProphecy->reveal());
124  }
125 
132  public function ‪isTableHiddenIsProperlyRetrieved(bool $expected, array $array): void
133  {
134  $subject = $this->getAccessibleMock(SuggestWizardController::class, ['dummy'], [], '', false);
135  self::assertEquals($expected, $subject->_call('isTableHidden', $array));
136  }
137 
141  public function ‪isTableHiddenIsProperlyRetrievedDataProvider(): array
142  {
143  return [
144  'notSetValue' => [false, ['ctrl' => ['hideTable' => null]]],
145  'true' => [true, ['ctrl' => ['hideTable' => true]]],
146  'false' => [false, ['ctrl' => ['hideTable' => false]]],
147  'string with true' => [true, ['ctrl' => ['hideTable' => '1']]],
148  'string with false' => [false, ['ctrl' => ['hideTable' => '0']]],
149  ];
150  }
151 
156  public function ‪whereClauseIsProperlyRetrieved(string $expected, array $array): void
157  {
158  $subject = $this->getAccessibleMock(SuggestWizardController::class, ['dummy'], [], '', false);
159  self::assertEquals($expected, $subject->_call('getWhereClause', $array));
160  }
161 
162  public function ‪whereClauseIsProperlyRetrievedDataProvider(): array
163  {
164  return [
165  'no foreign_table' => [
166  '',
167  [],
168  ],
169  'no foreign_table_where' => [
170  '',
171  [
172  'foreign_table' => 'aTable',
173  ],
174  ],
175  'empty where clause' => [
176  '',
177  [
178  'foreign_table' => 'aTable',
179  'foreign_table_where' => '',
180  ],
181  ],
182  'where clause' => [
183  'aTable.pid = 123',
184  [
185  'foreign_table' => 'aTable',
186  'foreign_table_where' => ' aTable.pid = 123 ORDER BY aTable.uid',
187  ],
188  ],
189  ];
190  }
191 }
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Wizard\SuggestWizardControllerTest\isTableHiddenIsProperlyRetrieved
‪isTableHiddenIsProperlyRetrieved(bool $expected, array $array)
Definition: SuggestWizardControllerTest.php:131
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Wizard\SuggestWizardControllerTest\isTableHiddenIsProperlyRetrievedDataProvider
‪array isTableHiddenIsProperlyRetrievedDataProvider()
Definition: SuggestWizardControllerTest.php:140
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Wizard\SuggestWizardControllerTest\whereClauseIsProperlyRetrieved
‪whereClauseIsProperlyRetrieved(string $expected, array $array)
Definition: SuggestWizardControllerTest.php:155
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Wizard\SuggestWizardControllerTest\getFlexFieldConfigurationThrowsExceptionIfSectionContainerFlexFieldIsNotFound
‪getFlexFieldConfigurationThrowsExceptionIfSectionContainerFlexFieldIsNotFound()
Definition: SuggestWizardControllerTest.php:82
‪TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
Definition: FlexFormTools.php:40
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Wizard\SuggestWizardControllerTest\whereClauseIsProperlyRetrievedDataProvider
‪whereClauseIsProperlyRetrievedDataProvider()
Definition: SuggestWizardControllerTest.php:161
‪TYPO3\CMS\Backend\Controller\Wizard\SuggestWizardController
Definition: SuggestWizardController.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Wizard\SuggestWizardControllerTest
Definition: SuggestWizardControllerTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Wizard\SuggestWizardControllerTest\getFlexFieldConfigurationThrowsExceptionIfSimpleFlexFieldIsNotFound
‪getFlexFieldConfigurationThrowsExceptionIfSimpleFlexFieldIsNotFound()
Definition: SuggestWizardControllerTest.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Controller\Wizard
Definition: SuggestWizardControllerTest.php:18