2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * tests for correctness of SQL parser
6 * @package phpMyAdmin-test
12 require_once 'PHPUnit/Framework.php';
14 define('PHPMYADMIN', 1);
15 define('TESTSUITE', 1);
16 $GLOBALS['charset'] = 'utf-8';
25 require_once './libraries/sqlparser.lib.php';
30 * @package phpMyAdmin-test
32 class PMA_SQL_parser_test
extends PHPUnit_Framework_TestCase
34 private function assertParser($sql, $expected, $error = '')
36 $parsed_sql = PMA_SQP_parse($sql);
37 $this->assertEquals(PMA_SQP_getErrorString(), $error);
38 $this->assertEquals($parsed_sql, $expected);
41 public function testParse_1()
43 $this->assertParser('SELECT 1;', array (
47 'type' => 'alpha_reservedWord',
54 'type' => 'digit_integer',
60 'type' => 'punct_queryend',
68 public function testParse_2()
70 $this->assertParser('SELECT * from aaa;', array (
71 'raw' => 'SELECT * from aaa;',
74 'type' => 'alpha_reservedWord',
87 'type' => 'alpha_reservedWord',
94 'type' => 'alpha_identifier',
101 'type' => 'punct_queryend',
109 public function testParse_3()
111 $this->assertParser('SELECT * from `aaa`;', array (
112 'raw' => 'SELECT * from `aaa`;',
115 'type' => 'alpha_reservedWord',
128 'type' => 'alpha_reservedWord',
135 'type' => 'quote_backtick',
141 'type' => 'punct_queryend',
149 public function testParse_4()
151 $this->assertParser('SELECT * from `aaa;', array (
152 'raw' => 'SELECT * from `aaa`;',
155 'type' => 'alpha_reservedWord',
168 'type' => 'alpha_reservedWord',
175 'type' => 'quote_backtick',
181 'type' => 'punct_queryend',
189 public function testParse_5()
191 $this->assertParser('SELECT * FROM `a_table` tbla INNER JOIN b_table` tblb ON tblb.id = tbla.id WHERE tblb.field1 != tbla.field1`;', array (
192 'raw' => 'SELECT * FROM `a_table` tbla INNER JOIN b_table` tblb ON tblb.id = tbla.id WHERE tblb.field1 != tbla.field1`;',
195 'type' => 'alpha_reservedWord',
208 'type' => 'alpha_reservedWord',
215 'type' => 'quote_backtick',
216 'data' => '`a_table`',
221 'type' => 'alpha_identifier',
224 'forbidden' => false,
228 'type' => 'alpha_reservedWord',
235 'type' => 'alpha_reservedWord',
242 'type' => 'alpha_identifier',
245 'forbidden' => false,
249 'type' => 'quote_backtick',
250 'data' => '` tblb ON tblb.id = tbla.id WHERE tblb.field1 != tbla.field1`',
255 'type' => 'punct_queryend',