summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2017-12-06 10:42:41 +0100
committerMichal Čihař <michal@cihar.com>2017-12-06 10:45:16 +0100
commit9b56a083c53fd17d06d542ec21aac9a31093d3dc (patch)
tree89d1a2a4b0096ae1d598ff2ccbad83f058df91f4 /tests
parent849bbf56a99cf14b5b486339211a848527c78f89 (diff)
downloadsql-parser-9b56a083c53fd17d06d542ec21aac9a31093d3dc.zip
sql-parser-9b56a083c53fd17d06d542ec21aac9a31093d3dc.tar.gz
sql-parser-9b56a083c53fd17d06d542ec21aac9a31093d3dc.tar.bz2
Improve SQL context loading
- add fallback in case there is no version match - do not zero one by one, byt by two to match version parts - better handle corner cases Fixes https://github.com/phpmyadmin/phpmyadmin/issues/13728 Signed-off-by: Michal Čihař <michal@cihar.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Lexer/ContextTest.php40
1 files changed, 30 insertions, 10 deletions
diff --git a/tests/Lexer/ContextTest.php b/tests/Lexer/ContextTest.php
index 3a3546b..913406d 100644
--- a/tests/Lexer/ContextTest.php
+++ b/tests/Lexer/ContextTest.php
@@ -14,16 +14,6 @@ class ContextTest extends TestCase
$this->assertTrue(isset(Context::$KEYWORDS['STORED']));
$this->assertFalse(isset(Context::$KEYWORDS['AUTHORS']));
- Context::load('MySql50600');
- $this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50600', Context::$loadedContext);
- $this->assertFalse(isset(Context::$KEYWORDS['STORED']));
- $this->assertTrue(isset(Context::$KEYWORDS['AUTHORS']));
-
- Context::loadClosest('MySql50712');
- $this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700', Context::$loadedContext);
-
- $this->assertEquals(null, Context::loadClosest('Sql'));
-
// Restoring context.
Context::load('');
$this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\ContextMySql50700', Context::$defaultContext);
@@ -32,6 +22,36 @@ class ContextTest extends TestCase
}
/**
+ * Test for loading closest SQL context
+ *
+ * @dataProvider contextLoading
+ */
+ public function testLoadClosest($context, $expected)
+ {
+ $this->assertEquals($expected, Context::loadClosest($context));
+ if (! is_null($expected)) {
+ $this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\Context' . $expected, Context::$loadedContext);
+ $this->assertTrue(class_exists(Context::$loadedContext));
+ }
+
+ // Restoring context.
+ Context::load('');
+ }
+
+ public function contextLoading()
+ {
+ return [
+ 'MySQL match' => ['MySql50500', 'MySql50500'],
+ 'MySQL strip' => ['MySql50712', 'MySql50700'],
+ 'MySQL fallback' => ['MySql99999', 'MySql50700'],
+ 'MariaDB match' => ['MariaDb100000', 'MariaDb100000'],
+ 'MariaDB strip' => ['MariaDb109900', 'MariaDb100000'],
+ 'MariaDB fallback' => ['MariaDb990000', 'MariaDb100300'],
+ 'Invalid' => ['Sql', null],
+ ];
+ }
+
+ /**
* @dataProvider contextNames
*
* @param mixed $context