2
2
/***************************************************************
3
3
* Copyright notice
4
4
*
5
- * (c) 2019 AOE GmbH <[email protected] >
5
+ * (c) 2020 AOE GmbH <[email protected] >
6
6
*
7
7
* All rights reserved
8
8
*
23
23
* This copyright notice MUST APPEAR in all copies of the script!
24
24
***************************************************************/
25
25
26
+ use Doctrine \DBAL \Schema \Column ;
27
+ use Doctrine \DBAL \Types \Type as ColumnTypes ;
26
28
use Nimut \TestingFramework \TestCase \FunctionalTestCase ;
29
+ use TYPO3 \CMS \Core \Database \Connection ;
30
+ use TYPO3 \CMS \Core \Database \ConnectionPool ;
27
31
use TYPO3 \CMS \Core \Utility \GeneralUtility ;
28
32
use TYPO3 \CMS \Install \Service \SqlExpectedSchemaService ;
29
33
@@ -98,10 +102,12 @@ public function doesUpdateStructureActionReportChanges()
98
102
$ result = $ this ->controller ->updateStructureAction ($ arguments );
99
103
100
104
// Assert that nothing has been created, this is just for reporting:
101
- $ tables = $ GLOBALS ['TYPO3_DB ' ]->admin_get_tables ();
102
- $ pagesFields = $ GLOBALS ['TYPO3_DB ' ]->admin_get_fields ('pages ' );
105
+ $ tables = $ this ->getTables ();
106
+ $ pagesFields = $ this ->getTableColumns ('pages ' );
107
+
103
108
$ this ->assertFalse (isset ($ tables ['tx_testextension_test ' ]));
104
- $ this ->assertNotEquals ('varchar(255) ' , strtolower ($ pagesFields ['alias ' ]['Type ' ]));
109
+ $ this ->assertEquals (ColumnTypes::STRING , $ pagesFields ['alias ' ]->getType ()->getName ());
110
+ $ this ->assertEquals (33 , $ pagesFields ['alias ' ]->getLength ());
105
111
106
112
// Assert that changes are reported:
107
113
$ this ->assertContains ('ALTER TABLE pages ADD tx_testextension_field_test ' , $ result );
@@ -122,12 +128,14 @@ public function doesUpdateStructureActionExecuteChanges()
122
128
$ result = $ this ->controller ->updateStructureAction ($ arguments );
123
129
124
130
// Assert that tables have been created:
125
- $ tables = $ GLOBALS ['TYPO3_DB ' ]->admin_get_tables ();
126
- $ pagesFields = $ GLOBALS ['TYPO3_DB ' ]->admin_get_fields ('pages ' );
131
+ $ tables = $ this ->getTables ();
132
+ $ pagesFields = $ this ->getTableColumns ('pages ' );
133
+
127
134
$ this ->assertTrue (isset ($ tables ['tx_testextension ' ]));
128
135
$ this ->assertTrue (isset ($ tables ['tx_testextension_test ' ]));
129
136
$ this ->assertTrue (isset ($ pagesFields ['tx_testextension_field_test ' ]));
130
- $ this ->assertEquals ('varchar(255) ' , strtolower ($ pagesFields ['alias ' ]['Type ' ]));
137
+ $ this ->assertEquals (ColumnTypes::STRING , $ pagesFields ['alias ' ]->getType ()->getName ());
138
+ $ this ->assertEquals (255 , $ pagesFields ['alias ' ]->getLength ());
131
139
132
140
// Assert that nothing is reported we just want to execute:
133
141
$ this ->assertEmpty ($ result );
@@ -149,9 +157,10 @@ public function doesUpdateStructureActionReportRemovals()
149
157
$ result = $ this ->controller ->updateStructureAction ($ arguments );
150
158
151
159
// Assert that nothing has been removed, this is just for reporting:
152
- $ tables = $ GLOBALS [ ' TYPO3_DB ' ]-> admin_get_tables ();
160
+ $ tables = $ this -> getTables ();
153
161
$ this ->assertTrue (isset ($ tables ['tx_testextension ' ]));
154
- $ pagesFields = $ GLOBALS ['TYPO3_DB ' ]->admin_get_fields ('pages ' );
162
+
163
+ $ pagesFields = $ this ->getTableColumns ('pages ' );
155
164
$ this ->assertTrue (isset ($ pagesFields ['tx_testextension_field ' ]));
156
165
157
166
// Assert that removals are reported:
@@ -175,9 +184,10 @@ public function doesUpdateStructureActionExecuteRemovals()
175
184
$ result = $ this ->controller ->updateStructureAction ($ arguments );
176
185
177
186
// Assert that tables and columns have been removed:
178
- $ tables = $ GLOBALS [ ' TYPO3_DB ' ]-> admin_get_tables ();
187
+ $ tables = $ this -> getTables ();
179
188
$ this ->assertFalse (isset ($ tables ['tx_testextension ' ]));
180
- $ pagesFields = $ GLOBALS ['TYPO3_DB ' ]->admin_get_fields ('pages ' );
189
+
190
+ $ pagesFields = $ this ->getTableColumns ('pages ' );
181
191
$ this ->assertFalse (isset ($ pagesFields ['tx_testextension_field ' ]));
182
192
183
193
// Assert that nothing is reported we just want to execute:
@@ -200,9 +210,10 @@ public function doesUpdateStructureActionReportDropKeys()
200
210
$ result = $ this ->controller ->updateStructureAction ($ arguments );
201
211
202
212
// Assert that nothing has been removed, this is just for reporting:
203
- $ tables = $ GLOBALS [ ' TYPO3_DB ' ]-> admin_get_tables ();
213
+ $ tables = $ this -> getTables ();
204
214
$ this ->assertTrue (isset ($ tables ['tx_testextension ' ]));
205
- $ pagesFields = $ GLOBALS ['TYPO3_DB ' ]->admin_get_fields ('pages ' );
215
+
216
+ $ pagesFields = $ this ->getTableColumns ('pages ' );
206
217
$ this ->assertTrue (isset ($ pagesFields ['tx_testextension_field ' ]));
207
218
208
219
// Assert that removals are reported:
@@ -233,6 +244,7 @@ public function doesUpdateStructureActionDumpChangesToFile()
233
244
234
245
$ this ->assertFileExists ($ testDumpFile );
235
246
$ testDumpFileContent = file_get_contents ($ testDumpFile );
247
+
236
248
// Assert that changes are dumped:
237
249
$ this ->assertContains ('ALTER TABLE pages ADD tx_testextension_field_test ' , $ testDumpFileContent );
238
250
$ this ->assertContains ('ALTER TABLE pages CHANGE alias alias varchar(255) ' , $ testDumpFileContent );
@@ -241,4 +253,32 @@ public function doesUpdateStructureActionDumpChangesToFile()
241
253
// Assert that dump result is reported:
242
254
$ this ->assertNotEmpty ($ result );
243
255
}
244
- }
256
+
257
+ /**
258
+ * @return string[]
259
+ */
260
+ private function getTables ()
261
+ {
262
+ /** @var Connection $connection */
263
+ $ connection = GeneralUtility::makeInstance (ConnectionPool::class)->getConnectionByName ('Default ' );
264
+ $ tables = $ connection ->getSchemaManager ()->listTableNames ();
265
+
266
+ return array_flip ($ tables );
267
+ }
268
+
269
+ /**
270
+ * @param string $table
271
+ * @return Column[]
272
+ */
273
+ private function getTableColumns (string $ table )
274
+ {
275
+ /** @var Connection $connection */
276
+ $ connection = GeneralUtility::makeInstance (ConnectionPool::class)->getConnectionByName ('Default ' );
277
+ $ tableColumns = [];
278
+ foreach ($ connection ->getSchemaManager ()->listTableColumns ($ table ) as $ column ) {
279
+ $ tableColumns [$ column ->getName ()] = $ column ;
280
+ }
281
+
282
+ return $ tableColumns ;
283
+ }
284
+ }
0 commit comments