‪TYPO3CMS  11.5
DatabaseRowDefaultAsReadonlyTest.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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪DatabaseRowDefaultAsReadonlyTest extends UnitTestCase
27 {
32  {
33  $input = [
34  'databaseRow' => [
35  'uid' => 10,
36  'l10n_parent' => 5,
37  'sys_language_uid' => 2,
38  'aField' => '',
39  ],
40  'defaultLanguageRow' => [
41  'uid' => 5,
42  'l10n_parent' => 0,
43  'sys_language_uid' => 0,
44  'aField' => 'some-default-value',
45  ],
46  'processedTca' => [
47  'ctrl' => [
48  'transOrigPointerField' => 'l10n_parent',
49  'languageField' => 'sys_language_uid',
50  ],
51  'columns' => [
52  'aField' => [
53  'label' => 'aField',
54  'l10n_display' => 'defaultAsReadonly',
55  ],
56  ],
57  ],
58  ];
59 
60  $expected = $input;
61  $expected['databaseRow']['aField'] = $expected['defaultLanguageRow']['aField'];
62 
63  self::assertEquals($expected, (new ‪DatabaseRowDefaultAsReadonly())->addData($input));
64  }
65 
70  public function ‪addDataDoesNotReplaceCurrentDatabaseValue(array $input): void
71  {
72  self::assertEquals(
73  $input['databaseRow']['aField'],
74  (new ‪DatabaseRowDefaultAsReadonly())->addData($input)['databaseRow']['aField']
75  );
76  }
77 
79  {
80  yield 'No default language row available' => [
81  [
82  'databaseRow' => [
83  'uid' => 10,
84  'l10n_parent' => 5,
85  'sys_language_uid' => 2,
86  'aField' => 'wont-be-overridden',
87  ],
88  'processedTca' => [
89  'ctrl' => [
90  'transOrigPointerField' => 'l10n_parent',
91  'languageField' => 'sys_language_uid',
92  ],
93  'columns' => [
94  'aField' => [
95  'label' => 'aField',
96  'l10n_display' => 'defaultAsReadonly',
97  ],
98  ],
99  ],
100  ],
101  ];
102  yield 'defaultAsReadonly is not set' => [
103  [
104  'databaseRow' => [
105  'uid' => 10,
106  'l10n_parent' => 5,
107  'sys_language_uid' => 2,
108  'aField' => 'wont-be-overridden',
109  ],
110  'defaultLanguageRow' => [
111  'uid' => 5,
112  'l10n_parent' => 0,
113  'sys_language_uid' => 0,
114  'aField' => 'some-default-value',
115  ],
116  'processedTca' => [
117  'ctrl' => [
118  'transOrigPointerField' => 'l10n_parent',
119  'languageField' => 'sys_language_uid',
120  ],
121  'columns' => [
122  'aField' => [
123  'label' => 'aField',
124  ],
125  ],
126  ],
127  ],
128  ];
129  yield 'current record is no overlay' => [
130  [
131  'databaseRow' => [
132  'uid' => 10,
133  'l10n_parent' => 0,
134  'sys_language_uid' => 2,
135  'aField' => 'wont-be-overridden',
136  ],
137  'defaultLanguageRow' => [
138  // This case usually can not occur, however since it's possible
139  // for 3rd party to hook in we have to check this case as well.
140  'aField' => 'some-default-value',
141  ],
142  'processedTca' => [
143  'ctrl' => [
144  'transOrigPointerField' => 'l10n_parent',
145  'languageField' => 'sys_language_uid',
146  ],
147  'columns' => [
148  'aField' => [
149  'label' => 'aField',
150  'l10n_display' => 'defaultAsReadonly',
151  ],
152  ],
153  ],
154  ],
155  ];
156  yield 'default row is not the localization parent of the current record' => [
157  [
158  'databaseRow' => [
159  'uid' => 10,
160  'l10n_parent' => 7,
161  'sys_language_uid' => 2,
162  'aField' => 'wont-be-overridden',
163  ],
164  'defaultLanguageRow' => [
165  'uid' => 5,
166  'l10n_parent' => 0,
167  'sys_language_uid' => 0,
168  'aField' => 'some-default-value',
169  ],
170  'processedTca' => [
171  'ctrl' => [
172  'transOrigPointerField' => 'l10n_parent',
173  'languageField' => 'sys_language_uid',
174  ],
175  'columns' => [
176  'aField' => [
177  'label' => 'aField',
178  'l10n_display' => 'defaultAsReadonly',
179  ],
180  ],
181  ],
182  ],
183  ];
184  }
185 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultAsReadonly
Definition: DatabaseRowDefaultAsReadonly.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRowDefaultAsReadonlyTest
Definition: DatabaseRowDefaultAsReadonlyTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRowDefaultAsReadonlyTest\addDataDoesNotReplaceCurrentDatabaseValue
‪addDataDoesNotReplaceCurrentDatabaseValue(array $input)
Definition: DatabaseRowDefaultAsReadonlyTest.php:70
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRowDefaultAsReadonlyTest\addDataDoesNotReplaceCurrentDatabaseValueDataProvider
‪addDataDoesNotReplaceCurrentDatabaseValueDataProvider()
Definition: DatabaseRowDefaultAsReadonlyTest.php:78
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRowDefaultAsReadonlyTest\addDataReplacesCurrentDatabaseValue
‪addDataReplacesCurrentDatabaseValue()
Definition: DatabaseRowDefaultAsReadonlyTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18