TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
TableBuilderTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 
4 namespace TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser;
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 
19 use Doctrine\DBAL\Schema\ForeignKeyConstraint;
20 use Doctrine\DBAL\Schema\Index;
21 use Doctrine\DBAL\Schema\Table;
22 use Doctrine\DBAL\Types\IntegerType;
23 use Doctrine\DBAL\Types\SmallIntType;
24 use Doctrine\DBAL\Types\TextType;
29 
34 {
38  protected $table;
39 
43  protected function setUp()
44  {
45  parent::setUp();
46  $sqlFile = file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'Fixtures', 'tablebuilder.sql']));
47  $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
48  $statements = $sqlReader->getCreateTableStatementArray($sqlFile);
49 
50  $parser = GeneralUtility::makeInstance(Parser::class, $statements[0]);
51  $this->table = $parser->parse()[0];
52  }
53 
57  public function hasExpectedTableName()
58  {
59  $this->assertSame('aTestTable', $this->table->getName());
60  }
61 
65  public function hasExpectedTableEngine()
66  {
67  $this->assertTrue($this->table->hasOption('engine'));
68  $this->assertSame('MyISAM', $this->table->getOption('engine'));
69  }
70 
74  public function hasExpectedTableCollation()
75  {
76  $this->assertTrue($this->table->hasOption('charset'));
77  $this->assertSame('latin1', $this->table->getOption('charset'));
78  }
79 
83  public function hasExpectedTableCharacterSet()
84  {
85  $this->assertTrue($this->table->hasOption('collate'));
86  $this->assertSame('latin1_german_cs', $this->table->getOption('collate'));
87  }
88 
92  public function hasExpectedTableRowFormat()
93  {
94  $this->assertTrue($this->table->hasOption('row_format'));
95  $this->assertSame('DYNAMIC', $this->table->getOption('row_format'));
96  }
97 
102  {
103  $this->assertTrue($this->table->hasOption('auto_increment'));
104  $this->assertSame('1', $this->table->getOption('auto_increment'));
105  }
106 
110  public function isExpectedUidColumn()
111  {
112  $subject = $this->table->getColumn('uid');
113  $this->assertInstanceOf(IntegerType::class, $subject->getType());
114  $this->assertSame(11, $subject->getLength());
115  $this->assertFalse($subject->getUnsigned());
116  $this->assertTrue($subject->getNotnull());
117  $this->assertNull($subject->getDefault());
118  $this->assertTrue($subject->getAutoincrement());
119  }
120 
124  public function isExpectedPidColumn()
125  {
126  $subject = $this->table->getColumn('pid');
127  $this->assertInstanceOf(IntegerType::class, $subject->getType());
128  $this->assertSame(11, $subject->getLength());
129  $this->assertFalse($subject->getUnsigned());
130  $this->assertTrue($subject->getNotnull());
131  $this->assertFalse($subject->getAutoincrement());
132  $this->assertSame('0', $subject->getDefault());
133  }
134 
138  public function isExpectedTstampColumn()
139  {
140  $subject = $this->table->getColumn('tstamp');
141  $this->assertInstanceOf(IntegerType::class, $subject->getType());
142  $this->assertSame(11, $subject->getLength());
143  $this->assertTrue($subject->getUnsigned());
144  $this->assertTrue($subject->getNotnull());
145  $this->assertFalse($subject->getAutoincrement());
146  $this->assertSame('0', $subject->getDefault());
147  }
148 
152  public function isExpectedSortingColumn()
153  {
154  $subject = $this->table->getColumn('sorting');
155  $this->assertInstanceOf(IntegerType::class, $subject->getType());
156  $this->assertSame(11, $subject->getLength());
157  $this->assertTrue($subject->getUnsigned());
158  $this->assertTrue($subject->getNotnull());
159  $this->assertFalse($subject->getAutoincrement());
160  $this->assertSame(0, $subject->getDefault());
161  }
162 
166  public function isExpectedDeletedColumn()
167  {
168  $subject = $this->table->getColumn('deleted');
169  $this->assertInstanceOf(SmallIntType::class, $subject->getType());
170  $this->assertSame(1, $subject->getLength());
171  $this->assertTrue($subject->getUnsigned());
172  $this->assertTrue($subject->getNotnull());
173  $this->assertFalse($subject->getAutoincrement());
174  $this->assertSame('0', $subject->getDefault());
175  }
176 
180  public function isExpectedTSconfigColumn()
181  {
182  $subject = $this->table->getColumn('TSconfig');
183  $this->assertInstanceOf(TextType::class, $subject->getType());
184  $this->assertSame(65535, $subject->getLength());
185  $this->assertFalse($subject->getNotnull());
186  $this->assertNull($subject->getDefault());
187  }
188 
192  public function isExpectedNoCacheColumn()
193  {
194  $subject = $this->table->getColumn('no_cache');
195  $this->assertInstanceOf(IntegerType::class, $subject->getType());
196  $this->assertSame(10, $subject->getLength());
197  $this->assertTrue($subject->getUnsigned());
198  $this->assertTrue($subject->getNotnull());
199  $this->assertFalse($subject->getAutoincrement());
200  $this->assertSame('0', $subject->getDefault());
201  }
202 
206  public function isExpectedPrimaryKey()
207  {
208  $subject = $this->table->getPrimaryKey();
209  $this->assertInstanceOf(Index::class, $subject);
210  $this->assertTrue($subject->isPrimary());
211  $this->assertSame(['`uid`'], $subject->getColumns());
212  }
213 
217  public function isExpectedParentKey()
218  {
219  $subject = $this->table->getIndex('parent');
220  $this->assertInstanceOf(Index::class, $subject);
221  $this->assertTrue($subject->isUnique());
222  $this->assertSame(['`pid`', '`deleted`', '`sorting`'], $subject->getColumns());
223  }
224 
228  public function isExpectedNoCacheKey()
229  {
230  $subject = $this->table->getIndex('noCache');
231  $this->assertInstanceOf(Index::class, $subject);
232  $this->assertTrue($subject->isSimpleIndex());
233  $this->assertSame(['`no_cache`'], $subject->getColumns());
234  }
235 
239  public function isExpectedForeignKey()
240  {
241  $subject = $this->table->getForeignKey('fk_overlay');
242  $this->assertInstanceOf(ForeignKeyConstraint::class, $subject);
243  $this->assertSame(['`pid`'], $subject->getForeignColumns());
244  $this->assertSame(['`uid`'], $subject->getLocalColumns());
245  $this->assertSame('aTestTable', $subject->getLocalTableName());
246  $this->assertSame('pages_language_overlay', $subject->getForeignTableName());
247  }
248 
252  public function hasColumnLengthOnIndex()
253  {
254  $subject = $this->table->getIndex('substring');
255  $this->assertSame(['`TSconfig`(80)'], $subject->getColumns());
256  }
257 }
static makeInstance($className,...$constructorArguments)