‪TYPO3CMS  9.5
ColumnDefinitionAttributesTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪ColumnDefinitionAttributesTest extends UnitTestCase
28 {
46  {
47  return [
48  'NULL' => [
49  'NULL',
50  true,
51  false,
52  null,
53  false,
54  false,
55  false,
56  false,
57  null,
58  null,
59  null,
60  ],
61  'NOT NULL' => [
62  'NOT NULL',
63  false,
64  false,
65  null,
66  false,
67  false,
68  false,
69  false,
70  null,
71  null,
72  null,
73  ],
74  'DEFAULT' => [
75  "DEFAULT '0'",
76  true,
77  true,
78  '0',
79  false,
80  false,
81  false,
82  false,
83  null,
84  null,
85  null,
86  ],
87  'AUTO_INCREMENT' => [
88  'AUTO_INCREMENT',
89  true,
90  false,
91  null,
92  true,
93  false,
94  false,
95  false,
96  null,
97  null,
98  null,
99  ],
100  'UNIQUE' => [
101  'UNIQUE',
102  true,
103  false,
104  null,
105  false,
106  false,
107  true,
108  false,
109  null,
110  null,
111  null,
112  ],
113  'UNIQUE KEY' => [
114  'UNIQUE KEY',
115  true,
116  false,
117  null,
118  false,
119  false,
120  true,
121  false,
122  null,
123  null,
124  null,
125  ],
126  'PRIMARY' => [
127  'PRIMARY',
128  true,
129  false,
130  null,
131  false,
132  false,
133  false,
134  true,
135  null,
136  null,
137  null,
138  ],
139  'PRIMARY KEY' => [
140  'PRIMARY KEY',
141  true,
142  false,
143  null,
144  false,
145  false,
146  false,
147  true,
148  null,
149  null,
150  null,
151  ],
152  'KEY' => [
153  'KEY',
154  true,
155  false,
156  null,
157  false,
158  true,
159  false,
160  false,
161  null,
162  null,
163  null,
164  ],
165  'COMMENT' => [
166  "COMMENT 'aComment'",
167  true,
168  false,
169  null,
170  false,
171  false,
172  false,
173  false,
174  'aComment',
175  null,
176  null,
177  ],
178  'COLUMN_FORMAT FIXED' => [
179  'COLUMN_FORMAT FIXED',
180  true,
181  false,
182  null,
183  false,
184  false,
185  false,
186  false,
187  null,
188  'fixed',
189  null,
190  ],
191  'COLUMN_FORMAT DYNAMIC' => [
192  'COLUMN_FORMAT DYNAMIC',
193  true,
194  false,
195  null,
196  false,
197  false,
198  false,
199  false,
200  null,
201  'dynamic',
202  null,
203  ],
204  'COLUMN_FORMAT DEFAULT' => [
205  'COLUMN_FORMAT DEFAULT',
206  true,
207  false,
208  null,
209  false,
210  false,
211  false,
212  false,
213  null,
214  null,
215  null,
216  ],
217  'STORAGE DISK' => [
218  'STORAGE DISK',
219  true,
220  false,
221  null,
222  false,
223  false,
224  false,
225  false,
226  null,
227  null,
228  'disk',
229  ],
230  'STORAGE MEMORY' => [
231  'STORAGE MEMORY',
232  true,
233  false,
234  null,
235  false,
236  false,
237  false,
238  false,
239  null,
240  null,
241  'memory',
242  ],
243  'STORAGE DEFAULT' => [
244  'STORAGE DEFAULT',
245  true,
246  false,
247  null,
248  false,
249  false,
250  false,
251  false,
252  null,
253  null,
254  null,
255  ],
256  "NOT NULL DEFAULT '0'" => [
257  "NOT NULL DEFAULT '0'",
258  false,
259  true,
260  '0',
261  false,
262  false,
263  false,
264  false,
265  null,
266  null,
267  null,
268  ],
269  'NOT NULL AUTO_INCREMENT' => [
270  'NOT NULL AUTO_INCREMENT',
271  false,
272  false,
273  null,
274  true,
275  false,
276  false,
277  false,
278  null,
279  null,
280  null,
281  ],
282  'NULL DEFAULT NULL' => [
283  'NULL DEFAULT NULL',
284  true,
285  true,
286  null,
287  false,
288  false,
289  false,
290  false,
291  null,
292  null,
293  null,
294  ],
295  'NOT NULL PRIMARY KEY' => [
296  'NOT NULL PRIMARY KEY',
297  false,
298  false,
299  null,
300  false,
301  false,
302  false,
303  true,
304  null,
305  null,
306  null,
307  ],
308  "NULL DEFAULT 'dummy' UNIQUE" => [
309  "NULL DEFAULT 'dummy' UNIQUE",
310  true,
311  true,
312  'dummy',
313  false,
314  false,
315  true,
316  false,
317  null,
318  null,
319  null,
320  ],
321  "NOT NULL DEFAULT '0' COMMENT 'aComment with blanks' AUTO_INCREMENT PRIMARY KEY COLUMN_FORMAT DYNAMIC" => [
322  "NOT NULL DEFAULT '0' COMMENT 'aComment with blanks' AUTO_INCREMENT PRIMARY KEY COLUMN_FORMAT DYNAMIC",
323  false,
324  true,
325  '0',
326  true,
327  false,
328  false,
329  true,
330  'aComment with blanks',
331  'dynamic',
332  null,
333  ],
334  ];
335  }
336 
353  string $columnAttribute,
354  bool $allowNull,
355  bool $hasDefaultValue,
356  $defaultValue,
357  bool $autoIncrement,
358  bool $createIndex,
359  bool $createUniqueIndex,
360  bool $isPrimaryKey,
361  string $comment = null,
362  string $columnFormat = null,
363  string $storage = null
364  ) {
365  $statement = sprintf('CREATE TABLE `aTable`(`aField` INT(11) %s);', $columnAttribute);
366  $subject = $this->‪createSubject($statement);
367 
368  $this->assertInstanceOf(CreateColumnDefinitionItem::class, $subject);
369  $this->assertSame($allowNull, $subject->allowNull);
370  $this->assertSame($hasDefaultValue, $subject->hasDefaultValue);
371  $this->assertSame($defaultValue, $subject->defaultValue);
372  $this->assertSame($createIndex, $subject->index);
373  $this->assertSame($createUniqueIndex, $subject->unique);
374  $this->assertSame($isPrimaryKey, $subject->primary);
375  $this->assertSame($autoIncrement, $subject->autoIncrement);
376  $this->assertSame($comment, $subject->comment);
377  $this->assertSame($columnFormat, $subject->columnFormat);
378  $this->assertSame($storage, $subject->storage);
379  }
380 
387  protected function ‪createSubject(string $statement): ‪CreateColumnDefinitionItem
388  {
389  ‪$parser = new ‪Parser($statement);
391  $createTableStatement = ‪$parser->getAST();
392 
393  return $createTableStatement->createDefinition->items[0];
394  }
395 }
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateTableStatement
Definition: CreateTableStatement.php:23
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateColumnDefinitionItem
Definition: CreateColumnDefinitionItem.php:26
‪$parser
‪$parser
Definition: annotationChecker.php:100
‪TYPO3\CMS\Core\Database\Schema\Parser\Parser
Definition: Parser.php:28
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\ColumnDefinitionAttributesTest
Definition: ColumnDefinitionAttributesTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\ColumnDefinitionAttributesTest\canParseColumnDefinitionAttributesDataProvider
‪array canParseColumnDefinitionAttributesDataProvider()
Definition: ColumnDefinitionAttributesTest.php:45
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser
Definition: AbstractDataTypeBaseTestCase.php:4
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\ColumnDefinitionAttributesTest\createSubject
‪TYPO3 CMS Core Database Schema Parser AST CreateColumnDefinitionItem createSubject(string $statement)
Definition: ColumnDefinitionAttributesTest.php:387
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\ColumnDefinitionAttributesTest\canParseColumnDefinitionAttributes
‪canParseColumnDefinitionAttributes(string $columnAttribute, bool $allowNull, bool $hasDefaultValue, $defaultValue, bool $autoIncrement, bool $createIndex, bool $createUniqueIndex, bool $isPrimaryKey, string $comment=null, string $columnFormat=null, string $storage=null)
Definition: ColumnDefinitionAttributesTest.php:352