‪TYPO3CMS  10.4
TableBuilderTest.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 Doctrine\DBAL\Schema\ForeignKeyConstraint;
21 use Doctrine\DBAL\Schema\Index;
22 use Doctrine\DBAL\Schema\Table;
23 use Doctrine\DBAL\Types\IntegerType;
24 use Doctrine\DBAL\Types\SmallIntType;
25 use Doctrine\DBAL\Types\TextType;
26 use Psr\EventDispatcher\EventDispatcherInterface;
29 use TYPO3\CMS\Core\Package\PackageManager;
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
35 class ‪TableBuilderTest extends UnitTestCase
36 {
40  protected ‪$resetSingletonInstances = true;
41 
45  protected ‪$table;
46 
50  protected function ‪setUp(): void
51  {
52  parent::setUp();
53  $sqlFile = file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'Fixtures', 'tablebuilder.sql']));
54  $eventDispatcherProphecy = $this->prophesize(EventDispatcherInterface::class);
55  $packageManagerProphecy = $this->prophesize(PackageManager::class);
56  $sqlReader = new ‪SqlReader($eventDispatcherProphecy->reveal(), $packageManagerProphecy->reveal());
57  $statements = $sqlReader->getCreateTableStatementArray($sqlFile);
58 
59  ‪$parser = new ‪Parser($statements[0]);
60  $this->table = ‪$parser->parse()[0];
61  }
62 
66  public function ‪hasExpectedTableName()
67  {
68  self::assertSame('aTestTable', $this->table->getName());
69  }
70 
74  public function ‪hasExpectedTableEngine()
75  {
76  self::assertTrue($this->table->hasOption('engine'));
77  self::assertSame('MyISAM', $this->table->getOption('engine'));
78  }
79 
83  public function ‪hasExpectedTableCollation()
84  {
85  self::assertTrue($this->table->hasOption('charset'));
86  self::assertSame('latin1', $this->table->getOption('charset'));
87  }
88 
92  public function ‪hasExpectedTableCharacterSet()
93  {
94  self::assertTrue($this->table->hasOption('collate'));
95  self::assertSame('latin1_german_cs', $this->table->getOption('collate'));
96  }
97 
101  public function ‪hasExpectedTableRowFormat()
102  {
103  self::assertTrue($this->table->hasOption('row_format'));
104  self::assertSame('DYNAMIC', $this->table->getOption('row_format'));
105  }
106 
110  public function ‪hasExpectedTableAutoIncrementValue()
111  {
112  self::assertTrue($this->table->hasOption('auto_increment'));
113  self::assertSame('1', $this->table->getOption('auto_increment'));
114  }
115 
119  public function ‪isExpectedUidColumn()
120  {
121  $subject = $this->table->getColumn('uid');
122  self::assertInstanceOf(IntegerType::class, $subject->getType());
123  self::assertSame(11, $subject->getLength());
124  self::assertFalse($subject->getUnsigned());
125  self::assertTrue($subject->getNotnull());
126  self::assertNull($subject->getDefault());
127  self::assertTrue($subject->getAutoincrement());
128  }
129 
133  public function ‪isExpectedPidColumn()
134  {
135  $subject = $this->table->getColumn('pid');
136  self::assertInstanceOf(IntegerType::class, $subject->getType());
137  self::assertSame(11, $subject->getLength());
138  self::assertFalse($subject->getUnsigned());
139  self::assertTrue($subject->getNotnull());
140  self::assertFalse($subject->getAutoincrement());
141  self::assertSame('0', $subject->getDefault());
142  }
143 
147  public function ‪isExpectedTstampColumn()
148  {
149  $subject = $this->table->getColumn('tstamp');
150  self::assertInstanceOf(IntegerType::class, $subject->getType());
151  self::assertSame(11, $subject->getLength());
152  self::assertTrue($subject->getUnsigned());
153  self::assertTrue($subject->getNotnull());
154  self::assertFalse($subject->getAutoincrement());
155  self::assertSame('0', $subject->getDefault());
156  }
157 
161  public function ‪isExpectedSortingColumn()
162  {
163  $subject = $this->table->getColumn('sorting');
164  self::assertInstanceOf(IntegerType::class, $subject->getType());
165  self::assertSame(11, $subject->getLength());
166  self::assertTrue($subject->getUnsigned());
167  self::assertTrue($subject->getNotnull());
168  self::assertFalse($subject->getAutoincrement());
169  self::assertSame(0, $subject->getDefault());
170  }
171 
175  public function ‪isExpectedDeletedColumn()
176  {
177  $subject = $this->table->getColumn('deleted');
178  self::assertInstanceOf(SmallIntType::class, $subject->getType());
179  self::assertSame(1, $subject->getLength());
180  self::assertTrue($subject->getUnsigned());
181  self::assertTrue($subject->getNotnull());
182  self::assertFalse($subject->getAutoincrement());
183  self::assertSame('0', $subject->getDefault());
184  }
185 
189  public function ‪isExpectedTSconfigColumn()
190  {
191  $subject = $this->table->getColumn('TSconfig');
192  self::assertInstanceOf(TextType::class, $subject->getType());
193  self::assertSame(65535, $subject->getLength());
194  self::assertFalse($subject->getNotnull());
195  self::assertNull($subject->getDefault());
196  }
197 
201  public function ‪isExpectedNoCacheColumn()
202  {
203  $subject = $this->table->getColumn('no_cache');
204  self::assertInstanceOf(IntegerType::class, $subject->getType());
205  self::assertSame(10, $subject->getLength());
206  self::assertTrue($subject->getUnsigned());
207  self::assertTrue($subject->getNotnull());
208  self::assertFalse($subject->getAutoincrement());
209  self::assertSame('0', $subject->getDefault());
210  }
211 
215  public function ‪isExpectedPrimaryKey()
216  {
217  $subject = $this->table->getPrimaryKey();
218  self::assertInstanceOf(Index::class, $subject);
219  self::assertTrue($subject->isPrimary());
220  self::assertSame(['`uid`'], $subject->getColumns());
221  }
222 
226  public function ‪isExpectedParentKey()
227  {
228  $subject = $this->table->getIndex('parent');
229  self::assertInstanceOf(Index::class, $subject);
230  self::assertTrue($subject->isUnique());
231  self::assertSame(['`pid`', '`deleted`', '`sorting`'], $subject->getColumns());
232  }
233 
237  public function ‪isExpectedNoCacheKey()
238  {
239  $subject = $this->table->getIndex('noCache');
240  self::assertInstanceOf(Index::class, $subject);
241  self::assertTrue($subject->isSimpleIndex());
242  self::assertSame(['`no_cache`'], $subject->getColumns());
243  }
244 
248  public function ‪isExpectedForeignKey()
249  {
250  $subject = $this->table->getForeignKey('fk_overlay');
251  self::assertInstanceOf(ForeignKeyConstraint::class, $subject);
252  self::assertSame(['`pid`'], $subject->getForeignColumns());
253  self::assertSame(['`uid`'], $subject->getLocalColumns());
254  self::assertSame('aTestTable', $subject->getLocalTableName());
255  self::assertSame('any_foreign_table', $subject->getForeignTableName());
256  }
257 
261  public function ‪hasColumnLengthOnIndex()
262  {
263  $subject = $this->table->getIndex('substring');
264  self::assertSame(['`TSconfig`(80)'], $subject->getColumns());
265  }
266 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedPrimaryKey
‪isExpectedPrimaryKey()
Definition: TableBuilderTest.php:213
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedNoCacheKey
‪isExpectedNoCacheKey()
Definition: TableBuilderTest.php:235
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedTstampColumn
‪isExpectedTstampColumn()
Definition: TableBuilderTest.php:145
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableName
‪hasExpectedTableName()
Definition: TableBuilderTest.php:64
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableEngine
‪hasExpectedTableEngine()
Definition: TableBuilderTest.php:72
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\setUp
‪setUp()
Definition: TableBuilderTest.php:48
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasColumnLengthOnIndex
‪hasColumnLengthOnIndex()
Definition: TableBuilderTest.php:259
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedDeletedColumn
‪isExpectedDeletedColumn()
Definition: TableBuilderTest.php:173
‪$parser
‪$parser
Definition: annotationChecker.php:108
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedPidColumn
‪isExpectedPidColumn()
Definition: TableBuilderTest.php:131
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableCharacterSet
‪hasExpectedTableCharacterSet()
Definition: TableBuilderTest.php:90
‪TYPO3\CMS\Core\Database\Schema\SqlReader
Definition: SqlReader.php:31
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedParentKey
‪isExpectedParentKey()
Definition: TableBuilderTest.php:224
‪TYPO3\CMS\Core\Database\Schema\Parser\Parser
Definition: Parser.php:71
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: TableBuilderTest.php:39
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\$table
‪Table $table
Definition: TableBuilderTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedForeignKey
‪isExpectedForeignKey()
Definition: TableBuilderTest.php:246
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableRowFormat
‪hasExpectedTableRowFormat()
Definition: TableBuilderTest.php:99
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedTSconfigColumn
‪isExpectedTSconfigColumn()
Definition: TableBuilderTest.php:187
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedSortingColumn
‪isExpectedSortingColumn()
Definition: TableBuilderTest.php:159
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedNoCacheColumn
‪isExpectedNoCacheColumn()
Definition: TableBuilderTest.php:199
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableCollation
‪hasExpectedTableCollation()
Definition: TableBuilderTest.php:81
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser
Definition: AbstractDataTypeBaseTestCase.php:18
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedUidColumn
‪isExpectedUidColumn()
Definition: TableBuilderTest.php:117
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableAutoIncrementValue
‪hasExpectedTableAutoIncrementValue()
Definition: TableBuilderTest.php:108
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest
Definition: TableBuilderTest.php:36