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
path: root/test
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-07 04:14:14 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-07 04:14:14 +0300
commit262e3e8129b2b6ef4149f4b1b4939f7f30e9b646 (patch)
treeffb0fba727691131691b0ce65cb3f052b16a0950 /test
parentb20d7f3a0431aa0380a1b82971170db4bd514cb9 (diff)
Add some unit tests for the Util class
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'test')
-rw-r--r--test/classes/UtilTest.php106
1 files changed, 106 insertions, 0 deletions
diff --git a/test/classes/UtilTest.php b/test/classes/UtilTest.php
index 9d070fbd4c..6e5e315474 100644
--- a/test/classes/UtilTest.php
+++ b/test/classes/UtilTest.php
@@ -731,6 +731,11 @@ class UtilTest extends AbstractTestCase
];
}
+ public function testFormatByteDownWithNullValue(): void
+ {
+ $this->assertNull(Util::formatByteDown(null));
+ }
+
/**
* format byte test, globals are defined
*
@@ -2234,4 +2239,105 @@ class UtilTest extends AbstractTestCase
Util::getScriptNameForOption($target, $location)
);
}
+
+ public function testShowIcons(): void
+ {
+ $GLOBALS['cfg']['ActionLinksMode'] = 'icons';
+ $this->assertTrue(Util::showIcons('ActionLinksMode'));
+ $GLOBALS['cfg']['ActionLinksMode'] = 'both';
+ $this->assertTrue(Util::showIcons('ActionLinksMode'));
+ $GLOBALS['cfg']['ActionLinksMode'] = 'text';
+ $this->assertFalse(Util::showIcons('ActionLinksMode'));
+ }
+
+ public function testShowText(): void
+ {
+ $GLOBALS['cfg']['ActionLinksMode'] = 'text';
+ $this->assertTrue(Util::showText('ActionLinksMode'));
+ $GLOBALS['cfg']['ActionLinksMode'] = 'both';
+ $this->assertTrue(Util::showText('ActionLinksMode'));
+ $GLOBALS['cfg']['ActionLinksMode'] = 'icons';
+ $this->assertFalse(Util::showText('ActionLinksMode'));
+ }
+
+ /**
+ * @dataProvider providerForTestGetMySQLDocuURL
+ */
+ public function testGetMySQLDocuURL(string $link, string $anchor, int $version, string $expected): void
+ {
+ $GLOBALS['dbi'] = $this->createDatabaseInterface();
+ $GLOBALS['dbi']->setVersion($version);
+ $this->assertSame($expected, Util::getMySQLDocuURL($link, $anchor));
+ }
+
+ /**
+ * @return array<int, array<int, int|string>>
+ * @psalm-return array<int, array{string, string, int, string}>
+ */
+ public function providerForTestGetMySQLDocuURL(): array
+ {
+ return [
+ [
+ 'ALTER_TABLE',
+ 'alter-table-index',
+ 80000,
+ 'index.php?route=/url&url='
+ . 'https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F8.0%2Fen%2Falter-table.html%23alter-table-index',
+ ],
+ [
+ 'ALTER_TABLE',
+ 'alter-table-index',
+ 50700,
+ 'index.php?route=/url&url='
+ . 'https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen%2Falter-table.html%23alter-table-index',
+ ],
+ [
+ '',
+ 'alter-table-index',
+ 50600,
+ 'index.php?route=/url&url='
+ . 'https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.6%2Fen%2Findex.html%23alter-table-index',
+ ],
+ [
+ 'ALTER_TABLE',
+ '',
+ 50500,
+ 'index.php?route=/url&url='
+ . 'https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.5%2Fen%2Falter-table.html',
+ ],
+ [
+ '',
+ '',
+ 50700,
+ 'index.php?route=/url&url='
+ . 'https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen%2Findex.html',
+ ],
+ ];
+ }
+
+ public function testGetDocuURL(): void
+ {
+ $this->assertSame(
+ 'index.php?route=/url&url=https%3A%2F%2Fmariadb.com%2Fkb%2Fen%2Fdocumentation%2F',
+ Util::getDocuURL(true)
+ );
+ $this->assertSame(
+ 'index.php?route=/url&url=https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.5%2Fen%2Findex.html',
+ Util::getDocuURL(false)
+ );
+ $this->assertSame(
+ 'index.php?route=/url&url=https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.5%2Fen%2Findex.html',
+ Util::getDocuURL()
+ );
+ }
+
+ public function testSplitURLQuery(): void
+ {
+ $actual = Util::splitURLQuery('');
+ $this->assertSame([], $actual);
+ $actual = Util::splitURLQuery('index.php');
+ $this->assertSame([], $actual);
+ $actual = Util::splitURLQuery('index.php?route=/table/structure&db=sakila&table=address');
+ $this->assertSame(['route=/table/structure', 'db=sakila', 'table=address'], $actual);
+ }
}