phpmyadmin/test/classes/CharsetsTest.php
Dmitrii Kustov 4bdf519588
Improve collations support for MariaDB 10.10+ (#18760)
* Added new charset queries

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Improve collations support for MariaDB 10.10+

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Using dbi to check for MariaDB

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Removed unnecessary query

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Cleanup

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Whitespaces

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Whitespaces

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Switched to getVersion()

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Removed use of version_compare

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Test for MariaDB 10.10+

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Update test/classes/CharsetsTest.php

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>

Fixes https://github.com/phpmyadmin/phpmyadmin/issues/18769

---------

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Co-authored-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
(cherry picked from commit ef92f1f484)
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2023-10-31 15:28:20 -03:00

102 lines
3.0 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\Charsets;
/**
* @covers \PhpMyAdmin\Charsets
*/
class CharsetsTest extends AbstractTestCase
{
protected function setUp(): void
{
parent::setUp();
parent::setGlobalDbi();
$GLOBALS['server'] = 0;
$GLOBALS['cfg']['DBG']['sql'] = false;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
}
public function testGetServerCharset(): void
{
$this->dummyDbi->addResult(
'SHOW SESSION VARIABLES LIKE \'character_set_server\';',
[
[
'character_set_server',
'utf8mb3',
],
],
[
'Variable_name',
'Value',
]
);
$this->dummyDbi->addResult('SHOW SESSION VARIABLES LIKE \'character_set_server\';', false);
$this->dummyDbi->addResult('SELECT @@character_set_server;', false);
$this->dummyDbi->addResult('SHOW SESSION VARIABLES LIKE \'character_set_server\';', false);
$this->dummyDbi->addResult(
'SELECT @@character_set_server;',
[
['utf8mb3'],
]
);
$charset = Charsets::getServerCharset($GLOBALS['dbi'], $GLOBALS['cfg']['Server']['DisableIS']);
$this->assertSame('utf8', $charset->getName());
$charset = Charsets::getServerCharset($GLOBALS['dbi'], $GLOBALS['cfg']['Server']['DisableIS']);
$this->assertSame('Unknown', $charset->getName());
$charset = Charsets::getServerCharset($GLOBALS['dbi'], $GLOBALS['cfg']['Server']['DisableIS']);
$this->assertSame('utf8', $charset->getName());
$this->assertAllQueriesConsumed();
}
public function testFindCollationByName(): void
{
$this->assertNull(Charsets::findCollationByName(
$GLOBALS['dbi'],
$GLOBALS['cfg']['Server']['DisableIS'],
null
));
$this->assertNull(Charsets::findCollationByName(
$GLOBALS['dbi'],
$GLOBALS['cfg']['Server']['DisableIS'],
''
));
$this->assertNull(Charsets::findCollationByName(
$GLOBALS['dbi'],
$GLOBALS['cfg']['Server']['DisableIS'],
'invalid'
));
$actual = Charsets::findCollationByName(
$GLOBALS['dbi'],
$GLOBALS['cfg']['Server']['DisableIS'],
'utf8_general_ci'
);
$this->assertInstanceOf(Charsets\Collation::class, $actual);
$this->assertSame('utf8_general_ci', $actual->getName());
}
public function testGetCollationsMariaDB(): void
{
$this->dbi->setVersion(['@@version' => '10.10.0-MariaDB']);
$collations = Charsets::getCollations($this->dbi, false);
$this->assertCount(4, $collations);
$this->assertContainsOnly('array', $collations);
foreach ($collations as $collation) {
$this->assertContainsOnlyInstancesOf(Charsets\Collation::class, $collation);
}
}
}