[TASK] dbal: convert DBMS specific key/default/extra values to MySQL SQL
[Packages/TYPO3.CMS.git] / typo3 / sysext / dbal / Tests / Unit / Database / DatabaseSpecificsPostgresqlTest.php
1 <?php
2 namespace TYPO3\CMS\Dbal\Tests\Unit\Database;
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 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * Test case
21 */
22 class DatabaseSpecificsPostgresqlTest extends DatabaseSpecificsTest {
23 /**
24 * Set up
25 */
26 protected function setUp() {
27 $GLOBALS['TYPO3_LOADED_EXT'] = array();
28
29 /** @var \TYPO3\CMS\Dbal\Database\Specifics\AbstractSpecifics|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
30 $this->subject = GeneralUtility::makeInstance($this->buildAccessibleProxy(\TYPO3\CMS\Dbal\Database\Specifics\PostgresSpecifics::class));
31 }
32
33 /**
34 * @test
35 * @param array $fieldDefinition
36 * @param string $expected
37 * @dataProvider getNativeDefaultValueProvider
38 */
39 public function getNativeDefaultValueStripsPostgresqlCharacterClasses($fieldDefinition, $expected) {
40 $actual = $this->subject->_call('getNativeDefaultValue', $fieldDefinition);
41 $this->assertSame($expected, $actual);
42 }
43
44 /**
45 * @test
46 * @param array $fieldDefinition
47 * @param string $expected
48 * @dataProvider getNativeExtraFieldAttributeProvider
49 */
50 public function getNativeExtraFieldAttributeSetsAutoIncrement($fieldDefinition, $expected) {
51 $actual = $this->subject->_call('getNativeExtraFieldAttributes', $fieldDefinition);
52 $this->assertSame($expected, $actual);
53 }
54
55 /**
56 * @test
57 * @param array $fieldDefinition
58 * @param string $expected
59 * @dataProvider getNativeKeyForFieldProvider
60 */
61 public function getNativeKeyForFieldProviderIdentifiesIndexes($fieldDefinition, $expected) {
62 $actual = $this->subject->_call('getNativeKeyForField', $fieldDefinition);
63 $this->assertSame($expected, $actual);
64 }
65
66 /**
67 * @return array
68 */
69 public function determineMetaTypeProvider() {
70 return array(
71 array('INT', 'I4'),
72 array('INTEGER', 'I4'),
73 array('TINYINT', 'I2'),
74 array('SMALLINT', 'I2'),
75 array('MEDIUMINT', 'I4'),
76 array('BIGINT', 'I8'),
77 array('DOUBLE', 'F'),
78 array('FLOAT', 'F'),
79 array('TIME', 'T'),
80 array('TIMESTAMP', 'T'),
81 array('DATETIME', 'T'),
82 array('DATE', 'D'),
83 array('YEAR', 'D'),
84 array('IMAGE', 'B'),
85 array('BLOB', 'B'),
86 array('MEDIUMBLOB', 'B'),
87 array('LONGBLOB', 'B'),
88 array('IMAGE', 'B'),
89 array('TEXT', 'XL'),
90 array('MEDIUMTEXT', 'XL'),
91 array('LONGTEXT', 'XL'),
92 array('STRING', 'C'),
93 array('CHAR', 'C'),
94 array('VARCHAR', 'C'),
95 array('TINYBLOB', 'B'),
96 array('TINYTEXT', 'C'),
97 array('ENUM', 'C'),
98 array('SET', 'C')
99 );
100 }
101
102 /**
103 * @return array
104 */
105 public function determineNativeTypeProvider() {
106 return array(
107 array('C', 'VARCHAR'),
108 array('C2', 'VARCHAR'),
109 array('X', 'LONGTEXT'),
110 array('X2', 'LONGTEXT'),
111 array('XL', 'LONGTEXT'),
112 array('B', 'LONGBLOB'),
113 array('D', 'DATE'),
114 array('T', 'DATETIME'),
115 array('L', 'TINYINT'),
116 array('I', 'INT'),
117 array('I1', 'SMALLINT'),
118 array('I2', 'SMALLINT'),
119 array('I4', 'INT'),
120 array('I8', 'BIGINT'),
121 array('R', 'INT'),
122 array('F', 'DOUBLE'),
123 array('N', 'NUMERIC'),
124 array('U', 'U')
125 );
126 }
127
128 /**
129 * @return array
130 */
131 public function determineNativeFieldLengthProvider() {
132 return array(
133 array('SMALLINT', '2', '(6)'),
134 array('INT', '4', '(11)'),
135 array('BIGINT', '8', '(20)'),
136 array('VARCHAR', -1, ''),
137 array('VARCHAR', 30, '(30)'),
138 array('DOUBLE', 8, '')
139 );
140 }
141
142 /**
143 * @return array
144 */
145 public function getNativeDefaultValueProvider() {
146 return array(
147 array(array('type' => 'SERIAL', 'has_default' => 1, 'default_value' => "nextval('tx_extensionmanager_domain_model_repository_uid_seq'::regclass)"), NULL),
148 array(array('type' => 'int4', 'has_default' => TRUE, 'default_value' => 0), 0),
149 array(array('type' => 'int4', 'has_default' => TRUE, 'default_value' => '(-1)'), -1),
150 array(array('type' => 'text', 'has_default' => FALSE, 'default_value' => NULL), NULL),
151 array(array('type' => 'varchar', 'has_default' => TRUE, 'default_value' => "''::character varying"), ""),
152 array(array('type' => 'varchar', 'has_default' => TRUE, 'default_value' => "'something'::character varying"), "something"),
153 array(array('type' => 'varchar', 'has_default' => TRUE, 'default_value' => "'some''thing'::character varying"), "some''thing"),
154 );
155 }
156
157 /**
158 * @return array
159 */
160 public function getNativeExtraFieldAttributeProvider() {
161 return array(
162 array(array('type' => 'SERIAL'), 'auto_increment'),
163 array(array('type' => 'int4', 'default_value' => 'nextval(\'somesequence_seq\''), 'auto_increment'),
164 array(array('type' => 'int4', 'default_value' => 0), '')
165 );
166 }
167
168 /**
169 * @return array
170 */
171 public function getNativeKeyForFieldProvider() {
172 return array(
173 array(array('primary_key' => TRUE), 'PRI'),
174 array(array('unique' => TRUE), 'UNI'),
175 array(array(), '')
176 );
177 }
178 }