assertEmpty(Generator::getDbLink()); } /** * Test for getDbLink * * @group medium */ public function testGetDbLinkNull(): void { global $cfg; $GLOBALS['db'] = 'test_db'; $GLOBALS['server'] = 99; $database = $GLOBALS['db']; $this->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 { $GLOBALS['cfg']['ActionLinksMode'] = 'text'; $this->assertEquals( '', Generator::getIcon('b_comment') ); } /** * Test for Util::getIcon */ public function testGetIconWithActionLinksMode(): void { $GLOBALS['cfg']['ActionLinksMode'] = 'icons'; $this->assertEquals( '', Generator::getIcon('b_comment') ); } /** * Test for Util::getIcon */ public function testGetIconAlternate(): void { $GLOBALS['cfg']['ActionLinksMode'] = 'icons'; $alternate_text = 'alt_str'; $this->assertEquals( '' . $alternate_text
            . '', Generator::getIcon('b_comment', $alternate_text) ); } /** * Test for Util::getIcon */ public function testGetIconWithForceText(): void { $GLOBALS['cfg']['ActionLinksMode'] = 'icons'; $alternate_text = 'alt_str'; // Here we are checking for an icon embedded inside a span (i.e not a menu // bar icon $this->assertEquals( '' . $alternate_text
            . ' ' . $alternate_text . '', Generator::getIcon('b_comment', $alternate_text, true, false) ); } /** * Test for showPHPDocumentation */ public function testShowPHPDocumentation(): void { $GLOBALS['server'] = 99; $GLOBALS['cfg']['ServerDefault'] = 0; $target = 'docu'; $lang = _pgettext('PHP documentation language', 'en'); $expected = '' . ''
            . __('Documentation') . ''; $this->assertEquals( $expected, Generator::showPHPDocumentation($target) ); } /** * Test for Generator::linkOrButton * * @param array $params params * @param int $limit limit * @param string $match match * * @dataProvider linksOrButtons */ public function testLinkOrButton(array $params, int $limit, string $match): void { parent::setGlobalConfig(); $restore = $GLOBALS['cfg']['LinkLengthLimit'] ?? 1000; $GLOBALS['cfg']['LinkLengthLimit'] = $limit; try { $result = call_user_func_array( [ Generator::class, 'linkOrButton', ], $params ); $this->assertEquals($match, $result); } finally { $GLOBALS['cfg']['LinkLengthLimit'] = $restore; } } /** * Data provider for Generator::linkOrButton test * * @return array */ 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', ], [ [ 'url.php?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') ); $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 6; $this->assertEquals( '
' . "\n"
            . 'SELECT[...]' . "\n"
            . '
', Generator::formatSql('SELECT 1 < 2', true) ); } /** * Test for getServerSSL */ public function testGetServerSSL(): void { global $cfg; $sslNotUsed = 'SSL is not being used' . ' Documentation'; $sslNotUsedCaution = 'SSL is not being used' . ' Documentation'; $cfg['Server'] = [ 'ssl' => false, 'host' => '127.0.0.1', ]; $this->assertEquals( $sslNotUsed, Generator::getServerSSL() ); $cfg['Server'] = [ 'ssl' => false, 'host' => 'custom.host', ]; $cfg['MysqlSslWarningSafeHosts'] = ['localhost', '127.0.0.1']; $this->assertEquals( $sslNotUsedCaution, Generator::getServerSSL() ); $cfg['Server'] = [ 'ssl' => false, 'host' => 'custom.host', ]; $cfg['MysqlSslWarningSafeHosts'] = ['localhost', '127.0.0.1', 'custom.host']; $this->assertEquals( $sslNotUsed, Generator::getServerSSL() ); $cfg['Server'] = [ 'ssl' => false, 'ssl_verify' => true, 'host' => 'custom.host', ]; $this->assertEquals( $sslNotUsed, Generator::getServerSSL() ); $cfg['Server'] = [ 'ssl' => true, 'ssl_verify' => false, 'host' => 'custom.host', ]; $this->assertEquals( 'SSL is used with disabled verification' . ' Documentation', Generator::getServerSSL() ); $cfg['Server'] = [ 'ssl' => true, 'ssl_verify' => true, 'host' => 'custom.host', ]; $this->assertEquals( 'SSL is used without certification authority' . ' Documentation', Generator::getServerSSL() ); $cfg['Server'] = [ '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 * * @param array $field field settings * @param bool $insertMode true if insert mode * @param string $expected expected result * @psalm-param array $field * * @dataProvider providerForTestGetDefaultFunctionForField */ public function testGetDefaultFunctionForField( array $field, bool $insertMode, string $expected ): void { $result = Generator::getDefaultFunctionForField($field, $insertMode); $this->assertEquals($expected, $result); } /** * Data provider for Generator::getDefaultFunctionForField test * * @return array * @psalm-return array, bool, string}> */ public static function providerForTestGetDefaultFunctionForField(): array { return [ [ [ 'True_Type' => 'GEOMETRY', 'first_timestamp' => false, 'Extra' => null, 'Key' => '', 'Type' => '', 'Null' => 'NO', ], true, 'ST_GeomFromText', ], [ [ 'True_Type' => 'timestamp', 'first_timestamp' => true, 'Extra' => null, 'Key' => '', 'Type' => '', 'Null' => 'NO', ], true, 'NOW', ], [ [ 'True_Type' => 'uuid', 'first_timestamp' => false, 'Key' => '', 'Type' => '', ], true, '', ], [ [ 'True_Type' => '', 'first_timestamp' => false, 'Key' => 'PRI', 'Type' => 'char(36)', ], true, 'UUID', ], ]; } public function testGetMessage(): void { $GLOBALS['cfg']['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; $GLOBALS['dbi'] = DatabaseInterface::load(new DbiDummy()); $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;
Edit inline ] [ Edit ] [ Explain SQL ] [ Create PHP code ] [ Refresh ]
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 { $GLOBALS['cfg']['ShowSQL'] = true; $GLOBALS['cfg']['SQLQuery']['Edit'] = false; $GLOBALS['cfg']['SQLQuery']['Refresh'] = true; $GLOBALS['display_query'] = 'EXPLAIN SELECT 1;'; $GLOBALS['unparsed_sql'] = null; $GLOBALS['sql_query'] = null; $GLOBALS['dbi'] = DatabaseInterface::load(new DbiDummy()); $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'); } }