|
5 | 5 | use PhpMyAdmin\SqlParser\Components\Expression; |
6 | 6 | use PhpMyAdmin\SqlParser\Components\Key; |
7 | 7 | use PhpMyAdmin\SqlParser\Components\OptionsArray; |
| 8 | +use PhpMyAdmin\SqlParser\Exceptions\ParserException; |
8 | 9 | use PhpMyAdmin\SqlParser\Parser; |
9 | 10 | use PhpMyAdmin\SqlParser\Tests\TestCase; |
| 11 | +use PhpMyAdmin\SqlParser\Token; |
10 | 12 |
|
11 | 13 | class KeyTest extends TestCase |
12 | 14 | { |
@@ -192,4 +194,123 @@ public function testParseKeyExpressionWithOptions() |
192 | 194 | ); |
193 | 195 | $this->assertSame(array(), $component->columns); |
194 | 196 | } |
| 197 | + |
| 198 | + public function testParseKeyExpressionWithOptionsError() |
| 199 | + { |
| 200 | + $parser = new Parser(); |
| 201 | + $component = Key::parse( |
| 202 | + $parser, |
| 203 | + $this->getTokensList( |
| 204 | + 'KEY `updated_tz_ind2` (()convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\'))) COMMENT \'my comment\',' |
| 205 | + ) |
| 206 | + ); |
| 207 | + $this->assertEquals('KEY', $component->type); |
| 208 | + $this->assertEquals('updated_tz_ind2', $component->name); |
| 209 | + $this->assertEquals(new OptionsArray( |
| 210 | + array( |
| 211 | + ) |
| 212 | + ), $component->options); |
| 213 | + $t = new Token( |
| 214 | + 'convert_tz', |
| 215 | + Token::TYPE_KEYWORD, |
| 216 | + 33 |
| 217 | + ); |
| 218 | + $t->position = 25; |
| 219 | + |
| 220 | + $this->assertEquals(array( |
| 221 | + new ParserException( |
| 222 | + 'Unexpected token.', |
| 223 | + $t |
| 224 | + ) |
| 225 | + ), $parser->errors); |
| 226 | + $expr = new Expression( |
| 227 | + '(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\'))' |
| 228 | + ); |
| 229 | + $expr->function = 'convert_tz'; |
| 230 | + $this->assertEquals( |
| 231 | + '()(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')', |
| 232 | + $component->expr |
| 233 | + ); |
| 234 | + $this->assertSame(array(), $component->columns); |
| 235 | + } |
| 236 | + |
| 237 | + public function testParseKeyOneExpressionWithOptions() |
| 238 | + { |
| 239 | + $parser = new Parser(); |
| 240 | + $component = Key::parse( |
| 241 | + $parser, |
| 242 | + $this->getTokensList( |
| 243 | + 'KEY `updated_tz_ind2`' |
| 244 | + . ' (' |
| 245 | + . '(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')), ' |
| 246 | + . '(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'FR\'))' |
| 247 | + . ')' |
| 248 | + . ' COMMENT \'my comment\',' |
| 249 | + ) |
| 250 | + ); |
| 251 | + $this->assertEquals('KEY', $component->type); |
| 252 | + $this->assertEquals('updated_tz_ind2', $component->name); |
| 253 | + $this->assertEquals(new OptionsArray( |
| 254 | + array( |
| 255 | + 4 => array( |
| 256 | + 'name' => 'COMMENT', |
| 257 | + 'equals' => false, |
| 258 | + 'expr' => '\'my comment\'', |
| 259 | + 'value' => 'my comment', |
| 260 | + ) |
| 261 | + ) |
| 262 | + ), $component->options); |
| 263 | + $this->assertSame(array(), $parser->errors); |
| 264 | + $expr = new Expression( |
| 265 | + '(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')),' |
| 266 | + . ' (convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'FR\'))' |
| 267 | + ); |
| 268 | + $expr->function = 'convert_tz'; |
| 269 | + $this->assertEquals( |
| 270 | + $expr, |
| 271 | + $component->expr |
| 272 | + ); |
| 273 | + $this->assertSame(array(), $component->columns); |
| 274 | + } |
| 275 | + |
| 276 | + public function testParseKeyMultipleExpressionsWithOptions() |
| 277 | + { |
| 278 | + $parser = new Parser(); |
| 279 | + $component = Key::parse( |
| 280 | + $parser, |
| 281 | + $this->getTokensList( |
| 282 | + 'KEY `updated_tz_ind2`' |
| 283 | + . ' (' |
| 284 | + . '(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')), ' |
| 285 | + . '(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'FR\')), ' |
| 286 | + . '(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'RU\'))' |
| 287 | + . ')' |
| 288 | + . ' COMMENT \'my comment\',' |
| 289 | + ) |
| 290 | + ); |
| 291 | + $this->assertEquals('KEY', $component->type); |
| 292 | + $this->assertEquals('updated_tz_ind2', $component->name); |
| 293 | + $this->assertEquals(new OptionsArray( |
| 294 | + array( |
| 295 | + 4 => array( |
| 296 | + 'name' => 'COMMENT', |
| 297 | + 'equals' => false, |
| 298 | + 'expr' => '\'my comment\'', |
| 299 | + 'value' => 'my comment', |
| 300 | + ) |
| 301 | + ) |
| 302 | + ), $component->options); |
| 303 | + $expr = new Expression( |
| 304 | + '(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')),' |
| 305 | + . ' (convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'FR\')),' |
| 306 | + . ' (convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'RU\'))' |
| 307 | + ); |
| 308 | + $expr->function = 'convert_tz'; |
| 309 | + $this->assertEquals( |
| 310 | + $expr, |
| 311 | + $component->expr |
| 312 | + ); |
| 313 | + $this->assertSame(array(), $component->columns); |
| 314 | + $this->assertSame(array(), $parser->errors); |
| 315 | + } |
195 | 316 | } |
0 commit comments