diff options
Diffstat (limited to 'tests/utils/QueryTest.php')
-rw-r--r-- | tests/utils/QueryTest.php | 96 |
1 files changed, 75 insertions, 21 deletions
diff --git a/tests/utils/QueryTest.php b/tests/utils/QueryTest.php index b933649..82a8a84 100644 --- a/tests/utils/QueryTest.php +++ b/tests/utils/QueryTest.php @@ -27,65 +27,92 @@ class QueryTest extends TestCase return array( array( 'ALTER TABLE DROP col', - array('reload' => true) + array( + 'reload' => true, + 'querytype' => 'ALTER' + ) ), array( 'CALL test()', - array('is_procedure' => true) + array( + 'is_procedure' => true, + 'querytype' => 'CALL' + ) ), array( 'CREATE TABLE tbl (id INT)', - array('reload' => true) + array( + 'reload' => true, + 'querytype' => 'CREATE' + ) ), array( 'CHECK TABLE tbl', - array('is_maint' => true) + array( + 'is_maint' => true, + 'querytype' => 'CHECK' + ) ), array( 'DELETE FROM tbl', array( 'is_affected' => true, - 'is_delete' => true + 'is_delete' => true, + 'querytype' => 'DELETE', ), ), array( 'DROP VIEW v', - array('reload' => true) + array( + 'reload' => true, + 'querytype' => 'DROP' + ) ), array( 'DROP DATABASE db', array( 'drop_database' => true, - 'reload' => true + 'reload' => true, + 'querytype' => 'DROP' ) ), array( 'EXPLAIN tbl', - array('is_explain' => true), + array( + 'is_explain' => true, + 'querytype' => 'EXPLAIN' + ), ), array( 'INSERT INTO tbl VALUES (1)', array( 'is_affected' => true, - 'is_insert' => true + 'is_insert' => true, + 'querytype' => 'INSERT' ) ), array( 'REPLACE INTO tbl VALUES (2)', array( 'is_affected' => true, - 'is_replace' => true + 'is_replace' => true, + 'is_insert' => true, + 'querytype' => 'REPLACE' ) ), array( 'SELECT 1', - array('is_select' => true) + array( + 'is_select' => true, + 'querytype' => 'SELECT' + ) ), array( 'SELECT * FROM tbl', array( 'is_select' => true, - 'select_from' => true + 'select_from' => true, + 'querytype' => 'SELECT' ) ), array( @@ -93,7 +120,8 @@ class QueryTest extends TestCase array( 'distinct' => true, 'is_select' => true, - 'select_from' => true + 'select_from' => true, + 'querytype' => 'SELECT' ) ), array( @@ -101,7 +129,9 @@ class QueryTest extends TestCase array( 'is_group' => true, 'is_select' => true, - 'select_from' => true + 'select_from' => true, + 'group' => true, + 'querytype' => 'SELECT' ) ), array( @@ -109,7 +139,8 @@ class QueryTest extends TestCase array( 'is_analyse' => true, 'is_select' => true, - 'select_from' => true + 'select_from' => true, + 'querytype' => 'SELECT' ) ), array( @@ -117,7 +148,8 @@ class QueryTest extends TestCase array( 'is_export' => true, 'is_select' => true, - 'select_from' => true + 'select_from' => true, + 'querytype' => 'SELECT' ) ), array( @@ -126,23 +158,31 @@ class QueryTest extends TestCase 'is_count' => true, 'is_func' => true, 'is_select' => true, - 'select_from' => true + 'select_from' => true, + 'querytype' => 'SELECT' ) ), array( 'SELECT (SELECT "foo")', array( 'is_select' => true, - 'is_subquery' => true + 'is_subquery' => true, + 'querytype' => 'SELECT' ) ), array( 'SHOW CREATE TABLE tbl', - array('is_show' => true) + array( + 'is_show' => true, + 'querytype' => 'SHOW' + ) ), array( 'UPDATE tbl SET id = 1', - array('is_affected' => true) + array( + 'is_affected' => true, + 'querytype' => 'UPDATE' + ) ) ); } @@ -158,7 +198,8 @@ class QueryTest extends TestCase array( 'parser' => $parser, 'statement' => $parser->statements[0], - 'tables' => array( + 'select_expr' => array('*'), + 'select_tables' => array( array('actor', null), array('film', 'sakila2') ) @@ -173,4 +214,17 @@ class QueryTest extends TestCase $this->assertEquals(array(), Query::getAll('')); } + public function testReplaceClause() + { + $parser = new Parser('SELECT *, (SELECT 1) FROM film LIMIT 0, 10'); + $this->assertEquals( + 'SELECT *, (SELECT 1) FROM film WHERE film_id > 0 LIMIT 0, 10', + Query::replaceClause( + $parser->statements[0], + $parser->list, + 'WHERE film_id > 0' + ) + ); + } + } |