3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
7 use PhpMyAdmin\DatabaseInterface
;
9 use PHPUnit\Framework\Attributes\CoversClass
;
10 use PHPUnit\Framework\Attributes\DataProvider
;
12 #[CoversClass(Types::class)]
13 class TypesTest
extends AbstractTestCase
15 protected Types
$object;
18 * Sets up the fixture, for example, opens a network connection.
19 * This method is called before a test is executed.
21 protected function setUp(): void
25 DatabaseInterface
::$instance = $this->createDatabaseInterface();
26 $this->object = new Types(DatabaseInterface
::getInstance());
30 * Test for isUnaryOperator
32 public function testUnary(): void
34 self
::assertTrue($this->object->isUnaryOperator('IS NULL'));
35 self
::assertFalse($this->object->isUnaryOperator('='));
39 * Test for getUnaryOperators
41 public function testGetUnaryOperators(): void
44 ['IS NULL', 'IS NOT NULL', "= ''", "!= ''"],
45 $this->object->getUnaryOperators(),
50 * Test for getNullOperators
52 public function testGetNullOperators(): void
55 ['IS NULL', 'IS NOT NULL'],
56 $this->object->getNullOperators(),
61 * Test for getEnumOperators
63 public function testGetEnumOperators(): void
67 $this->object->getEnumOperators(),
72 * Test for getTextOperators
74 public function testgetTextOperators(): void
94 $this->object->getTextOperators(),
99 * Test for getNumberOperators
101 public function testGetNumberOperators(): void
120 $this->object->getNumberOperators(),
125 * Test for getUUIDOperators
127 public function testGetUUIDOperators(): void
130 ['=', '!=', 'LIKE', 'LIKE %...%', 'NOT LIKE', 'NOT LIKE %...%', 'IN (...)', 'NOT IN (...)'],
131 $this->object->getUUIDOperators(),
136 * Test for getting type operators
138 * @param string $type Type of field
139 * @param bool $null Whether field can be NULL
140 * @param string|string[] $output Expected output
142 #[DataProvider('providerForGetTypeOperators')]
143 public function testGetTypeOperators(string $type, bool $null, string|
array $output): void
147 $this->object->getTypeOperators($type, $null),
152 * data provider for testGetTypeOperators
154 * @return array<array{string, bool, string|string[]}>
156 public static function providerForGetTypeOperators(): array
159 ['enum', false, ['=', '!=']],
206 ['=', '!=', 'LIKE', 'LIKE %...%', 'NOT LIKE', 'NOT LIKE %...%', 'IN (...)', 'NOT IN (...)'],
228 * Test for getTypeOperatorsHtml
230 * @param string $type Type of field
231 * @param bool $null Whether field can be NULL
232 * @param string $selectedOperator Option to be selected
233 * @param string $output Expected output
235 #[DataProvider('providerForTestGetTypeOperatorsHtml')]
236 public function testGetTypeOperatorsHtml(
239 string $selectedOperator,
244 $this->object->getTypeOperatorsHtml($type, $null, $selectedOperator),
249 * Provider for testGetTypeOperatorsHtml
251 * @return array<array{string, bool, string, string}>
253 public static function providerForTestGetTypeOperatorsHtml(): array
256 ['enum', false, '=', '<option value="=" selected="selected">=</option><option value="!=">!=</option>'],
261 * Test for getTypeDescription
263 * @param string $type The data type to get a description.
265 #[DataProvider('providerForTestGetTypeDescription')]
266 public function testGetTypeDescription(string $type): void
268 self
::assertNotEquals(
270 $this->object->getTypeDescription($type),
275 * Test for getTypeDescription with unknown value
277 public function testGetUnknownTypeDescription(): void
281 $this->object->getTypeDescription('UNKNOWN'),
286 * Provider for testGetTypeDescription
288 * @return array<array{string}>
290 public static function providerForTestGetTypeDescription(): array
331 ['GEOMETRYCOLLECTION'],
339 * @param string $class The class to get function list.
340 * @param string[] $output Expected function list
342 #[DataProvider('providerFortTestGetFunctionsClass')]
343 public function testGetFunctionsClass(string $class, array $output): void
347 $this->object->getFunctionsClass($class),
351 /** @return array<array{string, string[]}> */
352 public static function providerFortTestGetFunctionsClass(): array
421 'ST_GeomCollFromText',
429 'ST_GeomCollFromWKB',
486 'UNCOMPRESSED_LENGTH',
500 * Test for getFunctions
502 public function testGetFunctions(): void
542 $this->object->getFunctions('enum'),
547 * Test for getAllFunctions
549 public function testGetAllFunctions(): void
630 'ST_GeomCollFromText',
631 'ST_GeomCollFromWKB',
655 'UNCOMPRESSED_LENGTH',
672 $this->object->getAllFunctions(),
677 * Test for getAttributes
679 public function testGetAttributes(): void
682 ['', 'BINARY', 'UNSIGNED', 'UNSIGNED ZEROFILL', 'on update CURRENT_TIMESTAMP'],
683 $this->object->getAttributes(),
688 * Test for getColumns
690 public function testGetColumns(): void
714 'Date and time' => ['DATE', 'DATETIME', 'TIMESTAMP', 'TIME', 'YEAR'],
743 'GEOMETRYCOLLECTION',
747 $this->object->getColumns(),
752 * @param string $type Type to check
753 * @param string $output Expected result
755 #[DataProvider('providerFortTestGetTypeClass')]
756 public function testGetTypeClass(string $type, string $output): void
760 $this->object->getTypeClass($type),
765 * Data provider for type testing
767 * @return array<array{string, string}>
769 public static function providerFortTestGetTypeClass(): array
772 ['SERIAL', 'NUMBER'],
774 ['GEOMETRYCOLLECTION', 'SPATIAL'],