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