TYPO3 CMS  TYPO3_8-7
TableBuilderTest.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 
28 
32 class TableBuilderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
33 {
37  protected $table;
38 
42  protected function setUp()
43  {
44  parent::setUp();
45  $sqlFile = file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'Fixtures', 'tablebuilder.sql']));
46  $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
47  $statements = $sqlReader->getCreateTableStatementArray($sqlFile);
48 
49  $parser = GeneralUtility::makeInstance(Parser::class, $statements[0]);
50  $this->table = $parser->parse()[0];
51  }
52 
56  public function hasExpectedTableName()
57  {
58  $this->assertSame('aTestTable', $this->table->getName());
59  }
60 
64  public function hasExpectedTableEngine()
65  {
66  $this->assertTrue($this->table->hasOption('engine'));
67  $this->assertSame('MyISAM', $this->table->getOption('engine'));
68  }
69 
73  public function hasExpectedTableCollation()
74  {
75  $this->assertTrue($this->table->hasOption('charset'));
76  $this->assertSame('latin1', $this->table->getOption('charset'));
77  }
78 
82  public function hasExpectedTableCharacterSet()
83  {
84  $this->assertTrue($this->table->hasOption('collate'));
85  $this->assertSame('latin1_german_cs', $this->table->getOption('collate'));
86  }
87 
91  public function hasExpectedTableRowFormat()
92  {
93  $this->assertTrue($this->table->hasOption('row_format'));
94  $this->assertSame('DYNAMIC', $this->table->getOption('row_format'));
95  }
96 
101  {
102  $this->assertTrue($this->table->hasOption('auto_increment'));
103  $this->assertSame('1', $this->table->getOption('auto_increment'));
104  }
105 
109  public function isExpectedUidColumn()
110  {
111  $subject = $this->table->getColumn('uid');
112  $this->assertInstanceOf(IntegerType::class, $subject->getType());
113  $this->assertSame(11, $subject->getLength());
114  $this->assertFalse($subject->getUnsigned());
115  $this->assertTrue($subject->getNotnull());
116  $this->assertNull($subject->getDefault());
117  $this->assertTrue($subject->getAutoincrement());
118  }
119 
123  public function isExpectedPidColumn()
124  {
125  $subject = $this->table->getColumn('pid');
126  $this->assertInstanceOf(IntegerType::class, $subject->getType());
127  $this->assertSame(11, $subject->getLength());
128  $this->assertFalse($subject->getUnsigned());
129  $this->assertTrue($subject->getNotnull());
130  $this->assertFalse($subject->getAutoincrement());
131  $this->assertSame('0', $subject->getDefault());
132  }
133 
137  public function isExpectedTstampColumn()
138  {
139  $subject = $this->table->getColumn('tstamp');
140  $this->assertInstanceOf(IntegerType::class, $subject->getType());
141  $this->assertSame(11, $subject->getLength());
142  $this->assertTrue($subject->getUnsigned());
143  $this->assertTrue($subject->getNotnull());
144  $this->assertFalse($subject->getAutoincrement());
145  $this->assertSame('0', $subject->getDefault());
146  }
147 
151  public function isExpectedSortingColumn()
152  {
153  $subject = $this->table->getColumn('sorting');
154  $this->assertInstanceOf(IntegerType::class, $subject->getType());
155  $this->assertSame(11, $subject->getLength());
156  $this->assertTrue($subject->getUnsigned());
157  $this->assertTrue($subject->getNotnull());
158  $this->assertFalse($subject->getAutoincrement());
159  $this->assertSame(0, $subject->getDefault());
160  }
161 
165  public function isExpectedDeletedColumn()
166  {
167  $subject = $this->table->getColumn('deleted');
168  $this->assertInstanceOf(SmallIntType::class, $subject->getType());
169  $this->assertSame(1, $subject->getLength());
170  $this->assertTrue($subject->getUnsigned());
171  $this->assertTrue($subject->getNotnull());
172  $this->assertFalse($subject->getAutoincrement());
173  $this->assertSame('0', $subject->getDefault());
174  }
175 
179  public function isExpectedTSconfigColumn()
180  {
181  $subject = $this->table->getColumn('TSconfig');
182  $this->assertInstanceOf(TextType::class, $subject->getType());
183  $this->assertSame(65535, $subject->getLength());
184  $this->assertFalse($subject->getNotnull());
185  $this->assertNull($subject->getDefault());
186  }
187 
191  public function isExpectedNoCacheColumn()
192  {
193  $subject = $this->table->getColumn('no_cache');
194  $this->assertInstanceOf(IntegerType::class, $subject->getType());
195  $this->assertSame(10, $subject->getLength());
196  $this->assertTrue($subject->getUnsigned());
197  $this->assertTrue($subject->getNotnull());
198  $this->assertFalse($subject->getAutoincrement());
199  $this->assertSame('0', $subject->getDefault());
200  }
201 
205  public function isExpectedPrimaryKey()
206  {
207  $subject = $this->table->getPrimaryKey();
208  $this->assertInstanceOf(Index::class, $subject);
209  $this->assertTrue($subject->isPrimary());
210  $this->assertSame(['`uid`'], $subject->getColumns());
211  }
212 
216  public function isExpectedParentKey()
217  {
218  $subject = $this->table->getIndex('parent');
219  $this->assertInstanceOf(Index::class, $subject);
220  $this->assertTrue($subject->isUnique());
221  $this->assertSame(['`pid`', '`deleted`', '`sorting`'], $subject->getColumns());
222  }
223 
227  public function isExpectedNoCacheKey()
228  {
229  $subject = $this->table->getIndex('noCache');
230  $this->assertInstanceOf(Index::class, $subject);
231  $this->assertTrue($subject->isSimpleIndex());
232  $this->assertSame(['`no_cache`'], $subject->getColumns());
233  }
234 
238  public function isExpectedForeignKey()
239  {
240  $subject = $this->table->getForeignKey('fk_overlay');
241  $this->assertInstanceOf(ForeignKeyConstraint::class, $subject);
242  $this->assertSame(['`pid`'], $subject->getForeignColumns());
243  $this->assertSame(['`uid`'], $subject->getLocalColumns());
244  $this->assertSame('aTestTable', $subject->getLocalTableName());
245  $this->assertSame('pages_language_overlay', $subject->getForeignTableName());
246  }
247 
251  public function hasColumnLengthOnIndex()
252  {
253  $subject = $this->table->getIndex('substring');
254  $this->assertSame(['`TSconfig`(80)'], $subject->getColumns());
255  }
256 }
static makeInstance($className,... $constructorArguments)