Replace text_dir global var with LanguageManager::$textDir static
[phpmyadmin.git] / tests / classes / FieldMetadataTest.php
blobe1072a12990026b61a4d9ed3c7c63c5bbfdfd27c
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests;
7 use PhpMyAdmin\FieldMetadata;
8 use PHPUnit\Framework\Attributes\CoversClass;
10 use const MYSQLI_BLOB_FLAG;
11 use const MYSQLI_NUM_FLAG;
12 use const MYSQLI_TYPE_FLOAT;
13 use const MYSQLI_TYPE_INT24;
14 use const MYSQLI_TYPE_STRING;
16 #[CoversClass(FieldMetadata::class)]
17 class FieldMetadataTest extends AbstractTestCase
19 public function testEmptyConstruct(): void
21 $fm = FieldHelper::fromArray(['type' => -1]);
22 $this->assertSame('', $fm->getMappedType());
23 $this->assertFalse($fm->isBinary());
24 $this->assertFalse($fm->isEnum());
25 $this->assertFalse($fm->isUniqueKey());
26 $this->assertFalse($fm->isUnsigned());
27 $this->assertFalse($fm->isZerofill());
28 $this->assertFalse($fm->isSet());
29 $this->assertFalse($fm->isNotNull());
30 $this->assertFalse($fm->isPrimaryKey());
31 $this->assertFalse($fm->isMultipleKey());
32 $this->assertFalse($fm->isBlob());
35 public function testIsBinary(): void
37 $fm = FieldHelper::fromArray(['type' => MYSQLI_TYPE_STRING, 'charsetnr' => 63]);
38 $this->assertTrue($fm->isBinary());
39 $this->assertFalse($fm->isEnum());
40 $this->assertFalse($fm->isUniqueKey());
41 $this->assertFalse($fm->isUnsigned());
42 $this->assertFalse($fm->isZerofill());
43 $this->assertFalse($fm->isSet());
44 $this->assertFalse($fm->isNotNull());
45 $this->assertFalse($fm->isPrimaryKey());
46 $this->assertFalse($fm->isMultipleKey());
47 $this->assertFalse($fm->isBlob());
50 public function testIsNumeric(): void
52 $fm = FieldHelper::fromArray(['type' => MYSQLI_TYPE_INT24, 'flags' => MYSQLI_NUM_FLAG]);
53 $this->assertSame('int', $fm->getMappedType());
54 $this->assertFalse($fm->isBinary());
55 $this->assertFalse($fm->isEnum());
56 $this->assertFalse($fm->isUniqueKey());
57 $this->assertFalse($fm->isUnsigned());
58 $this->assertFalse($fm->isZerofill());
59 $this->assertFalse($fm->isSet());
60 $this->assertFalse($fm->isNotNull());
61 $this->assertFalse($fm->isPrimaryKey());
62 $this->assertFalse($fm->isMultipleKey());
63 $this->assertTrue($fm->isNumeric());
64 $this->assertFalse($fm->isBlob());
67 public function testIsBlob(): void
69 $fm = FieldHelper::fromArray(['type' => -1, 'flags' => MYSQLI_BLOB_FLAG]);
70 $this->assertSame('', $fm->getMappedType());
71 $this->assertFalse($fm->isBinary());
72 $this->assertFalse($fm->isEnum());
73 $this->assertFalse($fm->isUniqueKey());
74 $this->assertFalse($fm->isUnsigned());
75 $this->assertFalse($fm->isZerofill());
76 $this->assertFalse($fm->isSet());
77 $this->assertFalse($fm->isNotNull());
78 $this->assertFalse($fm->isPrimaryKey());
79 $this->assertFalse($fm->isMultipleKey());
80 $this->assertTrue($fm->isBlob());
83 public function testIsNumericFloat(): void
85 $fm = FieldHelper::fromArray(['type' => MYSQLI_TYPE_FLOAT, 'flags' => MYSQLI_NUM_FLAG]);
86 $this->assertSame('real', $fm->getMappedType());
87 $this->assertFalse($fm->isBinary());
88 $this->assertFalse($fm->isEnum());
89 $this->assertFalse($fm->isUniqueKey());
90 $this->assertFalse($fm->isUnsigned());
91 $this->assertFalse($fm->isZerofill());
92 $this->assertFalse($fm->isSet());
93 $this->assertFalse($fm->isNotNull());
94 $this->assertFalse($fm->isPrimaryKey());
95 $this->assertFalse($fm->isMultipleKey());
96 $this->assertTrue($fm->isNumeric());
97 $this->assertFalse($fm->isBlob());