',
Generator::getIcon('b_comment'),
);
}
/**
* Test for Util::getIcon
*/
public function testGetIconAlternate(): void
{
Config::getInstance()->set('ActionLinksMode', 'icons');
$alternateText = 'alt_str';
self::assertSame(
'
',
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 . '',
Generator::getIcon('b_comment', $alternateText, true, false),
);
}
/**
* Test for showPHPDocumentation
*/
public function testShowPHPDocumentation(): void
{
$target = 'docu';
$lang = _pgettext('PHP documentation language', 'en');
$expected = ''
. '
';
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'
. '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'
. '
';
$sslNotUsedCaution = 'SSL is not being used'
. '
';
$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'
. '
',
Generator::getServerSSL(),
);
$config->selectedServer = ['ssl' => true, 'ssl_verify' => true, 'host' => 'custom.host'];
self::assertSame(
'SSL is used without certification authority'
. '
',
Generator::getServerSSL(),
);
$config->selectedServer = [
'ssl' => true,
'ssl_verify' => true,
'ssl_ca' => '/etc/ssl/ca.crt',
'host' => 'custom.host',
];
self::assertSame(
'SSL is used'
. '
',
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'
Bookmark message
Message one.
SELECT 1;
Message one.
$sql = "EXPLAIN SELECT 1;";