TYPO3 CMS  TYPO3_7-6
SqlSchemaMigrationServiceTest.php
Go to the documentation of this file.
1 <?php
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 
21 {
26 
30  protected function setUp()
31  {
32  parent::setUp();
33  $this->sqlSchemaMigrationService = new \TYPO3\CMS\Install\Service\SqlSchemaMigrationService();
34  }
35 
40  {
41 
42  // Get the current database fields.
43  $currentDatabaseSchema = $this->sqlSchemaMigrationService->getFieldDefinitions_database();
44 
45  // Limit our scope to the be_users table:
46  $currentDatabaseSchemaForBeUsers = [];
47  $currentDatabaseSchemaForBeUsers['be_users'] = $currentDatabaseSchema['be_users'];
48  unset($currentDatabaseSchema);
49 
50  // Create a key and a field that belongs to that key:
51  $expectedDatabaseSchemaForBeUsers = $currentDatabaseSchemaForBeUsers;
52  $expectedDatabaseSchemaForBeUsers['be_users']['fields']['functional_test_field_1'] = "tinyint(1) unsigned NOT NULL default '0'";
53  $expectedDatabaseSchemaForBeUsers['be_users']['keys']['functional_test_key_1'] = 'KEY functional_test_key_1 (functional_test_field_1)';
54  $createFieldDiff = $this->sqlSchemaMigrationService->getDatabaseExtra($expectedDatabaseSchemaForBeUsers, $currentDatabaseSchemaForBeUsers);
55  $createFieldDiff = $this->sqlSchemaMigrationService->getUpdateSuggestions($createFieldDiff);
56  $this->sqlSchemaMigrationService->performUpdateQueries($createFieldDiff['add'], $createFieldDiff['add']);
57 
58  // Now remove the fields again (without the renaming step).
59  unset($currentDatabaseSchemaForBeUsers['be_users']['fields']['functional_test_field_1']);
60  unset($currentDatabaseSchemaForBeUsers['be_users']['keys']['functional_test_key_1']);
61  $this->sqlSchemaMigrationService->setDeletedPrefixKey('');
62  $removeFieldDiff = $this->sqlSchemaMigrationService->getDatabaseExtra($expectedDatabaseSchemaForBeUsers, $currentDatabaseSchemaForBeUsers);
63  $removeFieldDiff = $this->sqlSchemaMigrationService->getUpdateSuggestions($removeFieldDiff, 'remove');
64  $result = $this->sqlSchemaMigrationService->performUpdateQueries($removeFieldDiff['drop'], $removeFieldDiff['drop']);
65  $this->assertTrue($result, 'performUpdateQueries() did not return TRUE, this means an error occurred: ' . (is_array($result) ? array_pop($result) : ''));
66  }
67 }