[TASK] Deprecate $GLOBALS['TYPO3_LOADED_EXT']
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Database / Schema / SqlReaderTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Core\Tests\Unit\Database\Schema;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Core\Database\Schema\SqlReader;
20 use TYPO3\CMS\Core\Package\PackageManager;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22
23 /**
24 * Test case
25 */
26 class SqlReaderTest extends UnitTestCase
27 {
28 /**
29 * @var bool Reset singletons created by subject
30 */
31 protected $resetSingletonInstances = true;
32
33 /**
34 * @test
35 */
36 public function getStatementArraySplitsStatements()
37 {
38 $subject = new SqlReader(null, $this->prophesize(PackageManager::class)->reveal());
39 $result = $subject->getStatementArray(
40 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
41 LF .
42 'INSERT INTO aTestTable(`aTestField`) VALUES(1);'
43 );
44 $this->assertCount(2, $result);
45 $this->assertStringStartsWith('CREATE TABLE', $result[0]);
46 $this->assertStringStartsWith('INSERT INTO', $result[1]);
47 }
48
49 /**
50 * @test
51 */
52 public function getStatementArrayFiltersStatements()
53 {
54 $subject = new SqlReader(null, $this->prophesize(PackageManager::class)->reveal());
55 $result = $subject->getStatementArray(
56 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
57 LF .
58 'INSERT INTO aTestTable(`aTestField`) VALUES(1);',
59 '^CREATE TABLE'
60 );
61 $this->assertCount(1, $result);
62 $this->assertStringStartsWith('CREATE TABLE', array_pop($result));
63 }
64
65 /**
66 * @test
67 */
68 public function getInsertStatementArrayResult()
69 {
70 $subject = new SqlReader(null, $this->prophesize(PackageManager::class)->reveal());
71 $result = $subject->getInsertStatementArray(
72 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
73 LF .
74 'INSERT INTO aTestTable(`aTestField`) VALUES(1);'
75 );
76
77 $this->assertCount(1, $result);
78 $this->assertStringStartsWith('INSERT', array_pop($result));
79 }
80
81 /**
82 * @test
83 */
84 public function getInsertStatementArrayResultWithNewline()
85 {
86 $subject = new SqlReader(null, $this->prophesize(PackageManager::class)->reveal());
87 $result = $subject->getInsertStatementArray(
88 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
89 LF .
90 'INSERT INTO aTestTable(`aTestField`) ' .
91 LF .
92 'VALUES(1);'
93 );
94
95 $this->assertCount(1, $result);
96 $this->assertSame('INSERT INTO aTestTable(`aTestField`) VALUES(1);', array_pop($result));
97 }
98
99 /**
100 * @test
101 */
102 public function getCreateTableStatementArrayResult()
103 {
104 $subject = new SqlReader(null, $this->prophesize(PackageManager::class)->reveal());
105 $result = $subject->getCreateTableStatementArray(
106 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
107 LF .
108 'INSERT INTO aTestTable(`aTestField`) VALUES(1);'
109 );
110 $this->assertCount(1, $result);
111 $this->assertStringStartsWith('CREATE TABLE', array_pop($result));
112 }
113 }