Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add test case for parse_analyze.inc.php #534

Merged
merged 2 commits into from

2 participants

@adamgsoc2013

No description provided.

@nijel nijel merged commit 664d560 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
13 libraries/sqlparser.lib.php
@@ -3041,5 +3041,18 @@ function PMA_SQP_getParserDataMap()
'PMA_SQPdata_column_type' => $PMA_SQPdata_column_type,
);
}
+/**
+ * Get Parser analyze Map from parse_analyze_inc.php
+ *
+ * @param array $sql_query The SQL string
+ * @param array $db Current DB
+ *
+ * @return Array analyze Map from parse_analyze_inc.php
+ */
+function PMA_SQP_getParserAnalyzeMap($sql_query, $db)
+{
+ include 'libraries/parse_analyze.inc.php';
+ return $analyzed_sql_results;
+}
?>
View
67 test/libraries/PMA_SQL_parse_analyze_test.php
@@ -0,0 +1,67 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * tests for correctness of SQL parser analyze data
+ *
+ * @package PhpMyAdmin-test
+ */
+
+/*
+ * Include to test.
+ */
+require_once 'libraries/Util.class.php';
+require_once 'libraries/sqlparser.lib.php';
+
+class PMA_SQLParserAnalyze_Test extends PHPUnit_Framework_TestCase
+{
+ public function testPMA_SQP_getParserAnalyzeMa()
+ {
+ //select statement
+ $sql_query = "select * from PMA.PMAParse";
+ $db = "PMA";
+ $data = PMA_SQP_getParserAnalyzeMap($sql_query, $db);
+
+ $this->assertEquals(
+ array(
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'select',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ $data['parsed_sql'][0]
+ );
+ $this->assertEquals(
+ 'select * from PMA.PMAParse',
+ $data['analyzed_sql'][0]['unsorted_query']
+ );
+
+ $this->assertTrue($data['is_select']);
+ $this->assertFalse($data['is_group']);
+ $this->assertFalse($data['is_show']);
+
+ //update statement
+ $sql_query = "UPDATE `11`.`pma_bookmark` SET `id` = '2' WHERE `pma_bookmark`.`id` = 1;";
+ $db = "PMA";
+ $data = PMA_SQP_getParserAnalyzeMap($sql_query, $db);
+
+ $this->assertEquals(
+ array(
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'UPDATE',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ $data['parsed_sql'][0]
+ );
+ $this->assertEquals(
+ $sql_query,
+ $data['analyzed_sql'][0]['unsorted_query']
+ );
+ $this->assertFalse($data['is_group']);
+ $this->assertFalse($data['is_show']);
+ $this->assertTrue($data['is_affected']);
+ $this->assertFalse($data['is_select']);
+ }
+}
+
+?>
Something went wrong with that request. Please try again.