[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Tca / PagesVisibleFieldsTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Tca;
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 TYPO3\CMS\Backend\Tests\Functional\Form\FormTestService;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Frontend\Page\PageRepository;
20 use TYPO3\CMS\Lang\LanguageService;
21
22 class PagesVisibleFieldsTest extends \TYPO3\CMS\Components\TestingFramework\Core\FunctionalTestCase
23 {
24 /**
25 * These form fields a visisble in the default page types.
26 *
27 * @var array
28 */
29 protected static $defaultPageFormFields = [
30 'title',
31 'nav_title',
32 'subtitle',
33 'hidden',
34 'nav_hide',
35 'starttime',
36 'endtime',
37 'extendToSubpages',
38 'fe_group',
39 'fe_login_mode',
40 'abstract',
41 'keywords',
42 'description',
43 'author',
44 'author_email',
45 'layout',
46 'newUntil',
47 'backend_layout',
48 'backend_layout_next_level',
49 'content_from_pid',
50 'alias',
51 'target',
52 'url_scheme',
53 'cache_timeout',
54 'cache_tags',
55 'no_cache',
56 'l18n_cfg',
57 'is_siteroot',
58 'no_search',
59 'editlock',
60 'php_tree_stop',
61 'module',
62 'media',
63 'tsconfig_includes',
64 'TSconfig',
65 'categories',
66 ];
67
68 /**
69 * Configuration of hidden / additional form fields per page type.
70 *
71 * @var array
72 */
73 protected static $pageFormFields = [
74 PageRepository::DOKTYPE_BE_USER_SECTION => [],
75 PageRepository::DOKTYPE_DEFAULT => [],
76 PageRepository::DOKTYPE_SHORTCUT => [
77 'additionalFields' => [
78 'shortcut_mode',
79 'shortcut',
80 ],
81 'hiddenFields' => [
82 'keywords',
83 'description',
84 'content_from_pid',
85 'cache_timeout',
86 'cache_tags',
87 'no_cache',
88 'module',
89 ],
90 ],
91 PageRepository::DOKTYPE_MOUNTPOINT => [
92 'additionalFields' => [
93 'mount_pid_ol',
94 'mount_pid',
95 ],
96 'hiddenFields' => [
97 'keywords',
98 'description',
99 'content_from_pid',
100 'cache_timeout',
101 'cache_tags',
102 'no_cache',
103 'module',
104 ],
105 ],
106 PageRepository::DOKTYPE_LINK => [
107 'additionalFields' => [
108 'urltype',
109 'url',
110 ],
111 'hiddenFields' => [
112 'keywords',
113 'description',
114 'content_from_pid',
115 'cache_timeout',
116 'cache_tags',
117 'no_cache',
118 'module',
119 ],
120 ],
121 PageRepository::DOKTYPE_SYSFOLDER => [
122 'hiddenFields' => [
123 'nav_title',
124 'subtitle',
125 'nav_hide',
126 'starttime',
127 'endtime',
128 'extendToSubpages',
129 'fe_group',
130 'fe_login_mode',
131 'abstract',
132 'keywords',
133 'description',
134 'author',
135 'author_email',
136 'layout',
137 'newUntil',
138 'content_from_pid',
139 'cache_timeout',
140 'cache_tags',
141 'no_cache',
142 'content_from_pid',
143 'alias',
144 'target',
145 'url_scheme',
146 'cache_timeout',
147 'cache_tags',
148 'no_cache',
149 'l18n_cfg',
150 'is_siteroot',
151 'no_search',
152 'php_tree_stop',
153 ],
154 ],
155 PageRepository::DOKTYPE_RECYCLER => [
156 'hiddenFields' => [
157 'nav_title',
158 'subtitle',
159 'nav_hide',
160 'starttime',
161 'endtime',
162 'extendToSubpages',
163 'fe_group',
164 'fe_login_mode',
165 'abstract',
166 'keywords',
167 'description',
168 'author',
169 'author_email',
170 'layout',
171 'newUntil',
172 'backend_layout',
173 'backend_layout_next_level',
174 'content_from_pid',
175 'cache_timeout',
176 'cache_tags',
177 'no_cache',
178 'content_from_pid',
179 'alias',
180 'target',
181 'url_scheme',
182 'cache_timeout',
183 'cache_tags',
184 'no_cache',
185 'l18n_cfg',
186 'is_siteroot',
187 'no_search',
188 'php_tree_stop',
189 'module',
190 'media',
191 'tsconfig_includes',
192 'TSconfig',
193 ],
194 ],
195 PageRepository::DOKTYPE_SPACER => [
196 'hiddenFields' => [
197 'nav_title',
198 'subtitle',
199 'abstract',
200 'keywords',
201 'description',
202 'author',
203 'author_email',
204 'layout',
205 'newUntil',
206 'backend_layout',
207 'backend_layout_next_level',
208 'module',
209 'content_from_pid',
210 'cache_timeout',
211 'cache_tags',
212 'no_cache',
213 'content_from_pid',
214 'alias',
215 'target',
216 'url_scheme',
217 'cache_timeout',
218 'cache_tags',
219 'no_cache',
220 'l18n_cfg',
221 'is_siteroot',
222 'no_search',
223 'php_tree_stop',
224 'media',
225 'tsconfig_includes',
226 'TSconfig',
227 ],
228 ],
229 ];
230
231 /**
232 * @return array
233 */
234 public function pagesFormContainsExpectedFieldsDataProvider(): array
235 {
236 $pageTypes = [];
237
238 foreach (static::$pageFormFields as $doktype => $fieldConfig) {
239 $expectedFields = static::$defaultPageFormFields;
240 $hiddenFields = [];
241 if (array_key_exists('additionalFields', $fieldConfig)) {
242 $expectedFields = array_merge($expectedFields, $fieldConfig['additionalFields']);
243 }
244 if (array_key_exists('hiddenFields', $fieldConfig)) {
245 $hiddenFields = $fieldConfig['hiddenFields'];
246 $expectedFields = array_diff($expectedFields, $hiddenFields);
247 }
248 $pageTypes['page doktype ' . $doktype] = [$doktype, $expectedFields, $hiddenFields];
249 }
250
251 return $pageTypes;
252 }
253
254 /**
255 * @test
256 * @dataProvider pagesFormContainsExpectedFieldsDataProvider
257 * @param int $doktype
258 * @param array $expectedFields
259 * @param array $hiddenFields
260 */
261 public function pagesFormContainsExpectedFields(int $doktype, array $expectedFields, array $hiddenFields)
262 {
263 $this->setUpBackendUserFromFixture(1);
264 $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class);
265
266 $formEngineTestService = GeneralUtility::makeInstance(FormTestService::class);
267 $formResult = $formEngineTestService->createNewRecordForm('pages', ['doktype' => $doktype]);
268
269 foreach ($expectedFields as $expectedField) {
270 $this->assertNotFalse(
271 $formEngineTestService->formHtmlContainsField($expectedField, $formResult['html']),
272 'The field ' . $expectedField . ' is not in the HTML'
273 );
274 }
275
276 foreach ($hiddenFields as $hiddenField) {
277 $this->assertFalse(
278 $formEngineTestService->formHtmlContainsField($hiddenField, $formResult['html']),
279 'The field ' . $hiddenField . ' is in the HTML'
280 );
281 }
282 }
283 }