2 namespace TYPO3\CMS\Install\Tests\Unit\Service
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Utility\GeneralUtility
;
18 use TYPO3\CMS\Install\Service\SqlSchemaMigrationService
;
23 class SqlSchemaMigrationServiceTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
26 * Get a SchemaService instance with mocked DBAL enable database connection, DBAL not enabled
28 * @return \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
30 protected function getSqlSchemaMigrationService()
32 /** @var \TYPO3\CMS\Dbal\Database\DatabaseConnection|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $databaseConnection */
33 $subject = $this->getAccessibleMock(SqlSchemaMigrationService
::class, array('isDbalEnabled'), array(), '', false);
34 $subject->expects($this->any())->method('isDbalEnabled')->will($this->returnValue(false));
40 * Get a SchemaService instance with mocked DBAL enable database connection, DBAL enabled
42 * @return \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
44 protected function getDbalEnabledSqlSchemaMigrationService()
46 /** @var \TYPO3\CMS\Dbal\Database\DatabaseConnection|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $databaseConnection */
47 $databaseConnection = $this->getAccessibleMock(\TYPO3\CMS\Dbal\Database\DatabaseConnection
::class, array('dummy'), array(), '', false);
48 $databaseConnection->_set('dbmsSpecifics', GeneralUtility
::makeInstance(\TYPO3\CMS\Dbal\Database\Specifics\PostgresSpecifics
::class));
50 $subject = $this->getAccessibleMock(SqlSchemaMigrationService
::class, array('isDbalEnabled', 'getDatabaseConnection'), array(), '', false);
51 $subject->expects($this->any())->method('isDbalEnabled')->will($this->returnValue(true));
52 $subject->expects($this->any())->method('getDatabaseConnection')->will($this->returnValue($databaseConnection));
60 public function getFieldDefinitionsFileContentHandlesMultipleWhitespacesInFieldDefinitions()
62 $subject = $this->getSqlSchemaMigrationService();
63 // Multiple whitespaces and tabs in field definition
64 $inputString = 'CREATE table atable (' . LF
. 'aFieldName int(11)' . TAB
. TAB
. TAB
. 'unsigned DEFAULT \'0\'' . LF
. ');';
65 $result = $subject->getFieldDefinitions_fileContent($inputString);
71 'aFieldName' => 'int(11) unsigned default \'0\'',
85 public function getDatabaseExtraFindsChangedFields()
87 $subject = $this->getSqlSchemaMigrationService();
88 $differenceArray = $subject->getDatabaseExtra(
92 'foo' => 'varchar(999) DEFAULT \'0\' NOT NULL'
99 'foo' => 'varchar(255) DEFAULT \'0\' NOT NULL'
112 'foo' => 'varchar(999) DEFAULT \'0\' NOT NULL'
116 'diff_currentValues' => array(
119 'foo' => 'varchar(255) DEFAULT \'0\' NOT NULL'
130 public function getDatabaseExtraFindsChangedFieldsIncludingNull()
132 $subject = $this->getSqlSchemaMigrationService();
133 $differenceArray = $subject->getDatabaseExtra(
137 'foo' => 'varchar(999) NULL'
144 'foo' => 'varchar(255) NULL'
157 'foo' => 'varchar(999) NULL'
161 'diff_currentValues' => array(
164 'foo' => 'varchar(255) NULL'
175 public function getDatabaseExtraFindsChangedFieldsIgnoreNotNull()
177 $subject = $this->getSqlSchemaMigrationService();
178 $differenceArray = $subject->getDatabaseExtra(
182 'foo' => 'varchar(999) DEFAULT \'0\' NOT NULL'
189 'foo' => 'varchar(255) DEFAULT \'0\' NOT NULL'
204 'foo' => 'varchar(999) DEFAULT \'0\''
208 'diff_currentValues' => array(
211 'foo' => 'varchar(255) DEFAULT \'0\''
222 public function getDatabaseExtraIgnoresCaseDifference()
224 $subject = $this->getSqlSchemaMigrationService();
225 $differenceArray = $subject->getDatabaseExtra(
229 'foo' => 'INT(11) DEFAULT \'0\' NOT NULL',
236 'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
247 'diff_currentValues' => null,
255 public function getDatabaseExtraIgnoresCaseDifferenceButKeepsCaseInSetIntact()
257 $subject = $this->getSqlSchemaMigrationService();
258 $differenceArray = $subject->getDatabaseExtra(
262 'subtype' => 'SET(\'Tx_MyExt_Domain_Model_Xyz\',\'Tx_MyExt_Domain_Model_Abc\',\'\') NOT NULL DEFAULT \'\',',
269 'subtype' => 'set(\'Tx_MyExt_Domain_Model_Xyz\',\'Tx_MyExt_Domain_Model_Abc\',\'\') NOT NULL DEFAULT \'\',',
280 'diff_currentValues' => null,
288 public function getDatabaseExtraDoesNotLowercaseReservedWordsForTheComparison()
290 $subject = $this->getSqlSchemaMigrationService();
291 $differenceArray = $subject->getDatabaseExtra(
295 'PRIMARY KEY (md5hash)',
302 'PRIMARY KEY (md5hash)'),
312 'diff_currentValues' => null,
320 public function getDatabaseExtraFindsNewSpatialKeys()
322 $subject = $this->getSqlSchemaMigrationService();
323 $differenceArray = $subject->getDatabaseExtra(
327 'foo' => 'SPATIAL foo (foo)'
344 'foo' => 'SPATIAL foo (foo)'
349 'diff_currentValues' => null
357 public function checkColumnDefinitionIfCommentIsSupplied()
359 $subject = $this->getSqlSchemaMigrationService();
360 $fieldDefinition = $subject->assembleFieldDefinition(
367 'Extra' => 'auto_increment',
368 'Comment' => 'I am a comment',
373 'int(11) NOT NULL auto_increment COMMENT \'I am a comment\'',
381 public function checkColumnDefinitionIfNoCommentIsSupplied()
383 $subject = $this->getSqlSchemaMigrationService();
384 $fieldDefinition = $subject->assembleFieldDefinition(
391 'Extra' => 'auto_increment',
396 'int(11) NOT NULL auto_increment',
404 public function getDatabaseExtraIncludesEngineIfMySQLIsUsed()
406 $subject = $this->getSqlSchemaMigrationService();
407 $differenceArray = $subject->getDatabaseExtra(
411 'foo' => 'INT(11) DEFAULT \'0\' NOT NULL',
421 'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
435 'diff_currentValues' => null,
443 public function getDatabaseExtraExcludesEngineIfDbalIsUsed()
445 $subject = $this->getDbalEnabledSqlSchemaMigrationService();
446 $differenceArray = $subject->getDatabaseExtra(
450 'foo' => 'INT(11) DEFAULT \'0\' NOT NULL',
460 'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
472 'diff_currentValues' => null,
480 public function getDatabaseExtraIncludesUnsignedAttributeIfMySQLIsUsed()
482 $subject = $this->getSqlSchemaMigrationService();
483 $differenceArray = $subject->getDatabaseExtra(
487 'foo' => 'INT(11) UNSIGNED DEFAULT \'0\' NOT NULL',
497 'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
513 'foo' => 'int(11) UNSIGNED DEFAULT \'0\' NOT NULL',
517 'diff_currentValues' => array(
520 'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
531 public function getDatabaseExtraExcludesUnsignedAttributeIfDbalIsUsed()
533 $subject = $this->getDbalEnabledSqlSchemaMigrationService();
534 $differenceArray = $subject->getDatabaseExtra(
538 'foo' => 'INT(11) UNSIGNED DEFAULT \'0\' NOT NULL',
548 'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
562 'diff_currentValues' => null
570 public function getDatabaseExtraIgnoresIndexPrefixLengthIfDbalIsUsed()
572 $subject = $this->getDbalEnabledSqlSchemaMigrationService();
573 $differenceArray = $subject->getDatabaseExtra(
577 'foo' => 'KEY foo (foo(199))'
584 'foo' => 'KEY foo (foo)'
595 'diff_currentValues' => null,
603 public function getDatabaseExtraComparesIndexPrefixLengthIfMySQLIsUsed()
605 $subject = $this->getSqlSchemaMigrationService();
606 $differenceArray = $subject->getDatabaseExtra(
610 'foo' => 'KEY foo (foo(199))'
617 'foo' => 'KEY foo (foo)'
630 'foo' => 'KEY foo (foo(199))'
634 'diff_currentValues' => array(
637 'foo' => 'KEY foo (foo)'