From 482d0de1dfd5ed877599c42ef34ed1a71019e653 Mon Sep 17 00:00:00 2001 From: Dirk-jan Date: Sat, 13 Jul 2013 11:30:29 +0200 Subject: [PATCH 1/6] Added SQL_MODE for copy and move operations to prevent import errors --- libraries/operations.lib.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/operations.lib.php b/libraries/operations.lib.php index 3b275f6430..126c835306 100644 --- a/libraries/operations.lib.php +++ b/libraries/operations.lib.php @@ -377,6 +377,11 @@ function PMA_getSqlQueryAndCreateDbBeforeCopy() $GLOBALS['dbi']->query($local_query); $GLOBALS['db'] = $original_db; + // Set the SQL mode to NO_AUTO_VALUE_ON_ZERO to prevent MySQL from creating + // export statements it cannot import + $sql_set_mode = "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'"; + PMA_DBI_query($sql_set_mode); + // rebuild the database list because PMA_Table::moveCopy // checks in this list if the target db exists $GLOBALS['pma']->databases->build(); From 5f0a9873625cc93b2132cf7998f0560297d100ec Mon Sep 17 00:00:00 2001 From: adamgsoc2013 Date: Mon, 15 Jul 2013 10:30:53 +0800 Subject: [PATCH 2/6] add unit test case for PMA_Table* --- test/classes/PMA_TableSearch_test.php | 107 ++++++++++++ test/classes/PMA_Table_test.php | 225 +++++++++++++++++++++----- 2 files changed, 295 insertions(+), 37 deletions(-) create mode 100644 test/classes/PMA_TableSearch_test.php diff --git a/test/classes/PMA_TableSearch_test.php b/test/classes/PMA_TableSearch_test.php new file mode 100644 index 0000000000..b1f683044c --- /dev/null +++ b/test/classes/PMA_TableSearch_test.php @@ -0,0 +1,107 @@ +getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $columns =array( + array( + 'Field' => 'Field1', + 'Type' => 'Type1', + 'Null' => 'Null1', + 'Collation' => 'Collation1', + ), + array( + 'Field' => 'Field2', + 'Type' => 'Type2', + 'Null' => 'Null2', + 'Collation' => 'Collation2', + ) + ); + $dbi->expects($this->any())->method('getColumns') + ->will($this->returnValue($columns)); + + $show_create_table = "CREATE TABLE `pma_bookmark` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `dbase` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', + `user` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', + `label` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '', + `query` text COLLATE utf8_bin NOT NULL, + PRIMARY KEY (`id`), + KEY `foreign_field` (`foreign_db`,`foreign_table`) + ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Bookmarks'"; + + $dbi->expects($this->any())->method('fetchValue') + ->will($this->returnValue($show_create_table)); + + $GLOBALS['dbi'] = $dbi; + } + + /** + * tearDown function for test cases + * + * @access protected + * @return void + */ + protected function tearDown() + { + + } + + /** + * Test for __construct + * + * @return void + */ + public function testConstruct() + { + $tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "normal"); + $columNames = $tableSearch->getColumnNames(); + $this->assertEquals( + 'Field1', + $columNames[0] + ); + $this->assertEquals( + 'Field2', + $columNames[1] + ); + } +} +?> diff --git a/test/classes/PMA_Table_test.php b/test/classes/PMA_Table_test.php index 2664828f4e..15802eeb93 100644 --- a/test/classes/PMA_Table_test.php +++ b/test/classes/PMA_Table_test.php @@ -1,4 +1,5 @@ getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $sql_isView_true = "SELECT TABLE_NAME + FROM information_schema.VIEWS + WHERE TABLE_SCHEMA = 'PMA' + AND TABLE_NAME = 'PMA_BookMark'"; + + $sql_isView_false = "SELECT TABLE_NAME + FROM information_schema.VIEWS + WHERE TABLE_SCHEMA = 'PMA' + AND TABLE_NAME = 'PMA_BookMark_2'"; + + $sql_isUpdatableView_true = "SELECT TABLE_NAME + FROM information_schema.VIEWS + WHERE TABLE_SCHEMA = 'PMA' + AND TABLE_NAME = 'PMA_BookMark' + AND IS_UPDATABLE = 'YES'"; + + $sql_isUpdatableView_false = "SELECT TABLE_NAME + FROM information_schema.VIEWS + WHERE TABLE_SCHEMA = 'PMA' + AND TABLE_NAME = 'PMA_BookMark_2' + AND IS_UPDATABLE = 'YES'"; + + $sql_analyzeStructure_true = "SELECT COLUMN_NAME, DATA_TYPE + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = 'PMA' + AND TABLE_NAME = 'PMA_BookMark'"; + + $fetchResult = array( + array( + $sql_isView_true, + null, + null, + null, + 0, + true + ), + array( + $sql_isView_false, + null, + null, + null, + 0, + false + ), + array( + $sql_isUpdatableView_true, + null, + null, + null, + 0, + true + ), + array( + $sql_isUpdatableView_false, + null, + null, + null, + 0, + false + ), + array( + $sql_analyzeStructure_true, + null, + null, + null, + 0, + array( + array('COLUMN_NAME'=>'COLUMN_NAME', 'DATA_TYPE'=>'DATA_TYPE') + ) + ), + ); + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->any())->method('fetchResult') + ->will($this->returnValueMap($fetchResult)); + + $GLOBALS['dbi'] = $dbi; } /** - * Test object creating + * tearDown function for test cases * + * @access protected * @return void */ + protected function tearDown() + { + + } + public function testCreate() { $table = new PMA_Table('table1', 'pma_test'); @@ -57,17 +150,103 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase } /** - * Test renaming + * Test for constructor * * @return void */ - public function testRename() + public function testConstruct() { - $table = new PMA_Table('table1', 'pma_test'); - $table->rename('table3'); - $this->assertEquals('table3', $table->getName()); + $table = new PMA_Table("PMA_BookMark", "PMA"); + $this->assertEquals( + 'PMA_BookMark', + $table->__toString() + ); + $this->assertEquals( + 'PMA_BookMark', + $table->getName() + ); + $this->assertEquals( + 'PMA', + $table->getDbName() + ); + $this->assertEquals( + 'PMA.PMA_BookMark', + $table->getFullName() + ); } + /** + * Test for isView + * + * @return void + */ + public function testIsView() + { + $this->assertEquals( + false, + PMA_Table::isView() + ); + + //validate that it is the same as DBI fetchResult + $this->assertEquals( + true, + PMA_Table::isView('PMA', 'PMA_BookMark') + ); + $this->assertEquals( + false, + PMA_Table::isView('PMA', 'PMA_BookMark_2') + ); + } + + /** + * Test for isUpdatableView + * + * @return void + */ + public function testIsUpdatableView() + { + $this->assertEquals( + false, + PMA_Table::isUpdatableView() + ); + + //validate that it is the same as DBI fetchResult + $this->assertEquals( + true, + PMA_Table::isUpdatableView('PMA', 'PMA_BookMark') + ); + $this->assertEquals( + false, + PMA_Table::isUpdatableView('PMA', 'PMA_BookMark_2') + ); + } + + /** + * Test for analyzeStructure + * + * @return void + */ + public function testAnalyzeStructure() + { + $this->assertEquals( + false, + PMA_Table::analyzeStructure() + ); + + //validate that it is the same as DBI fetchResult + $show_create_table = PMA_Table::analyzeStructure('PMA', 'PMA_BookMark'); + $this->assertEquals( + array('type'=>'DATA_TYPE'), + $show_create_table[0]['create_table_fields']['COLUMN_NAME'] + ); + } + + /** + * Test object creating + * + * @return void + */ + /** * Test Set & Get * @@ -88,34 +267,6 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase ); } - /** - * Test getting columns - * - * @return void - */ - public function testColumns() - { - $table = new PMA_Table('table1', 'pma_test'); - $this->assertEquals( - array('`pma_test`.`table1`.`i`', '`pma_test`.`table1`.`o`'), - $table->getColumns() - ); - } - - /** - * Test getting unique columns - * - * @return void - */ - public function testUniqueColumns() - { - $table = new PMA_Table('table1', 'pma_test'); - $this->assertEquals( - array(), - $table->getUniqueColumns() - ); - } - /** * Test name validation * @@ -149,4 +300,4 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase ); } } - +?> From 7cf5cc0d4c6b3bdf4dd96fc68788ae01ba1c4940 Mon Sep 17 00:00:00 2001 From: adamgsoc2013 Date: Mon, 15 Jul 2013 10:42:31 +0800 Subject: [PATCH 3/6] make better diff --- test/classes/PMA_Table_test.php | 124 +++++++++++++++++--------------- 1 file changed, 65 insertions(+), 59 deletions(-) diff --git a/test/classes/PMA_Table_test.php b/test/classes/PMA_Table_test.php index 15802eeb93..b525f44571 100644 --- a/test/classes/PMA_Table_test.php +++ b/test/classes/PMA_Table_test.php @@ -142,7 +142,12 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase { } - + + /** + * Test object creating + * + * @return void + */ public function testCreate() { $table = new PMA_Table('table1', 'pma_test'); @@ -175,6 +180,65 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase ); } + /** + * Test object creating + * + * @return void + */ + + /** + * Test Set & Get + * + * @return void + */ + public function testSetAndGet() + { + $table = new PMA_Table('table1', 'pma_test'); + $table->set('production', 'Phpmyadmin'); + $table->set('db', 'mysql'); + $this->assertEquals( + "Phpmyadmin", + $table->get("production") + ); + $this->assertEquals( + "mysql", + $table->get("db") + ); + } + + /** + * Test name validation + * + * @param string $name name to test + * @param boolena $result expected result + * + * @return void + * + * @dataProvider dataValidateName + */ + public function testValidateName($name, $result) + { + $this->assertEquals( + $result, + PMA_Table::isValidName($name) + ); + } + + /** + * Data provider for name validation + * + * @return array with test data + */ + public function dataValidateName() + { + return array( + array('test', true), + array('te/st', false), + array('te.st', false), + array('te\\st', false), + ); + } + /** * Test for isView * @@ -241,63 +305,5 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase ); } - /** - * Test object creating - * - * @return void - */ - - /** - * Test Set & Get - * - * @return void - */ - public function testSetAndGet() - { - $table = new PMA_Table('table1', 'pma_test'); - $table->set('production', 'Phpmyadmin'); - $table->set('db', 'mysql'); - $this->assertEquals( - "Phpmyadmin", - $table->get("production") - ); - $this->assertEquals( - "mysql", - $table->get("db") - ); - } - - /** - * Test name validation - * - * @param string $name name to test - * @param boolena $result expected result - * - * @return void - * - * @dataProvider dataValidateName - */ - public function testValidateName($name, $result) - { - $this->assertEquals( - $result, - PMA_Table::isValidName($name) - ); - } - - /** - * Data provider for name validation - * - * @return array with test data - */ - public function dataValidateName() - { - return array( - array('test', true), - array('te/st', false), - array('te.st', false), - array('te\\st', false), - ); - } } ?> From 014cbe7036509430cf5a0f03945c7cada2f87059 Mon Sep 17 00:00:00 2001 From: adamgsoc2013 Date: Mon, 15 Jul 2013 17:07:53 +0800 Subject: [PATCH 4/6] not need to do on tearDown --- test/classes/PMA_Table_test.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/classes/PMA_Table_test.php b/test/classes/PMA_Table_test.php index b525f44571..8522d4345e 100644 --- a/test/classes/PMA_Table_test.php +++ b/test/classes/PMA_Table_test.php @@ -131,17 +131,6 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase $GLOBALS['dbi'] = $dbi; } - - /** - * tearDown function for test cases - * - * @access protected - * @return void - */ - protected function tearDown() - { - - } /** * Test object creating From 3f646649ea82a5f13f391fb72876d53751eb4527 Mon Sep 17 00:00:00 2001 From: ayushchd Date: Mon, 15 Jul 2013 16:28:42 +0545 Subject: [PATCH 5/6] Fix test failures because of header redirect --- test/libraries/PMA_Form_Processing_test.php | 7 ++++++- test/libraries/PMA_user_preferences_test.php | 8 +++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/test/libraries/PMA_Form_Processing_test.php b/test/libraries/PMA_Form_Processing_test.php index bfc3d95f82..6be1d49908 100644 --- a/test/libraries/PMA_Form_Processing_test.php +++ b/test/libraries/PMA_Form_Processing_test.php @@ -29,6 +29,11 @@ class PMA_From_Processing_Test extends PHPUnit_Framework_TestCase */ public function testProcessFormSet() { + if (!defined('PMA_TEST_HEADERS')) { + $this->markTestSkipped( + 'Cannot redefine constant/function - missing runkit extension' + ); + } // case 1 $formDisplay = $this->getMockBuilder('FormDisplay') @@ -106,7 +111,7 @@ class PMA_From_Processing_Test extends PHPUnit_Framework_TestCase process_formset($formDisplay); $this->assertEquals( - 'HTTP/1.1 303 See OtherLocation: index.php', + array('HTTP/1.1 303 See Other', 'Location: index.php'), $GLOBALS['header'] ); diff --git a/test/libraries/PMA_user_preferences_test.php b/test/libraries/PMA_user_preferences_test.php index 380a691e00..620081221b 100644 --- a/test/libraries/PMA_user_preferences_test.php +++ b/test/libraries/PMA_user_preferences_test.php @@ -354,8 +354,10 @@ class PMA_User_Preferences_Test extends PHPUnit_Framework_TestCase */ public function testUserprefsRedirect() { - if (! PMA_HAS_RUNKIT) { - $this->markTestSkipped('Cannot redefine constant'); + if (!defined('PMA_TEST_HEADERS')) { + $this->markTestSkipped( + 'Cannot redefine constant/function - missing runkit extension' + ); } $GLOBALS['cfg']['PmaAbsoluteUri'] = 'http://www.phpmyadmin.net'; @@ -379,7 +381,7 @@ class PMA_User_Preferences_Test extends PHPUnit_Framework_TestCase $this->assertContains( 'Location: http://www.phpmyadmin.netfile.html?a=b&saved=1&server=0&' . 'token=token#h+ash', - $GLOBALS['header'] + $GLOBALS['header'][0] ); if ($redefine !== null) { From 98fa2119576825db6121817cd635c1122cc6a4aa Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Mon, 15 Jul 2013 07:57:24 -0400 Subject: [PATCH 6/6] Fix typo --- libraries/sqlparser.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 59275313cf..7cfde965e7 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -1667,7 +1667,7 @@ function PMA_SQP_analyze($arr) $in_limit = false; $after_limit = true; - // for the presnece of PROCEDURE ANALYSE + // for the presence of PROCEDURE ANALYSE if (isset($subresult['queryflags']['select_from']) && $subresult['queryflags']['select_from'] == 1 && ($i + 1) < $size @@ -1678,7 +1678,7 @@ function PMA_SQP_analyze($arr) } } - // for the presnece of INTO OUTFILE + // for the presence of INTO OUTFILE if ($upper_data == 'INTO' && isset($subresult['queryflags']['select_from']) && $subresult['queryflags']['select_from'] == 1