assertEquals( '' . htmlspecialchars($database) . '', Generator::getDbLink(''), ); } /** * Test for getDbLink */ public function testGetDbLink(): void { $GLOBALS['server'] = 99; $database = 'test_database'; $this->assertEquals( '' . htmlspecialchars($database) . '', Generator::getDbLink($database), ); } /** * Test for getDbLink */ public function testGetDbLinkWithSpecialChars(): void { $GLOBALS['server'] = 99; $database = 'test&data\'base'; $this->assertEquals( '' . htmlspecialchars($database) . '', Generator::getDbLink($database), ); } /** * Test for Util::getIcon */ public function testGetIconWithoutActionLinksMode(): void { Config::getInstance()->settings['ActionLinksMode'] = 'text'; $this->assertEquals( '', Generator::getIcon('b_comment'), ); } /** * Test for Util::getIcon */ public function testGetIconWithActionLinksMode(): void { Config::getInstance()->settings['ActionLinksMode'] = 'icons'; $this->assertEquals( '', Generator::getIcon('b_comment'), ); } /** * Test for Util::getIcon */ public function testGetIconAlternate(): void { Config::getInstance()->settings['ActionLinksMode'] = 'icons'; $alternateText = 'alt_str'; $this->assertEquals( '' . $alternateText
            . '', Generator::getIcon('b_comment', $alternateText), ); } /** * Test for Util::getIcon */ public function testGetIconWithForceText(): void { Config::getInstance()->settings['ActionLinksMode'] = 'icons'; $alternateText = 'alt_str'; // Here we are checking for an icon embedded inside a span (i.e not a menu // bar icon $this->assertEquals( '' . $alternateText
            . ' ' . $alternateText . '', Generator::getIcon('b_comment', $alternateText, true, false), ); } /** * Test for showPHPDocumentation */ public function testShowPHPDocumentation(): void { $GLOBALS['server'] = 99; Config::getInstance()->settings['ServerDefault'] = 0; $target = 'docu'; $lang = _pgettext('PHP documentation language', 'en'); $expected = '' . ''
            . __('Documentation') . ''; $this->assertEquals( $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->settings['LinkLengthLimit'] ?? 1000; $config->settings['LinkLengthLimit'] = $limit; try { $result = call_user_func_array( [Generator::class, 'linkOrButton'], $params, ); $this->assertEquals($match, $result); } finally { $config->settings['LinkLengthLimit'] = $restore; } } /** * Data provider for Generator::linkOrButton test * * @return mixed[] */ 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 { $this->assertEquals( '
' . "\n"
            . 'SELECT 1 < 2' . "\n"
            . '
', Generator::formatSql('SELECT 1 < 2'), ); Config::getInstance()->settings['MaxCharactersInDisplayedSQL'] = 6; $this->assertEquals( '
' . "\n"
            . 'SELECT[...]' . "\n"
            . '
', 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']; $this->assertEquals( $sslNotUsed, Generator::getServerSSL(), ); $config->selectedServer = ['ssl' => false, 'host' => 'custom.host']; $config->settings['MysqlSslWarningSafeHosts'] = ['localhost', '127.0.0.1']; $this->assertEquals( $sslNotUsedCaution, Generator::getServerSSL(), ); $config->selectedServer = ['ssl' => false, 'host' => 'custom.host']; $config->settings['MysqlSslWarningSafeHosts'] = ['localhost', '127.0.0.1', 'custom.host']; $this->assertEquals( $sslNotUsed, Generator::getServerSSL(), ); $config->selectedServer = ['ssl' => false, 'ssl_verify' => true, 'host' => 'custom.host']; $this->assertEquals( $sslNotUsed, Generator::getServerSSL(), ); $config->selectedServer = ['ssl' => true, 'ssl_verify' => false, 'host' => 'custom.host']; $this->assertEquals( 'SSL is used with disabled verification' . ' Documentation', Generator::getServerSSL(), ); $config->selectedServer = ['ssl' => true, 'ssl_verify' => true, 'host' => 'custom.host']; $this->assertEquals( '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', ]; $this->assertEquals( '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 = $this->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, ); $this->assertEquals($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 { Config::getInstance()->settings['ShowSQL'] = true; $GLOBALS['display_query'] = null; $GLOBALS['unparsed_sql'] = null; $GLOBALS['sql_query'] = 'SELECT 1;'; $usingBookmarkMessage = Message::notice('Bookmark message'); $GLOBALS['using_bookmark_message'] = $usingBookmarkMessage; DatabaseInterface::$instance = $this->createDatabaseInterface(); $GLOBALS['db'] = 'test_db'; $GLOBALS['table'] = 'test_table'; $GLOBALS['server'] = 2; $GLOBALS['special_message'] = 'Message [em]two[/em].'; SessionCache::set('profiling_supported', true); // phpcs:disable Generic.Files.LineLength.TooLong $expected = <<<'HTML'
SELECT 1;
HTML; // phpcs:enable $this->assertSame($expected, Generator::getMessage('Message [em]one[/em].')); $this->assertArrayNotHasKey('using_bookmark_message', $GLOBALS); $this->assertArrayNotHasKey('special_message', $GLOBALS); SessionCache::remove('profiling_supported'); } public function testGetMessage2(): void { $config = Config::getInstance(); $config->settings['ShowSQL'] = true; $config->settings['SQLQuery']['Edit'] = false; $config->settings['SQLQuery']['Refresh'] = true; $GLOBALS['display_query'] = 'EXPLAIN SELECT 1;'; $GLOBALS['unparsed_sql'] = null; $GLOBALS['sql_query'] = null; DatabaseInterface::$instance = $this->createDatabaseInterface(); $GLOBALS['db'] = 'test_db'; $GLOBALS['table'] = 'test_table'; $GLOBALS['server'] = 2; $GLOBALS['show_as_php'] = true; $GLOBALS['special_message'] = 'Message [em]two[/em].'; SessionCache::set('profiling_supported', true); // phpcs:disable Generic.Files.LineLength.TooLong $expected = <<<'HTML'
$sql = "EXPLAIN SELECT 1;";
HTML; // phpcs:enable $this->assertSame($expected, Generator::getMessage(Message::success('Message [em]one[/em].'))); $this->assertArrayNotHasKey('special_message', $GLOBALS); SessionCache::remove('profiling_supported'); } }