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 { $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 function linksOrButtons(): array { parent::setGlobalConfig(); 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', ], [ [ Url::getFromRoute('/server/databases'), ['some' => 'parameter'], 'text', ], 20, 'text', ], [ [ Url::getFromRoute('/server/databases'), null, 'text', ], 20, 'text', ], [ [ Url::getFromRoute('/server/databases'), ['some' => 'parameter'], 'text', ], 100, 'text', ], [ [ Url::getFromRoute('/server/databases'), null, 'text', ], 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 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', ], ]; } }