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);
24 require_once './libraries/sqlparser.lib.php';
29 * @package phpMyAdmin-test
31 class PMA_SQL_parser_test
extends PHPUnit_Framework_TestCase
33 private function assertParser($sql, $expected, $error = '')
35 $parsed_sql = PMA_SQP_parse($sql);
36 $this->assertEquals(PMA_SQP_getErrorString(), $error);
37 $this->assertEquals($parsed_sql, $expected);
40 public function testParse_1()
42 $this->assertParser('SELECT 1;', array (
46 'type' => 'alpha_reservedWord',
53 'type' => 'digit_integer',
59 'type' => 'punct_queryend',
67 public function testParse_2()
69 $this->assertParser('SELECT * from aaa;', array (
70 'raw' => 'SELECT * from aaa;',
73 'type' => 'alpha_reservedWord',
86 'type' => 'alpha_reservedWord',
93 'type' => 'alpha_identifier',
100 'type' => 'punct_queryend',
108 public function testParse_3()
110 $this->assertParser('SELECT * from `aaa`;', array (
111 'raw' => 'SELECT * from `aaa`;',
114 'type' => 'alpha_reservedWord',
127 'type' => 'alpha_reservedWord',
134 'type' => 'quote_backtick',
140 'type' => 'punct_queryend',
148 public function testParse_4()
150 $this->assertParser('SELECT * from `aaa;', array (
151 'raw' => 'SELECT * from `aaa`;',
154 'type' => 'alpha_reservedWord',
167 'type' => 'alpha_reservedWord',
174 'type' => 'quote_backtick',
180 'type' => 'punct_queryend',
188 public function testParse_5()
190 $this->assertParser('SELECT * FROM `a_table` tbla INNER JOIN b_table` tblb ON tblb.id = tbla.id WHERE tblb.field1 != tbla.field1`;', array (
191 'raw' => 'SELECT * FROM `a_table` tbla INNER JOIN b_table` tblb ON tblb.id = tbla.id WHERE tblb.field1 != tbla.field1`;',
194 'type' => 'alpha_reservedWord',
207 'type' => 'alpha_reservedWord',
214 'type' => 'quote_backtick',
215 'data' => '`a_table`',
220 'type' => 'alpha_identifier',
223 'forbidden' => false,
227 'type' => 'alpha_reservedWord',
234 'type' => 'alpha_reservedWord',
241 'type' => 'alpha_identifier',
244 'forbidden' => false,
248 'type' => 'quote_backtick',
249 'data' => '` tblb ON tblb.id = tbla.id WHERE tblb.field1 != tbla.field1`',
254 'type' => 'punct_queryend',