diff --git a/libraries/DatabaseInterface.php b/libraries/DatabaseInterface.php index 94e2257790..8425ebfda3 100644 --- a/libraries/DatabaseInterface.php +++ b/libraries/DatabaseInterface.php @@ -489,10 +489,9 @@ class DatabaseInterface $needAnd = false; if ($table || (true === $tbl_is_group)) { $sql .= " `Name` LIKE '" - . - // Util::escapeMysqlWildcards( + . Util::escapeMysqlWildcards( $this->escapeString($table, $link) - // ) + ) . "%'"; $needAnd = true; } diff --git a/libraries/DbSearch.php b/libraries/DbSearch.php index ce31557f92..9299bf2800 100644 --- a/libraries/DbSearch.php +++ b/libraries/DbSearch.php @@ -204,8 +204,7 @@ class DbSearch // Usage example: If user is searching for a literal $ in a regexp search, // he should enter \$ as the value. $criteriaSearchStringEscaped = $GLOBALS['dbi']->escapeString( - $this->_criteriaSearchString, - ($this->_criteriaSearchType == 4 ? false : true) + $this->_criteriaSearchString ); // Extract search words or pattern $search_words = (($this->_criteriaSearchType > 2) diff --git a/libraries/db_table_exists.lib.php b/libraries/db_table_exists.lib.php index 48af281128..8407a2b712 100644 --- a/libraries/db_table_exists.lib.php +++ b/libraries/db_table_exists.lib.php @@ -62,7 +62,7 @@ if (empty($is_table) if (! $is_table) { $_result = $GLOBALS['dbi']->tryQuery( 'SHOW TABLES LIKE \'' - . $GLOBALS['dbi']->escapeString($table, true) . '\';', + . $GLOBALS['dbi']->escapeString($table) . '\';', null, PMA\libraries\DatabaseInterface::QUERY_STORE ); $is_table = @$GLOBALS['dbi']->numRows($_result); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ef300c6b50..902ea01424 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -27,7 +27,7 @@ test/libraries/rte test/libraries - diff --git a/test/classes/DbSearchTest.php b/test/classes/DbSearchTest.php index bc745ed2fc..31ca9b2404 100644 --- a/test/classes/DbSearchTest.php +++ b/test/classes/DbSearchTest.php @@ -10,6 +10,7 @@ */ require_once 'libraries/url_generating.lib.php'; +require_once 'libraries/js_escape.lib.php'; require_once 'libraries/database_interface.inc.php'; require_once 'test/PMATestCase.php'; @@ -40,6 +41,22 @@ class DbSearchTest extends PMATestCase $this->object = new DbSearch('pma_test'); $GLOBALS['server'] = 0; $GLOBALS['db'] = 'pma'; + + //mock DBI + $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->any()) + ->method('getColumns') + ->with('pma', 'table1') + ->will($this->returnValue(array())); + + $dbi->expects($this->any()) + ->method('escapeString') + ->will($this->returnArgument(0)); + + $GLOBALS['dbi'] = $dbi; } /** @@ -77,18 +94,6 @@ class DbSearchTest extends PMATestCase */ public function testGetSearchSqls() { - //mock DBI - $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface') - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->any()) - ->method('getColumns') - ->with('pma', 'table1') - ->will($this->returnValue(array())); - - $GLOBALS['dbi'] = $dbi; - $this->assertEquals( array ( 'select_columns' => 'SELECT * FROM `pma`.`table1` WHERE FALSE', diff --git a/test/classes/navigation/NavigationTest.php b/test/classes/navigation/NavigationTest.php index 72a11090e9..c6c0d6a67c 100644 --- a/test/classes/navigation/NavigationTest.php +++ b/test/classes/navigation/NavigationTest.php @@ -117,13 +117,11 @@ class NavigationTest extends PMATestCase $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface') ->disableOriginalConstructor() ->getMock(); - $dbi->expects($this->any())->method('escapeString') - ->will($this->returnArgument(0)); $dbi->expects($this->once()) ->method('tryQuery') ->with($expectedQuery) ->will($this->returnValue(true)); - $dbi->expects($this->at(1)) + $dbi->expects($this->at(3)) ->method('fetchArray') ->will( $this->returnValue( @@ -133,7 +131,7 @@ class NavigationTest extends PMATestCase ) ) ); - $dbi->expects($this->at(2)) + $dbi->expects($this->at(4)) ->method('fetchArray') ->will( $this->returnValue( @@ -143,11 +141,13 @@ class NavigationTest extends PMATestCase ) ) ); - $dbi->expects($this->at(3)) + $dbi->expects($this->at(5)) ->method('fetchArray') ->will($this->returnValue(false)); $dbi->expects($this->once()) ->method('freeResult'); + $dbi->expects($this->any())->method('escapeString') + ->will($this->returnArgument(0)); $GLOBALS['dbi'] = $dbi; diff --git a/test/classes/plugin/export/ExportHtmlwordTest.php b/test/classes/plugin/export/ExportHtmlwordTest.php index 5e8e1336ed..06aef14afc 100644 --- a/test/classes/plugin/export/ExportHtmlwordTest.php +++ b/test/classes/plugin/export/ExportHtmlwordTest.php @@ -479,20 +479,15 @@ class ExportHtmlwordTest extends PMATestCase ->disableOriginalConstructor() ->getMock(); - $dbi->expects($this->at(1)) + $dbi->expects($this->exactly(2)) ->method('fetchResult') - ->will($this->returnValue(array())); - - $dbi->expects($this->at(6)) - ->method('fetchResult') - ->will( - $this->returnValue( - array( - 'fieldname' => array( - 'values' => 'test-', - 'transformation' => 'testfoo', - 'mimetype' => 'test<' - ) + ->willReturnOnConsecutiveCalls( + array(), + array( + 'fieldname' => array( + 'values' => 'test-', + 'transformation' => 'testfoo', + 'mimetype' => 'test<' ) ) ); @@ -527,6 +522,8 @@ class ExportHtmlwordTest extends PMATestCase ) ) ); + $dbi->expects($this->any())->method('escapeString') + ->will($this->returnArgument(0)); $GLOBALS['dbi'] = $dbi; @@ -573,29 +570,20 @@ class ExportHtmlwordTest extends PMATestCase ->disableOriginalConstructor() ->getMock(); - $dbi->expects($this->at(1)) + $dbi->expects($this->exactly(2)) ->method('fetchResult') - ->will( - $this->returnValue( - array( - 'fieldname' => array( - 'foreign_table' => 'ftable', - 'foreign_field' => 'ffield' - ) + ->willReturnOnConsecutiveCalls( + array( + 'fieldname' => array( + 'foreign_table' => 'ftable', + 'foreign_field' => 'ffield' ) - ) - ); - - $dbi->expects($this->at(6)) - ->method('fetchResult') - ->will( - $this->returnValue( - array( - 'field' => array( - 'values' => 'test-', - 'transformation' => 'testfoo', - 'mimetype' => 'test<' - ) + ), + array( + 'field' => array( + 'values' => 'test-', + 'transformation' => 'testfoo', + 'mimetype' => 'test<' ) ) ); @@ -631,6 +619,8 @@ class ExportHtmlwordTest extends PMATestCase ) ) ); + $dbi->expects($this->any())->method('escapeString') + ->will($this->returnArgument(0)); $GLOBALS['dbi'] = $dbi; @@ -700,6 +690,8 @@ class ExportHtmlwordTest extends PMATestCase ) ) ); + $dbi->expects($this->any())->method('escapeString') + ->will($this->returnArgument(0)); $GLOBALS['dbi'] = $dbi; diff --git a/test/classes/plugin/export/ExportOdtTest.php b/test/classes/plugin/export/ExportOdtTest.php index 6a9994bb86..8a9a7f2c08 100644 --- a/test/classes/plugin/export/ExportOdtTest.php +++ b/test/classes/plugin/export/ExportOdtTest.php @@ -688,20 +688,15 @@ class ExportOdtTest extends PMATestCase ->disableOriginalConstructor() ->getMock(); - $dbi->expects($this->at(1)) + $dbi->expects($this->exactly(2)) ->method('fetchResult') - ->will($this->returnValue(array())); - - $dbi->expects($this->at(6)) - ->method('fetchResult') - ->will( - $this->returnValue( - array( - 'fieldname' => array( - 'values' => 'test-', - 'transformation' => 'testfoo', - 'mimetype' => 'test<' - ) + ->willReturnOnConsecutiveCalls( + array(), + array( + 'fieldname' => array( + 'values' => 'test-', + 'transformation' => 'testfoo', + 'mimetype' => 'test<' ) ) ); @@ -794,29 +789,20 @@ class ExportOdtTest extends PMATestCase ->disableOriginalConstructor() ->getMock(); - $dbi->expects($this->at(1)) + $dbi->expects($this->exactly(2)) ->method('fetchResult') - ->will( - $this->returnValue( - array( - 'fieldname' => array( - 'foreign_table' => 'ftable', - 'foreign_field' => 'ffield' - ) + ->willReturnOnConsecutiveCalls( + array( + 'fieldname' => array( + 'foreign_table' => 'ftable', + 'foreign_field' => 'ffield' ) - ) - ); - - $dbi->expects($this->at(6)) - ->method('fetchResult') - ->will( - $this->returnValue( - array( - 'field' => array( - 'values' => 'test-', - 'transformation' => 'testfoo', - 'mimetype' => 'test<' - ) + ), + array( + 'field' => array( + 'values' => 'test-', + 'transformation' => 'testfoo', + 'mimetype' => 'test<' ) ) ); diff --git a/test/classes/plugin/export/ExportSqlTest.php b/test/classes/plugin/export/ExportSqlTest.php index 8228bb9916..8ba44774c9 100644 --- a/test/classes/plugin/export/ExportSqlTest.php +++ b/test/classes/plugin/export/ExportSqlTest.php @@ -92,6 +92,9 @@ class ExportSqlTest extends PMATestCase ->method('getCompatibilities') ->will($this->returnValue(array('v1', 'v2'))); + $dbi->expects($this->any())->method('escapeString') + ->will($this->returnArgument(0)); + $GLOBALS['dbi'] = $dbi; $GLOBALS['plugin_param']['export_type'] = 'server'; $GLOBALS['plugin_param']['single_table'] = false; @@ -857,8 +860,10 @@ class ExportSqlTest extends PMATestCase $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface') ->disableOriginalConstructor() ->getMock(); + $dbi->expects($this->any())->method('escapeString') + ->will($this->returnArgument(0)); - $dbi->expects($this->at(0)) + $dbi->expects($this->any(0)) ->method('getColumns') ->with('db', 'view') ->will( @@ -876,22 +881,6 @@ class ExportSqlTest extends PMATestCase ) ); - $dbi->expects($this->at(1)) - ->method('getColumns') - ->with('db', 'view') - ->will( - $this->returnValue( - array( - 'cname' => array( - 'Type' => 'char', - 'Collation' => 'utf-8', - 'Null' => 'YES', - 'Comment' => 'cmt', - 'Field' => 'fname' - ) - ) - ) - ); $GLOBALS['dbi'] = $dbi; $GLOBALS['sql_compatibility'] = 'MSSQL'; @@ -910,6 +899,31 @@ class ExportSqlTest extends PMATestCase // case 2 unset($GLOBALS['sql_compatibility']); + + $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + $dbi->expects($this->any())->method('escapeString') + ->will($this->returnArgument(0)); + + $dbi->expects($this->any()) + ->method('getColumns') + ->with('db', 'view') + ->will( + $this->returnValue( + array( + 'cname' => array( + 'Type' => 'char', + 'Collation' => 'utf-8', + 'Null' => 'YES', + 'Comment' => 'cmt', + 'Field' => 'fname' + ) + ) + ) + ); + $GLOBALS['dbi'] = $dbi; + $result = $method->invoke( $this->object, 'db', 'view', "\n", false ); @@ -950,12 +964,8 @@ class ExportSqlTest extends PMATestCase ->disableOriginalConstructor() ->getMock(); - $dbi->expects($this->at(0)) + $dbi->expects($this->any()) ->method('query') - ->with( - 'SHOW TABLE STATUS FROM `db` WHERE Name = \'table\'', null, - PMA\libraries\DatabaseInterface::QUERY_STORE - ) ->will($this->returnValue('res')); $dbi->expects($this->never()) @@ -982,11 +992,6 @@ class ExportSqlTest extends PMATestCase ->with('res') ->will($this->returnValue($tmpres)); - $dbi->expects($this->at(5)) - ->method('query') - ->with('SET SQL_QUOTE_SHOW_CREATE = 1') - ->will($this->returnValue('res')); - $dbi->expects($this->once()) ->method('tryQuery') ->with('SHOW CREATE TABLE `db`.`table`') @@ -1019,7 +1024,7 @@ class ExportSqlTest extends PMATestCase $dbi->expects($this->once()) ->method('getTable') - ->will($this->returnValue(new Table('table', 'db'))); + ->will($this->returnValue(new Table('table', 'db', $dbi))); $GLOBALS['dbi'] = $dbi; $GLOBALS['cfg']['Server']['DisableIS'] = false; @@ -1121,12 +1126,8 @@ class ExportSqlTest extends PMATestCase ->disableOriginalConstructor() ->getMock(); - $dbi->expects($this->at(0)) + $dbi->expects($this->any()) ->method('query') - ->with( - 'SHOW TABLE STATUS FROM `db` WHERE Name = \'table\'', null, - PMA\libraries\DatabaseInterface::QUERY_STORE - ) ->will($this->returnValue('res')); $dbi->expects($this->never()) @@ -1153,11 +1154,6 @@ class ExportSqlTest extends PMATestCase ->with('res') ->will($this->returnValue($tmpres)); - $dbi->expects($this->at(5)) - ->method('query') - ->with('SET SQL_QUOTE_SHOW_CREATE = 0') - ->will($this->returnValue('res')); - $dbi->expects($this->once()) ->method('tryQuery') ->with('SHOW CREATE TABLE `db`.`table`') @@ -1169,7 +1165,10 @@ class ExportSqlTest extends PMATestCase $dbi->expects($this->once()) ->method('getTable') - ->will($this->returnValue(new Table('table', 'db'))); + ->will($this->returnValue(new Table('table', 'db', $dbi))); + $dbi->expects($this->any()) + ->method('escapeString') + ->will($this->returnArgument(0)); $GLOBALS['dbi'] = $dbi; $GLOBALS['cfg']['Server']['DisableIS'] = false; @@ -1207,32 +1206,24 @@ class ExportSqlTest extends PMATestCase ->disableOriginalConstructor() ->getMock(); - $dbi->expects($this->at(0)) + $dbi->expects($this->exactly(2)) ->method('fetchResult') - ->will( - $this->returnValue( - array( - 'foo' => array( - 'foreign_table' => 'ftable', - 'foreign_field' => 'ffield' - ) + ->willReturnOnConsecutiveCalls( + array( + 'foo' => array( + 'foreign_table' => 'ftable', + 'foreign_field' => 'ffield' + ) + ), + array( + 'fieldname' => array( + 'values' => 'test-', + 'transformation' => 'testfoo', + 'mimetype' => 'test<' ) ) ); - $dbi->expects($this->at(1)) - ->method('fetchResult') - ->will( - $this->returnValue( - array( - 'fieldname' => array( - 'values' => 'test-', - 'transformation' => 'testfoo', - 'mimetype' => 'test<' - ) - ) - ) - ); $GLOBALS['dbi'] = $dbi; $method = new ReflectionMethod('PMA\libraries\plugins\export\ExportSql', '_getTableComments'); diff --git a/test/classes/plugin/export/ExportTexytextTest.php b/test/classes/plugin/export/ExportTexytextTest.php index ace70296f8..56399e0722 100644 --- a/test/classes/plugin/export/ExportTexytextTest.php +++ b/test/classes/plugin/export/ExportTexytextTest.php @@ -364,6 +364,7 @@ class ExportTexytextTest extends PMATestCase $this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportTexytext') ->setMethods(array('formatOneColumnDefinition')) ->getMock(); + $GLOBALS['controllink'] = null; // case 1 @@ -387,20 +388,25 @@ class ExportTexytextTest extends PMATestCase ->with('db', 'table') ->will($this->returnValue($keys)); - $dbi->expects($this->at(2)) + $dbi->expects($this->exactly(2)) ->method('fetchResult') - ->will( - $this->returnValue( - array( - 'fname' => array( - 'foreign_table' => ' 'ffield>' - ) + ->willReturnOnConsecutiveCalls( + array( + 'fname' => array( + 'foreign_table' => ' 'ffield>' + ) + ), + array( + 'fname' => array( + 'values' => 'test-', + 'transformation' => 'testfoo', + 'mimetype' => 'test<' ) ) ); - $dbi->expects($this->at(3)) + $dbi->expects($this->once()) ->method('fetchValue') ->will( $this->returnValue( @@ -408,20 +414,6 @@ class ExportTexytextTest extends PMATestCase ) ); - $dbi->expects($this->at(5)) - ->method('fetchResult') - ->will( - $this->returnValue( - array( - 'fname' => array( - 'values' => 'test-', - 'transformation' => 'testfoo', - 'mimetype' => 'test<' - ) - ) - ) - ); - $columns = array( 'Field' => 'fname', 'Comment' => 'comm'