setLanguage(); } /** * Test for getDbLink */ public function testGetDbLinkNull(): void { Current::$database = 'test_db'; Current::$server = 99; $database = Current::$database; self::assertSame( '' . htmlspecialchars($database) . '', Generator::getDbLink(''), ); } /** * Test for getDbLink */ public function testGetDbLink(): void { Current::$server = 99; $database = 'test_database'; self::assertSame( '' . htmlspecialchars($database) . '', Generator::getDbLink($database), ); } /** * Test for getDbLink */ public function testGetDbLinkWithSpecialChars(): void { Current::$server = 99; $database = 'test&data\'base'; self::assertSame( '' . htmlspecialchars($database) . '', Generator::getDbLink($database), ); } /** * Test for Util::getIcon */ public function testGetIconWithoutActionLinksMode(): void { Config::getInstance()->set('ActionLinksMode', 'text'); self::assertSame( '', Generator::getIcon('b_comment'), ); } /** * Test for Util::getIcon */ public function testGetIconWithActionLinksMode(): void { Config::getInstance()->set('ActionLinksMode', 'icons'); self::assertSame( '', Generator::getIcon('b_comment'), ); } /** * Test for Util::getIcon */ public function testGetIconAlternate(): void { Config::getInstance()->set('ActionLinksMode', 'icons'); $alternateText = 'alt_str'; self::assertSame( '' . $alternateText
            . '', Generator::getIcon('b_comment', $alternateText), ); } /** * Test for Util::getIcon */ public function testGetIconWithForceText(): void { $alternateText = 'alt_str'; // Here we are checking for an icon embedded inside a span (i.e not a menu // bar icon self::assertSame( '' . $alternateText
            . ' ' . $alternateText . '', Generator::getIcon('b_comment', $alternateText, true, false), ); } /** * Test for showPHPDocumentation */ public function testShowPHPDocumentation(): void { $target = 'docu'; $lang = _pgettext('PHP documentation language', 'en'); $expected = '' . ''
            . __('Documentation') . ''; self::assertSame( $expected, Generator::showPHPDocumentation($target), ); } /** * Test for Generator::linkOrButton * * @param mixed[] $params params * @param int $limit limit * @param string $match match */ #[DataProvider('linksOrButtons')] public function testLinkOrButton(array $params, int $limit, string $match): void { $config = Config::getInstance(); $restore = $config->config->LinkLengthLimit; $config->set('LinkLengthLimit', $limit); try { $result = Generator::linkOrButton(...$params); self::assertSame($match, $result); } finally { $config->set('LinkLengthLimit', $restore); } } /** * Data provider for Generator::linkOrButton test * * @return array[]|string[]|null[]|bool[], int, string}> */ public static function linksOrButtons(): array { return [ [['index.php', null, 'text'], 1000, 'text'], [ ['index.php', ['some' => 'parameter'], 'text'], 20, 'text', ], [['index.php', null, 'text', [], 'target'], 1000, 'text'], [ [ 'https://mariadb.org/explain_analyzer/analyze/?client=phpMyAdmin&raw_explain=%2B---%2B', null, 'text', [], 'target', ], 10, // This is not the behavior we want for the analyser feature, next test will disable the limit 'text', ], [ [ 'https://mariadb.org/explain_analyzer/analyze/?client=phpMyAdmin&raw_explain=%2B---%2B', null, 'text', [], 'target', false, ], 10, 'text', ], [ ['index.php?route=/url&url=http://phpmyadmin.net/', null, 'text', [], '_blank'], 1000, 'text', ], [ ['index.php?route=/server/databases', ['some' => 'parameter'], 'text'], 20, 'text', ], [ ['index.php?route=/server/databases', null, 'text'], 20, 'text', ], [ ['index.php?route=/server/databases', ['some' => 'parameter'], 'text'], 100, 'text', ], [ ['index.php?route=/server/databases', null, 'text'], 100, 'text', ], [ [ 'index.php', null, 'text', ['title' => '"'], ], 100, 'text', ], ]; } public function testFormatSql(): void { self::assertSame( '
'
            . 'SELECT 1 < 2'
            . '
', Generator::formatSql('SELECT 1 < 2'), ); Config::getInstance()->set('MaxCharactersInDisplayedSQL', 6); self::assertSame( '
'
            . 'SELECT[...]'
            . '
', Generator::formatSql('SELECT 1 < 2', true), ); } /** * Test for getServerSSL */ public function testGetServerSSL(): void { $sslNotUsed = 'SSL is not being used' . ' Documentation'; $sslNotUsedCaution = 'SSL is not being used' . ' Documentation'; $config = Config::getInstance(); $config->selectedServer = ['ssl' => false, 'host' => '127.0.0.1']; self::assertSame( $sslNotUsed, Generator::getServerSSL(), ); $config->selectedServer = ['ssl' => false, 'host' => 'custom.host']; self::assertSame( $sslNotUsedCaution, Generator::getServerSSL(), ); $config->selectedServer = ['ssl' => false, 'host' => 'custom.host']; $config->set('MysqlSslWarningSafeHosts', ['localhost', '127.0.0.1', 'custom.host']); self::assertSame( $sslNotUsed, Generator::getServerSSL(), ); $config->selectedServer = ['ssl' => false, 'ssl_verify' => true, 'host' => 'custom.host']; self::assertSame( $sslNotUsed, Generator::getServerSSL(), ); $config->selectedServer = ['ssl' => true, 'ssl_verify' => false, 'host' => 'custom.host']; self::assertSame( 'SSL is used with disabled verification' . ' Documentation', Generator::getServerSSL(), ); $config->selectedServer = ['ssl' => true, 'ssl_verify' => true, 'host' => 'custom.host']; self::assertSame( 'SSL is used without certification authority' . ' Documentation', Generator::getServerSSL(), ); $config->selectedServer = [ 'ssl' => true, 'ssl_verify' => true, 'ssl_ca' => '/etc/ssl/ca.crt', 'host' => 'custom.host', ]; self::assertSame( 'SSL is used' . ' Documentation', Generator::getServerSSL(), ); } /** * Test for Generator::getDefaultFunctionForField */ #[DataProvider('providerForTestGetDefaultFunctionForField')] public function testGetDefaultFunctionForField( string $trueType, bool $firstTimestamp, string|null $defaultValue, string $extra, bool $isNull, string $key, string $type, bool $insertMode, string $expected, ): void { $dbiStub = self::createStub(DatabaseInterface::class); $dbiStub->types = new Types($dbiStub); $dbiStub->method('getVersion')->willReturn(50700); DatabaseInterface::$instance = $dbiStub; $result = Generator::getDefaultFunctionForField( $trueType, $firstTimestamp, $defaultValue, $extra, $isNull, $key, $type, $insertMode, ); self::assertSame($expected, $result); } /** * Data provider for Generator::getDefaultFunctionForField test * * @return array{string, bool, string|null, string, bool, string, string, bool, string}[] */ public static function providerForTestGetDefaultFunctionForField(): array { return [ [ 'GEOMETRY', false, null, '', false, '', '', true, 'ST_GeomFromText', ], [ 'timestamp', true, null, '', false, '', '', true, 'NOW', ], [ 'uuid', false, null, '', false, '', '', true, '', ], [ '', false, null, '', false, 'PRI', 'char(36)', true, 'UUID', ], ]; } public function testGetMessage(): void { Current::$displayQuery = null; Current::$sqlQuery = 'SELECT 1;'; Sql::$usingBookmarkMessage = Message::notice('Bookmark message'); DatabaseInterface::$instance = $this->createDatabaseInterface(); Current::$database = 'test_db'; Current::$table = 'test_table'; Current::$server = 2; Sql::$showAsPhp = null; SessionCache::set('profiling_supported', true); // phpcs:disable Generic.Files.LineLength.TooLong $expected = <<<'HTML'
SELECT 1;
HTML; // phpcs:enable self::assertSame($expected, Generator::getMessage('Message [em]one[/em].')); SessionCache::remove('profiling_supported'); } public function testGetMessage2(): void { Current::$displayQuery = 'EXPLAIN SELECT 1;'; Current::$sqlQuery = ''; DatabaseInterface::$instance = $this->createDatabaseInterface(); Current::$database = 'test_db'; Current::$table = 'test_table'; Current::$server = 2; Sql::$showAsPhp = true; SessionCache::set('profiling_supported', true); // phpcs:disable Generic.Files.LineLength.TooLong $expected = <<<'HTML'
$sql = "EXPLAIN SELECT 1;";
HTML; // phpcs:enable self::assertSame($expected, Generator::getMessage(Message::success('Message [em]one[/em].'))); SessionCache::remove('profiling_supported'); } }