e5857861d36ec5f341e17d184309503b1fd34f80
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Functional / Tca / PagesLanguageOverlayVisibleFieldsTest.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\Localization\LanguageService;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Frontend\Page\PageRepository;
21
22 class PagesLanguageOverlayVisibleFieldsTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
23 {
24 /**
25 * These form fields a visisble in the default page types.
26 *
27 * @var array
28 */
29 protected static $defaultPagesLanguageOverlayFields = [
30 'title',
31 'nav_title',
32 'subtitle',
33 'hidden',
34 'starttime',
35 'endtime',
36 'abstract',
37 'keywords',
38 'description',
39 'author',
40 'author_email',
41 'media',
42 ];
43
44 /**
45 * Configuration of hidden / additional form fields per page type.
46 *
47 * @var array
48 */
49 protected static $pageFormFields = [
50 PageRepository::DOKTYPE_BE_USER_SECTION => [],
51 PageRepository::DOKTYPE_DEFAULT => [],
52 PageRepository::DOKTYPE_SHORTCUT => [
53 'additionalFields' => [
54 'shortcut_mode',
55 'shortcut',
56 ],
57 'hiddenFields' => [
58 'keywords',
59 'description',
60 'content_from_pid',
61 'cache_timeout',
62 'cache_tags',
63 'no_cache',
64 'module',
65 ],
66 ],
67 PageRepository::DOKTYPE_MOUNTPOINT => [
68 'hiddenFields' => [
69 'keywords',
70 'description',
71 'content_from_pid',
72 'cache_timeout',
73 'cache_tags',
74 'no_cache',
75 'module',
76 ],
77 ],
78 PageRepository::DOKTYPE_LINK => [
79 'additionalFields' => [
80 'url',
81 ],
82 'hiddenFields' => [
83 'keywords',
84 'description',
85 'content_from_pid',
86 'cache_timeout',
87 'cache_tags',
88 'no_cache',
89 'module',
90 ],
91 ],
92 PageRepository::DOKTYPE_SYSFOLDER => [
93 'hiddenFields' => [
94 'nav_title',
95 'subtitle',
96 'starttime',
97 'endtime',
98 'abstract',
99 'keywords',
100 'description',
101 'author',
102 'author_email',
103 ],
104 ],
105 PageRepository::DOKTYPE_RECYCLER => [
106 'hiddenFields' => [
107 'nav_title',
108 'subtitle',
109 'starttime',
110 'endtime',
111 'abstract',
112 'keywords',
113 'description',
114 'author',
115 'author_email',
116 'media',
117 ],
118 ],
119 PageRepository::DOKTYPE_SPACER => [
120 'hiddenFields' => [
121 'nav_title',
122 'subtitle',
123 'abstract',
124 'keywords',
125 'description',
126 'author',
127 'author_email',
128 'media',
129 ],
130 ],
131 ];
132
133 /**
134 * @return array
135 */
136 public function pagesLanguageOverlayFormContainsExpectedFieldsDataProvider(): array
137 {
138 $pageTypes = [];
139
140 foreach (static::$pageFormFields as $doktype => $fieldConfig) {
141 $expectedFields = static::$defaultPagesLanguageOverlayFields;
142 $hiddenFields = [];
143 if (array_key_exists('additionalFields', $fieldConfig)) {
144 $expectedFields = array_merge($expectedFields, $fieldConfig['additionalFields']);
145 }
146 if (array_key_exists('hiddenFields', $fieldConfig)) {
147 $hiddenFields = $fieldConfig['hiddenFields'];
148 $expectedFields = array_diff($expectedFields, $hiddenFields);
149 }
150 $pageTypes['page doktype ' . $doktype] = [$doktype, $expectedFields, $hiddenFields];
151 }
152
153 return $pageTypes;
154 }
155
156 /**
157 * @test
158 * @dataProvider pagesLanguageOverlayFormContainsExpectedFieldsDataProvider
159 * @param int $doktype
160 * @param array $expectedFields
161 * @param array $hiddenFields
162 */
163 public function pagesLanguageOverlayFormContainsExpectedFields(
164 int $doktype,
165 array $expectedFields,
166 array $hiddenFields
167 ) {
168 $this->setUpBackendUserFromFixture(1);
169 $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class);
170
171 $formEngineTestService = GeneralUtility::makeInstance(FormTestService::class);
172 $formResult = $formEngineTestService->createNewRecordForm('pages_language_overlay', ['doktype' => $doktype]);
173
174 foreach ($expectedFields as $expectedField) {
175 $this->assertNotFalse(
176 $formEngineTestService->formHtmlContainsField($expectedField, $formResult['html']),
177 'The field ' . $expectedField . ' is not in the form HTML'
178 );
179 }
180
181 foreach ($hiddenFields as $hiddenField) {
182 $this->assertFalse(
183 $formEngineTestService->formHtmlContainsField($hiddenField, $formResult['html']),
184 'The field ' . $hiddenField . ' is in the form HTML'
185 );
186 }
187 }
188 }