Remove some useless comments
[phpmyadmin.git] / test / classes / Plugins / Export / Helpers / TablePropertyTest.php
blobfdc3b2b1865390fdb2aa2f94222ea4906f36376a
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests\Plugins\Export\Helpers;
7 use PhpMyAdmin\Plugins\Export\Helpers\TableProperty;
8 use PhpMyAdmin\Tests\AbstractTestCase;
10 class TablePropertyTest extends AbstractTestCase
12 /** @var TableProperty */
13 protected $object;
15 /**
16 * Configures global environment.
18 protected function setUp(): void
20 parent::setUp();
21 $GLOBALS['server'] = 0;
22 $row = [
23 ' name ',
24 'int ',
25 true,
26 ' PRI',
27 '0',
28 'mysql',
30 $this->object = new TableProperty($row);
33 /**
34 * tearDown for test cases
36 protected function tearDown(): void
38 parent::tearDown();
39 unset($this->object);
42 public function testConstructor(): void
44 $this->assertEquals(
45 'name',
46 $this->object->name
49 $this->assertEquals(
50 'int',
51 $this->object->type
54 $this->assertEquals(
56 $this->object->nullable
59 $this->assertEquals(
60 'PRI',
61 $this->object->key
64 $this->assertEquals(
65 '0',
66 $this->object->defaultValue
69 $this->assertEquals(
70 'mysql',
71 $this->object->ext
75 public function testGetPureType(): void
77 $this->object->type = 'int(10)';
79 $this->assertEquals(
80 'int',
81 $this->object->getPureType()
84 $this->object->type = 'char';
86 $this->assertEquals(
87 'char',
88 $this->object->getPureType()
92 /**
93 * @param string $nullable nullable value
94 * @param string $expected expected output
96 * @dataProvider isNotNullProvider
98 public function testIsNotNull(string $nullable, string $expected): void
100 $this->object->nullable = $nullable;
102 $this->assertEquals(
103 $expected,
104 $this->object->isNotNull()
109 * Data provider for testIsNotNull
111 * @return array Test Data
113 public function isNotNullProvider(): array
115 return [
117 'NO',
118 'true',
122 'false',
125 'no',
126 'false',
132 * @param string $key key value
133 * @param string $expected expected output
135 * @dataProvider isUniqueProvider
137 public function testIsUnique(string $key, string $expected): void
139 $this->object->key = $key;
141 $this->assertEquals(
142 $expected,
143 $this->object->isUnique()
148 * Data provider for testIsUnique
150 * @return array Test Data
152 public function isUniqueProvider(): array
154 return [
156 'PRI',
157 'true',
160 'UNI',
161 'true',
165 'false',
168 'pri',
169 'false',
172 'uni',
173 'false',
179 * @param string $type type value
180 * @param string $expected expected output
182 * @dataProvider getDotNetPrimitiveTypeProvider
184 public function testGetDotNetPrimitiveType(string $type, string $expected): void
186 $this->object->type = $type;
188 $this->assertEquals(
189 $expected,
190 $this->object->getDotNetPrimitiveType()
195 * Data provider for testGetDotNetPrimitiveType
197 * @return array Test Data
199 public function getDotNetPrimitiveTypeProvider(): array
201 return [
203 'int',
204 'int',
207 'long',
208 'long',
211 'char',
212 'string',
215 'varchar',
216 'string',
219 'text',
220 'string',
223 'longtext',
224 'string',
227 'tinyint',
228 'bool',
231 'datetime',
232 'DateTime',
236 'unknown',
239 'dummy',
240 'unknown',
243 'INT',
244 'unknown',
250 * @param string $type type value
251 * @param string $expected expected output
253 * @dataProvider getDotNetObjectTypeProvider
255 public function testGetDotNetObjectType(string $type, string $expected): void
257 $this->object->type = $type;
259 $this->assertEquals(
260 $expected,
261 $this->object->getDotNetObjectType()
266 * Data provider for testGetDotNetObjectType
268 * @return array Test Data
270 public function getDotNetObjectTypeProvider(): array
272 return [
274 'int',
275 'Int32',
278 'long',
279 'Long',
282 'char',
283 'String',
286 'varchar',
287 'String',
290 'text',
291 'String',
294 'longtext',
295 'String',
298 'tinyint',
299 'Boolean',
302 'datetime',
303 'DateTime',
307 'Unknown',
310 'dummy',
311 'Unknown',
314 'INT',
315 'Unknown',
320 public function testGetIndexName(): void
322 $this->object->name = "ä'7<ab>";
323 $this->object->key = 'PRI';
325 $this->assertEquals(
326 "index=\"ä'7&lt;ab&gt;\"",
327 $this->object->getIndexName()
330 $this->object->key = '';
332 $this->assertEquals(
334 $this->object->getIndexName()
338 public function testIsPK(): void
340 $this->object->key = 'PRI';
342 $this->assertTrue(
343 $this->object->isPK()
346 $this->object->key = '';
348 $this->assertFalse(
349 $this->object->isPK()
353 public function testFormatCs(): void
355 $this->object->name = 'Name#name#123';
357 $this->assertEquals(
358 'text123Namename',
359 $this->object->formatCs('text123#name#')
363 public function testFormatXml(): void
365 $this->object->name = '"a\'';
367 $this->assertEquals(
368 '&quot;a\'index="&quot;a\'"',
369 $this->object->formatXml('#name##indexName#')
373 public function testFormat(): void
375 $this->assertEquals(
376 'NameintInt32intfalsetrue',
377 $this->object->format(
378 '#ucfirstName##dotNetPrimitiveType##dotNetObjectType##type#' .
379 '#notNull##unique#'