Ignore SkipLockedTables (Drizzle)
[phpmyadmin.git] / test / PMA_SQL_parser_test.php
blobd384bd2c234c9d3750f0b96e85efc4fc4e7916e4
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * tests for correctness of SQL parser
6 * @package phpMyAdmin-test
7 */
9 /**
10 * Tests core.
12 require_once 'PHPUnit/Framework.php';
14 define('PHPMYADMIN', 1);
15 define('TESTSUITE', 1);
17 function __($s) {
18 return $s;
21 /**
22 * Include to test.
24 require_once './libraries/sqlparser.lib.php';
26 /**
27 * Test for SQL parser
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 (
43 'raw' => 'SELECT 1;',
44 0 =>
45 array (
46 'type' => 'alpha_reservedWord',
47 'data' => 'SELECT',
48 'pos' => 6,
49 'forbidden' => true,
51 1 =>
52 array (
53 'type' => 'digit_integer',
54 'data' => '1',
55 'pos' => 8,
57 2 =>
58 array (
59 'type' => 'punct_queryend',
60 'data' => ';',
61 'pos' => 0,
63 'len' => 3,
64 ));
67 public function testParse_2()
69 $this->assertParser('SELECT * from aaa;', array (
70 'raw' => 'SELECT * from aaa;',
71 0 =>
72 array (
73 'type' => 'alpha_reservedWord',
74 'data' => 'SELECT',
75 'pos' => 6,
76 'forbidden' => true,
78 1 =>
79 array (
80 'type' => 'punct',
81 'data' => '*',
82 'pos' => 0,
84 2 =>
85 array (
86 'type' => 'alpha_reservedWord',
87 'data' => 'from',
88 'pos' => 13,
89 'forbidden' => true,
91 3 =>
92 array (
93 'type' => 'alpha_identifier',
94 'data' => 'aaa',
95 'pos' => 17,
96 'forbidden' => false,
98 4 =>
99 array (
100 'type' => 'punct_queryend',
101 'data' => ';',
102 'pos' => 0,
104 'len' => 5,
108 public function testParse_3()
110 $this->assertParser('SELECT * from `aaa`;', array (
111 'raw' => 'SELECT * from `aaa`;',
112 0 =>
113 array (
114 'type' => 'alpha_reservedWord',
115 'data' => 'SELECT',
116 'pos' => 6,
117 'forbidden' => true,
119 1 =>
120 array (
121 'type' => 'punct',
122 'data' => '*',
123 'pos' => 0,
125 2 =>
126 array (
127 'type' => 'alpha_reservedWord',
128 'data' => 'from',
129 'pos' => 13,
130 'forbidden' => true,
132 3 =>
133 array (
134 'type' => 'quote_backtick',
135 'data' => '`aaa`',
136 'pos' => 0,
138 4 =>
139 array (
140 'type' => 'punct_queryend',
141 'data' => ';',
142 'pos' => 0,
144 'len' => 5,
148 public function testParse_4()
150 $this->assertParser('SELECT * from `aaa;', array (
151 'raw' => 'SELECT * from `aaa`;',
152 0 =>
153 array (
154 'type' => 'alpha_reservedWord',
155 'data' => 'SELECT',
156 'pos' => 6,
157 'forbidden' => true,
159 1 =>
160 array (
161 'type' => 'punct',
162 'data' => '*',
163 'pos' => 0,
165 2 =>
166 array (
167 'type' => 'alpha_reservedWord',
168 'data' => 'from',
169 'pos' => 13,
170 'forbidden' => true,
172 3 =>
173 array (
174 'type' => 'quote_backtick',
175 'data' => '`aaa`',
176 'pos' => 0,
178 4 =>
179 array (
180 'type' => 'punct_queryend',
181 'data' => ';',
182 'pos' => 0,
184 'len' => 5,
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`;',
192 0 =>
193 array (
194 'type' => 'alpha_reservedWord',
195 'data' => 'SELECT',
196 'pos' => 6,
197 'forbidden' => true,
199 1 =>
200 array (
201 'type' => 'punct',
202 'data' => '*',
203 'pos' => 0,
205 2 =>
206 array (
207 'type' => 'alpha_reservedWord',
208 'data' => 'FROM',
209 'pos' => 13,
210 'forbidden' => true,
212 3 =>
213 array (
214 'type' => 'quote_backtick',
215 'data' => '`a_table`',
216 'pos' => 0,
218 4 =>
219 array (
220 'type' => 'alpha_identifier',
221 'data' => 'tbla',
222 'pos' => 28,
223 'forbidden' => false,
225 5 =>
226 array (
227 'type' => 'alpha_reservedWord',
228 'data' => 'INNER',
229 'pos' => 34,
230 'forbidden' => true,
232 6 =>
233 array (
234 'type' => 'alpha_reservedWord',
235 'data' => 'JOIN',
236 'pos' => 39,
237 'forbidden' => true,
239 7 =>
240 array (
241 'type' => 'alpha_identifier',
242 'data' => 'b_table',
243 'pos' => 47,
244 'forbidden' => false,
246 8 =>
247 array (
248 'type' => 'quote_backtick',
249 'data' => '` tblb ON tblb.id = tbla.id WHERE tblb.field1 != tbla.field1`',
250 'pos' => 0,
252 9 =>
253 array (
254 'type' => 'punct_queryend',
255 'data' => ';',
256 'pos' => 0,
258 'len' => 10,