Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / test / libraries / PMA_SQL_parser_test.php
blob155f439c11d989c244e92d555fa837719e45b72b
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 * Include to 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 (
26 'raw' => 'SELECT 1;',
27 0 =>
28 array (
29 'type' => 'alpha_reservedWord',
30 'data' => 'SELECT',
31 'pos' => 6,
32 'forbidden' => true,
34 1 =>
35 array (
36 'type' => 'digit_integer',
37 'data' => '1',
38 'pos' => 8,
40 2 =>
41 array (
42 'type' => 'punct_queryend',
43 'data' => ';',
44 'pos' => 0,
46 'len' => 3,
47 ));
50 public function testParse_2()
52 $this->assertParser('SELECT * from aaa;', array (
53 'raw' => 'SELECT * from aaa;',
54 0 =>
55 array (
56 'type' => 'alpha_reservedWord',
57 'data' => 'SELECT',
58 'pos' => 6,
59 'forbidden' => true,
61 1 =>
62 array (
63 'type' => 'punct',
64 'data' => '*',
65 'pos' => 0,
67 2 =>
68 array (
69 'type' => 'alpha_reservedWord',
70 'data' => 'from',
71 'pos' => 13,
72 'forbidden' => true,
74 3 =>
75 array (
76 'type' => 'alpha_identifier',
77 'data' => 'aaa',
78 'pos' => 17,
79 'forbidden' => false,
81 4 =>
82 array (
83 'type' => 'punct_queryend',
84 'data' => ';',
85 'pos' => 0,
87 'len' => 5,
88 ));
91 public function testParse_3()
93 $this->assertParser('SELECT * from `aaa`;', array (
94 'raw' => 'SELECT * from `aaa`;',
95 0 =>
96 array (
97 'type' => 'alpha_reservedWord',
98 'data' => 'SELECT',
99 'pos' => 6,
100 'forbidden' => true,
102 1 =>
103 array (
104 'type' => 'punct',
105 'data' => '*',
106 'pos' => 0,
108 2 =>
109 array (
110 'type' => 'alpha_reservedWord',
111 'data' => 'from',
112 'pos' => 13,
113 'forbidden' => true,
115 3 =>
116 array (
117 'type' => 'quote_backtick',
118 'data' => '`aaa`',
119 'pos' => 0,
121 4 =>
122 array (
123 'type' => 'punct_queryend',
124 'data' => ';',
125 'pos' => 0,
127 'len' => 5,
131 public function testParse_4()
133 $GLOBALS['is_ajax_request'] = true;
134 $this->assertParser('SELECT * from `aaa;', array (
135 'raw' => 'SELECT * from `aaa`;',
136 0 =>
137 array (
138 'type' => 'alpha_reservedWord',
139 'data' => 'SELECT',
140 'pos' => 6,
141 'forbidden' => true,
143 1 =>
144 array (
145 'type' => 'punct',
146 'data' => '*',
147 'pos' => 0,
149 2 =>
150 array (
151 'type' => 'alpha_reservedWord',
152 'data' => 'from',
153 'pos' => 13,
154 'forbidden' => true,
156 3 =>
157 array (
158 'type' => 'quote_backtick',
159 'data' => '`aaa`',
160 'pos' => 0,
162 4 =>
163 array (
164 'type' => 'punct_queryend',
165 'data' => ';',
166 'pos' => 0,
168 'len' => 5,
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`;',
176 0 =>
177 array (
178 'type' => 'alpha_reservedWord',
179 'data' => 'SELECT',
180 'pos' => 6,
181 'forbidden' => true,
183 1 =>
184 array (
185 'type' => 'punct',
186 'data' => '*',
187 'pos' => 0,
189 2 =>
190 array (
191 'type' => 'alpha_reservedWord',
192 'data' => 'FROM',
193 'pos' => 13,
194 'forbidden' => true,
196 3 =>
197 array (
198 'type' => 'quote_backtick',
199 'data' => '`a_table`',
200 'pos' => 0,
202 4 =>
203 array (
204 'type' => 'alpha_identifier',
205 'data' => 'tbla',
206 'pos' => 28,
207 'forbidden' => false,
209 5 =>
210 array (
211 'type' => 'alpha_reservedWord',
212 'data' => 'INNER',
213 'pos' => 34,
214 'forbidden' => true,
216 6 =>
217 array (
218 'type' => 'alpha_reservedWord',
219 'data' => 'JOIN',
220 'pos' => 39,
221 'forbidden' => true,
223 7 =>
224 array (
225 'type' => 'alpha_identifier',
226 'data' => 'b_table',
227 'pos' => 47,
228 'forbidden' => false,
230 8 =>
231 array (
232 'type' => 'quote_backtick',
233 'data' => '` tblb ON tblb.id = tbla.id WHERE tblb.field1 != tbla.field1`',
234 'pos' => 0,
236 9 =>
237 array (
238 'type' => 'punct_queryend',
239 'data' => ';',
240 'pos' => 0,
242 'len' => 10,