2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Tests for correctness of SQL parser
6 * @package phpMyAdmin-test
12 require_once 'libraries/sqlparser.lib.php';
14 class PMA_SQL_parser_test
extends PHPUnit_Framework_TestCase
16 private function assertParser($sql, $expected, $error = '')
18 $parsed_sql = PMA_SQP_parse($sql);
19 $this->assertEquals(PMA_SQP_getErrorString(), $error);
20 $this->assertEquals($parsed_sql, $expected);
23 public function testParse_1()
25 $this->assertParser('SELECT 1;', array (
29 'type' => 'alpha_reservedWord',
36 'type' => 'digit_integer',
42 'type' => 'punct_queryend',
50 public function testParse_2()
52 $this->assertParser('SELECT * from aaa;', array (
53 'raw' => 'SELECT * from aaa;',
56 'type' => 'alpha_reservedWord',
69 'type' => 'alpha_reservedWord',
76 'type' => 'alpha_identifier',
83 'type' => 'punct_queryend',
91 public function testParse_3()
93 $this->assertParser('SELECT * from `aaa`;', array (
94 'raw' => 'SELECT * from `aaa`;',
97 'type' => 'alpha_reservedWord',
110 'type' => 'alpha_reservedWord',
117 'type' => 'quote_backtick',
123 'type' => 'punct_queryend',
131 public function testParse_4()
133 $GLOBALS['is_ajax_request'] = true;
134 $this->assertParser('SELECT * from `aaa;', array (
135 'raw' => 'SELECT * from `aaa`;',
138 'type' => 'alpha_reservedWord',
151 'type' => 'alpha_reservedWord',
158 'type' => 'quote_backtick',
164 'type' => 'punct_queryend',
172 public function testParse_5()
174 $this->assertParser('SELECT * FROM `a_table` tbla INNER JOIN b_table` tblb ON tblb.id = tbla.id WHERE tblb.field1 != tbla.field1`;', array (
175 'raw' => 'SELECT * FROM `a_table` tbla INNER JOIN b_table` tblb ON tblb.id = tbla.id WHERE tblb.field1 != tbla.field1`;',
178 'type' => 'alpha_reservedWord',
191 'type' => 'alpha_reservedWord',
198 'type' => 'quote_backtick',
199 'data' => '`a_table`',
204 'type' => 'alpha_identifier',
207 'forbidden' => false,
211 'type' => 'alpha_reservedWord',
218 'type' => 'alpha_reservedWord',
225 'type' => 'alpha_identifier',
228 'forbidden' => false,
232 'type' => 'quote_backtick',
233 'data' => '` tblb ON tblb.id = tbla.id WHERE tblb.field1 != tbla.field1`',
238 'type' => 'punct_queryend',