Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Desportes <williamdes@wdes.fr>2020-11-10 10:42:36 +0300
committerWilliam Desportes <williamdes@wdes.fr>2020-11-10 14:12:56 +0300
commitd860597375406a99fd5d0fd83103815e231284f9 (patch)
tree72a92ca4b22b2bc2ad722aaef39177898829ee9d /test/classes/Controllers/Server
parent6961d176595111cd01dffb523c4da452d82249c4 (diff)
#16418 - Make MariaDBMySQLKBS optional
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'test/classes/Controllers/Server')
-rw-r--r--test/classes/Controllers/Server/VariablesControllerTest.php95
1 files changed, 89 insertions, 6 deletions
diff --git a/test/classes/Controllers/Server/VariablesControllerTest.php b/test/classes/Controllers/Server/VariablesControllerTest.php
index 8457853eac..d6ea504a5f 100644
--- a/test/classes/Controllers/Server/VariablesControllerTest.php
+++ b/test/classes/Controllers/Server/VariablesControllerTest.php
@@ -7,12 +7,13 @@ namespace PhpMyAdmin\Tests\Controllers\Server;
use PhpMyAdmin\Controllers\Server\VariablesController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
+use PhpMyAdmin\Providers\ServerVariables\ServerVariablesProvider;
+use PhpMyAdmin\Providers\ServerVariables\VoidProvider as ServerVariablesVoidProvider;
use PhpMyAdmin\Response;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\Response as ResponseStub;
-use Williamdes\MariaDBMySQLKBS\Search as KBSearch;
-use Williamdes\MariaDBMySQLKBS\SlimData as KBSlimData;
+use ReflectionProperty;
use function htmlspecialchars;
use function str_replace;
@@ -135,22 +136,104 @@ class VariablesControllerTest extends AbstractTestCase
$nameForValueByte = 'byte_variable';
$nameForValueNotByte = 'not_a_byte_variable';
- $slimData = new KBSlimData();
- $slimData->addVariable($nameForValueByte, 'byte', null);
- $slimData->addVariable($nameForValueNotByte, 'string', null);
- KBSearch::loadTestData($slimData);
+ //name is_numeric and the value type is byte
+ $args = [
+ $nameForValueByte,
+ '3',
+ ];
+ $voidProviderMock = $this->getMockBuilder(ServerVariablesVoidProvider::class)->getMock();
+
+ $voidProviderMock
+ ->expects($this->exactly(2))
+ ->method('getVariableType')
+ ->willReturnOnConsecutiveCalls(
+ 'byte',
+ 'string'
+ );
+
+ $response = new ReflectionProperty(ServerVariablesProvider::class, 'instance');
+ $response->setAccessible(true);
+ $response->setValue($voidProviderMock);
+
+ [$formattedValue, $isHtmlFormatted] = $this->callFunction(
+ $controller,
+ VariablesController::class,
+ 'formatVariable',
+ $args
+ );
+
+ $this->assertEquals(
+ '<abbr title="3">3 B</abbr>',
+ $formattedValue
+ );
+ $this->assertTrue($isHtmlFormatted);
+
+ //name is_numeric and the value type is not byte
+ $args = [
+ $nameForValueNotByte,
+ '3',
+ ];
+ [$formattedValue, $isHtmlFormatted] = $this->callFunction(
+ $controller,
+ VariablesController::class,
+ 'formatVariable',
+ $args
+ );
+ $this->assertEquals(
+ '3',
+ $formattedValue
+ );
+ $this->assertFalse($isHtmlFormatted);
+
+ //value is not a number
+ $args = [
+ $nameForValueNotByte,
+ 'value',
+ ];
+ [$formattedValue, $isHtmlFormatted] = $this->callFunction(
+ $controller,
+ VariablesController::class,
+ 'formatVariable',
+ $args
+ );
+ $this->assertEquals(
+ 'value',
+ $formattedValue
+ );
+ $this->assertFalse($isHtmlFormatted);
+ }
+
+ /**
+ * Test for formatVariable()
+ */
+ public function testFormatVariableMariaDbMySqlKbs(): void
+ {
+ if (! ServerVariablesProvider::mariaDbMySqlKbsExists()) {
+ $this->markTestSkipped('MariaDbMySqlKbs is missing');
+ }
+
+ $response = new ReflectionProperty(ServerVariablesProvider::class, 'instance');
+ $response->setAccessible(true);
+ $response->setValue(null);
+
+ $controller = new VariablesController(Response::getInstance(), new Template(), $GLOBALS['dbi']);
+
+ $nameForValueByte = 'wsrep_replicated_bytes';
+ $nameForValueNotByte = 'wsrep_thread_count';
//name is_numeric and the value type is byte
$args = [
$nameForValueByte,
'3',
];
+
[$formattedValue, $isHtmlFormatted] = $this->callFunction(
$controller,
VariablesController::class,
'formatVariable',
$args
);
+
$this->assertEquals(
'<abbr title="3">3 B</abbr>',
$formattedValue