3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
8 use PhpMyAdmin\Current
;
9 use PhpMyAdmin\ListDatabase
;
10 use PhpMyAdmin\UserPrivilegesFactory
;
11 use PHPUnit\Framework\Attributes\CoversClass
;
12 use PHPUnit\Framework\Attributes\DataProvider
;
14 #[CoversClass(ListDatabase::class)]
15 class ListDatabaseTest
extends AbstractTestCase
18 * Test for ListDatabase::exists
20 public function testExists(): void
22 $dbi = $this->createDatabaseInterface();
23 $config = new Config();
24 $config->selectedServer
['DisableIS'] = false;
25 $config->selectedServer
['only_db'] = ['single\\_db'];
26 $object = new ListDatabase($dbi, $config, new UserPrivilegesFactory($dbi));
28 self
::assertTrue($object->exists('single_db'));
31 #[DataProvider('providerForTestGetList')]
32 public function testGetList(string $currentDbName, string $dbName): void
34 $dbi = $this->createDatabaseInterface();
35 $config = new Config();
36 $config->selectedServer
['DisableIS'] = false;
37 $config->selectedServer
['only_db'] = ['single\\_db'];
38 $object = new ListDatabase($dbi, $config, new UserPrivilegesFactory($dbi));
40 Current
::$database = $currentDbName;
42 [['name' => $dbName, 'is_selected' => $currentDbName === $dbName]],
47 /** @return list<list{string,string}> */
48 public static function providerForTestGetList(): array
52 ['single_db', 'single_db'],
57 * Test for checkHideDatabase
59 public function testCheckHideDatabase(): void
61 $dbi = $this->createDatabaseInterface();
62 $config = new Config();
63 $config->selectedServer
['DisableIS'] = false;
64 $config->selectedServer
['only_db'] = ['single\\_db'];
65 $config->selectedServer
['hide_db'] = 'single\\_db';
66 $object = new ListDatabase($dbi, $config, new UserPrivilegesFactory($dbi));
68 self
::assertSame([], (array) $object);