Start testcase for SQL parser.

This commit is contained in:
Michal Čihař
2010-08-30 15:53:00 +02:00
parent 388327d642
commit a6ba984504
2 changed files with 69 additions and 3 deletions

View File

@@ -43,7 +43,9 @@ if (! defined('PMA_MINIMUM_COMMON')) {
* Include data for the SQL Parser * Include data for the SQL Parser
*/ */
require_once './libraries/sqlparser.data.php'; require_once './libraries/sqlparser.data.php';
require_once './libraries/mysql_charsets.lib.php'; if (!defined('TESTSUITE')) {
require_once './libraries/mysql_charsets.lib.php';
}
if (!isset($mysql_charsets)) { if (!isset($mysql_charsets)) {
$mysql_charsets = array(); $mysql_charsets = array();
$mysql_charsets_count = 0; $mysql_charsets_count = 0;
@@ -2091,8 +2093,8 @@ if (! defined('PMA_MINIMUM_COMMON')) {
$docu = TRUE; $docu = TRUE;
break; break;
} // end switch } // end switch
// inner_sql is a span that exists for all cases // inner_sql is a span that exists for all cases
// of $cfg['SQP']['fmtType'] to make possible a replacement // of $cfg['SQP']['fmtType'] to make possible a replacement
// for inline editing // for inline editing
$str .= '<span class="inner_sql">'; $str .= '<span class="inner_sql">';
$close_docu_link = false; $close_docu_link = false;

View File

@@ -0,0 +1,64 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for correctness of SQL parser
*
* @package phpMyAdmin-test
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
define('PHPMYADMIN', 1);
define('TESTSUITE', 1);
$GLOBALS['charset'] = 'utf-8';
/**
* Include to test.
*/
require_once './libraries/sqlparser.lib.php';
/**
* Test for SQL parser
*
* @package phpMyAdmin-test
*/
class PMA_SQL_parser_test extends PHPUnit_Framework_TestCase
{
private function assertParser($sql, $expected)
{
$parsed_sql = PMA_SQP_parse($sql);
$this->assertEquals($parsed_sql, $expected);
}
public function testParse_1()
{
$this->assertParser('SELECT 1;', array (
'raw' => 'SELECT 1;',
0 =>
array (
'type' => 'alpha_reservedWord',
'data' => 'SELECT',
'pos' => 6,
'forbidden' => true,
),
1 =>
array (
'type' => 'digit_integer',
'data' => '1',
'pos' => 8,
),
2 =>
array (
'type' => 'punct_queryend',
'data' => ';',
'pos' => 0,
),
'len' => 3,
));
}
}
?>