[BUGFIX] Extension installer: Handle multiple blanks
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / Service / SqlSchemaMigrationServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Install\Tests\Unit\Service;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
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.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Install\Service\SqlSchemaMigrationService;
18
19 /**
20 * Test case
21 *
22 * @author Mario Rimann <mario.rimann@typo3.org>
23 */
24 class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
25
26 /**
27 * @test
28 */
29 public function getFieldDefinitionsFileContentHandlesMultipleWhitespacesInFieldDefinitions() {
30 $subject = new SqlSchemaMigrationService();
31 // Multiple whitespaces and tabs in field definition
32 $inputString = 'CREATE table aTable (' . LF . 'aFieldName int(11)' . TAB . TAB . TAB . 'unsigned DEFAULT \'0\'' . LF . ');';
33 $result = $subject->getFieldDefinitions_fileContent($inputString);
34 $this->assertEquals(
35 array(
36 'aTable' => array(
37 'fields' => array(
38 'aFieldName' => 'int(11) unsigned default \'0\'',
39 ),
40 'extra' => array(
41 'COLLATE' => '',
42 ),
43 ),
44 ),
45 $result
46 );
47 }
48
49 /**
50 * @test
51 */
52 public function getDatabaseExtraFindsChangedFields() {
53 $subject = new SqlSchemaMigrationService();
54 $differenceArray = $subject->getDatabaseExtra(
55 array(
56 'tx_foo' => array(
57 'fields' => array(
58 'foo' => 'varchar(999) DEFAULT \'0\' NOT NULL'
59 )
60 )
61 ),
62 array(
63 'tx_foo' => array(
64 'fields' => array(
65 'foo' => 'varchar(255) DEFAULT \'0\' NOT NULL'
66 )
67 )
68 )
69 );
70
71
72
73 $this->assertEquals(
74 $differenceArray,
75 array(
76 'extra' => array(),
77 'diff' => array(
78 'tx_foo' => array(
79 'fields' => array(
80 'foo' => 'varchar(999) DEFAULT \'0\''
81 )
82 )
83 ),
84 'diff_currentValues' => array(
85 'tx_foo' => array(
86 'fields' => array(
87 'foo' => 'varchar(255) DEFAULT \'0\''
88 )
89 )
90 )
91 )
92 );
93 }
94
95 /**
96 * @test
97 */
98 public function getDatabaseExtraIgnoresCaseDifference() {
99 $subject = new SqlSchemaMigrationService();
100 $differenceArray = $subject->getDatabaseExtra(
101 array(
102 'tx_foo' => array(
103 'fields' => array(
104 'foo' => 'INT(11) DEFAULT \'0\' NOT NULL'
105 )
106 )
107 ),
108 array(
109 'tx_foo' => array(
110 'fields' => array(
111 'foo' => 'int(11) DEFAULT \'0\' NOT NULL'
112 )
113 )
114 )
115 );
116
117
118 $this->assertEquals(
119 $differenceArray,
120 array(
121 'extra' => array(),
122 'diff' => array(),
123 'diff_currentValues' => NULL
124 )
125 );
126 }
127
128 /**
129 * @test
130 */
131 public function getDatabaseExtraDoesNotLowercaseReservedWordsForTheComparison() {
132 $subject = new SqlSchemaMigrationService();
133 $differenceArray = $subject->getDatabaseExtra(
134 array(
135 'tx_foo' => array(
136 'fields' => array(
137 'PRIMARY KEY (md5hash)'
138 )
139 )
140 ),
141 array(
142 'tx_foo' => array(
143 'fields' => array(
144 'PRIMARY KEY (md5hash)')
145 )
146 )
147 );
148
149
150 $this->assertEquals(
151 $differenceArray,
152 array(
153 'extra' => array(),
154 'diff' => array(),
155 'diff_currentValues' => NULL
156 )
157 );
158 }
159 }