[TASK] Implement group "mysql" in functional tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Functional / SqlSchemaMigrationServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Install\Tests\Functional;
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 /**
18 * Functional tests for the SQL schema migration service.
19 */
20 class SqlSchemaMigrationServiceTest extends \TYPO3\Components\TestingFramework\Core\Functional\FunctionalTestCase
21 {
22 /**
23 * @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService
24 */
25 protected $sqlSchemaMigrationService;
26
27 /**
28 * Initializes a SqlSchemaMigrationService instance.
29 */
30 protected function setUp()
31 {
32 parent::setUp();
33 $this->sqlSchemaMigrationService = new \TYPO3\CMS\Install\Service\SqlSchemaMigrationService();
34 }
35
36 /**
37 * @test
38 *
39 * @group mysql
40 */
41 public function columnAndKeyDeletionDoesNotReturnAnError()
42 {
43
44 // Get the current database fields.
45 $currentDatabaseSchema = $this->sqlSchemaMigrationService->getFieldDefinitions_database();
46
47 // Limit our scope to the be_users table:
48 $currentDatabaseSchemaForBeUsers = [];
49 $currentDatabaseSchemaForBeUsers['be_users'] = $currentDatabaseSchema['be_users'];
50 unset($currentDatabaseSchema);
51
52 // Create a key and a field that belongs to that key:
53 $expectedDatabaseSchemaForBeUsers = $currentDatabaseSchemaForBeUsers;
54 $expectedDatabaseSchemaForBeUsers['be_users']['fields']['functional_test_field_1'] = "tinyint(1) unsigned NOT NULL default '0'";
55 $expectedDatabaseSchemaForBeUsers['be_users']['keys']['functional_test_key_1'] = 'KEY functional_test_key_1 (functional_test_field_1)';
56 $createFieldDiff = $this->sqlSchemaMigrationService->getDatabaseExtra($expectedDatabaseSchemaForBeUsers, $currentDatabaseSchemaForBeUsers);
57 $createFieldDiff = $this->sqlSchemaMigrationService->getUpdateSuggestions($createFieldDiff);
58 $this->sqlSchemaMigrationService->performUpdateQueries($createFieldDiff['add'], $createFieldDiff['add']);
59
60 // Now remove the fields again (without the renaming step).
61 unset($currentDatabaseSchemaForBeUsers['be_users']['fields']['functional_test_field_1']);
62 unset($currentDatabaseSchemaForBeUsers['be_users']['keys']['functional_test_key_1']);
63 $this->sqlSchemaMigrationService->setDeletedPrefixKey('');
64 $removeFieldDiff = $this->sqlSchemaMigrationService->getDatabaseExtra($expectedDatabaseSchemaForBeUsers, $currentDatabaseSchemaForBeUsers);
65 $removeFieldDiff = $this->sqlSchemaMigrationService->getUpdateSuggestions($removeFieldDiff, 'remove');
66 $result = $this->sqlSchemaMigrationService->performUpdateQueries($removeFieldDiff['drop'], $removeFieldDiff['drop']);
67 $this->assertTrue($result, 'performUpdateQueries() did not return TRUE, this means an error occurred: ' . (is_array($result) ? array_pop($result) : ''));
68 }
69 }