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