From f357c5194c6e80fc0ed294270afacaae666fca63 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 24 Jul 2017 19:49:17 -0700 Subject: [PATCH] rdbms: Increase coverage for Database::selectSQLText() * Add case for `$tables[0] == ' '`. * Add case for `$tables == ''`. * Add case for 'DISTINCT' option. * Add case for 'FOR UPDATE' option. * Add case for 'LOCK IN SHARE MODE' option. * Add case for 'EXPLAIN' option. Change-Id: I4a5f4754bc30d31ec35a085f39321fd358b6aa49 --- .../libs/rdbms/database/DatabaseSQLTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/phpunit/includes/libs/rdbms/database/DatabaseSQLTest.php b/tests/phpunit/includes/libs/rdbms/database/DatabaseSQLTest.php index 7e9494c6c4..f519772c76 100644 --- a/tests/phpunit/includes/libs/rdbms/database/DatabaseSQLTest.php +++ b/tests/phpunit/includes/libs/rdbms/database/DatabaseSQLTest.php @@ -59,6 +59,23 @@ class DatabaseSQLTest extends PHPUnit_Framework_TestCase { "FROM table " . "WHERE alias = 'text'" ], + [ + [ + // 'tables' with space prepended indicates pre-escaped table name + 'tables' => ' table LEFT JOIN table2', + 'fields' => [ 'field' ], + 'conds' => [ 'field' => 'text' ], + ], + "SELECT field FROM table LEFT JOIN table2 WHERE field = 'text'" + ], + [ + [ + // Empty 'tables' is allowed + 'tables' => '', + 'fields' => [ 'SPECIAL_QUERY()' ], + ], + "SELECT SPECIAL_QUERY()" + ], [ [ 'tables' => 'table', @@ -134,6 +151,30 @@ class DatabaseSQLTest extends PHPUnit_Framework_TestCase { "FROM table " . "WHERE alias IN ('1','2','3','4')" ], + [ + [ + 'tables' => 'table', + 'fields' => [ 'field' ], + 'options' => [ 'DISTINCT', 'LOCK IN SHARE MODE' ], + ], + "SELECT DISTINCT field FROM table LOCK IN SHARE MODE" + ], + [ + [ + 'tables' => 'table', + 'fields' => [ 'field' ], + 'options' => [ 'EXPLAIN' => true ], + ], + 'EXPLAIN SELECT field FROM table' + ], + [ + [ + 'tables' => 'table', + 'fields' => [ 'field' ], + 'options' => [ 'FOR UPDATE' ], + ], + "SELECT field FROM table FOR UPDATE" + ], ]; } -- 2.20.1