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(); 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 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..8522d4345e 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 * @@ -57,17 +144,37 @@ 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 object creating + * + * @return void + */ + /** * Test Set & Get * @@ -88,34 +195,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 * @@ -148,5 +227,72 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase array('te\\st', false), ); } -} + + /** + * 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'] + ); + } + +} +?> 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) {