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