‪TYPO3CMS  ‪main
TcaUuidTest.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\Test;
21 use Symfony\Component\Uid\Uuid;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪TcaUuidTest extends UnitTestCase
26 {
27  public function ‪resultArrayDataProvider(): \Generator
28  {
29  yield 'Only handles TCA type "uuid" records' => [
30  [
31  'command' => 'new',
32  'tableName' => 'aTable',
33  'databaseRow' => [
34  'aField' => '',
35  ],
36  'processedTca' => [
37  'columns' => [
38  'aField' => [
39  'config' => [
40  'type' => 'input',
41  ],
42  ],
43  ],
44  ],
45  ],
46  '',
47  ];
48  yield 'Does not handle records with valid uuid value' => [
49  [
50  'command' => 'edit',
51  'tableName' => 'aTable',
52  'databaseRow' => [
53  'aField' => 'b3190536-1431-453e-afbb-25b8c5022513',
54  ],
55  'processedTca' => [
56  'columns' => [
57  'aField' => [
58  'config' => [
59  'type' => 'uuid',
60  ],
61  ],
62  ],
63  ],
64  ],
65  'b3190536-1431-453e-afbb-25b8c5022513',
66  ];
67  yield 'Does handle records with invalid uuid value' => [
68  [
69  'command' => 'edit',
70  'tableName' => 'aTable',
71  'databaseRow' => [
72  'aField' => '_-invalid-_',
73  ],
74  'processedTca' => [
75  'columns' => [
76  'aField' => [
77  'config' => [
78  'type' => 'uuid',
79  ],
80  ],
81  ],
82  ],
83  ],
84  'b3190536-1431-453e-afbb-25b8c5022513',
85  ];
86  }
87 
88  #[Test]
89  public function ‪addDataDoesOnlyHandleTypeUuid(): void
90  {
91  $input = [
92  'command' => 'new',
93  'tableName' => 'aTable',
94  'databaseRow' => [
95  'aField' => '',
96  ],
97  'processedTca' => [
98  'columns' => [
99  'aField' => [
100  'config' => [
101  'type' => 'input',
102  ],
103  ],
104  ],
105  ],
106  ];
107 
108  self::assertSame('', (new ‪TcaUuid())->addData($input)['databaseRow']['aField']);
109  }
110 
111  #[Test]
113  {
114  $input = [
115  'command' => 'new',
116  'tableName' => 'aTable',
117  'databaseRow' => [
118  'aField' => 'b3190536-1431-453e-afbb-25b8c5022513',
119  ],
120  'processedTca' => [
121  'columns' => [
122  'aField' => [
123  'config' => [
124  'type' => 'uuid',
125  ],
126  ],
127  ],
128  ],
129  ];
130 
131  self::assertSame('b3190536-1431-453e-afbb-25b8c5022513', (new ‪TcaUuid())->addData($input)['databaseRow']['aField']);
132  }
133 
134  #[Test]
136  {
137  $input = [
138  'command' => 'new',
139  'tableName' => 'aTable',
140  'databaseRow' => [
141  'aField' => '_-invalid-_',
142  ],
143  'processedTca' => [
144  'columns' => [
145  'aField' => [
146  'config' => [
147  'type' => 'uuid',
148  ],
149  ],
150  ],
151  ],
152  ];
153 
154  self::assertFalse(Uuid::isValid($input['databaseRow']['aField']));
155  self::assertTrue(Uuid::isValid((new ‪TcaUuid())->addData($input)['databaseRow']['aField']));
156  }
157 
158  #[Test]
160  {
161  $input = [
162  'command' => 'new',
163  'tableName' => 'aTable',
164  'databaseRow' => [
165  'aField' => '',
166  ],
167  'processedTca' => [
168  'columns' => [
169  'aField' => [
170  'config' => [
171  'type' => 'uuid',
172  ],
173  ],
174  ],
175  ],
176  ];
177 
178  self::assertFalse(Uuid::isValid($input['databaseRow']['aField']));
179  self::assertTrue(Uuid::isValid((new ‪TcaUuid())->addData($input)['databaseRow']['aField']));
180  }
181 
182  #[Test]
184  {
185  $input = [
186  'command' => 'new',
187  'tableName' => 'aTable',
188  'databaseRow' => [
189  'aField' => '',
190  ],
191  'processedTca' => [
192  'columns' => [
193  'aField' => [
194  'config' => [
195  'type' => 'uuid',
196  ],
197  ],
198  ],
199  ],
200  ];
201 
202  $input['processedTca']['columns']['aField']['config']['version'] = 6;
203  self::assertEquals(6, (int)(new ‪TcaUuid())->addData($input)['databaseRow']['aField'][14]);
204 
205  $input['processedTca']['columns']['aField']['config']['version'] = 7;
206  self::assertEquals(7, (int)(new ‪TcaUuid())->addData($input)['databaseRow']['aField'][14]);
207 
208  $input['processedTca']['columns']['aField']['config']['version'] = 4;
209  self::assertEquals(4, (int)(new ‪TcaUuid())->addData($input)['databaseRow']['aField'][14]);
210 
211  $input['processedTca']['columns']['aField']['config']['version'] = 12345678; // Defaults to 4
212  self::assertEquals(4, (int)(new ‪TcaUuid())->addData($input)['databaseRow']['aField'][14]);
213 
214  unset($input['processedTca']['columns']['aField']['config']['version']); // Defaults to 4
215  self::assertEquals(4, (int)(new ‪TcaUuid())->addData($input)['databaseRow']['aField'][14]);
216  }
217 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaUuidTest\addDataDoesNotHandleFieldsWithValidUuidValue
‪addDataDoesNotHandleFieldsWithValidUuidValue()
Definition: TcaUuidTest.php:112
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaUuidTest\resultArrayDataProvider
‪resultArrayDataProvider()
Definition: TcaUuidTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaUuidTest\addDataCreatesValidUuidValueWithDefinedVersion
‪addDataCreatesValidUuidValueWithDefinedVersion()
Definition: TcaUuidTest.php:183
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaUuidTest\addDataCreatesValidUuidValueForInvalidUuid
‪addDataCreatesValidUuidValueForInvalidUuid()
Definition: TcaUuidTest.php:135
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaUuidTest\addDataDoesOnlyHandleTypeUuid
‪addDataDoesOnlyHandleTypeUuid()
Definition: TcaUuidTest.php:89
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaUuidTest
Definition: TcaUuidTest.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaUuidTest\addDataCreatesValidUuidValueForEmptyField
‪addDataCreatesValidUuidValueForEmptyField()
Definition: TcaUuidTest.php:159
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaUuid
Definition: TcaUuid.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18