From 6eced72d9327b187a72c5d247ddc0707c22a9388 Mon Sep 17 00:00:00 2001 From: ayushchd Date: Tue, 6 Aug 2013 23:58:29 +0530 Subject: [PATCH 01/53] Fix uninitialized variable issue --- libraries/plugins/export/ExportTexytext.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/plugins/export/ExportTexytext.class.php b/libraries/plugins/export/ExportTexytext.class.php index 16d8b9527e..1e6efa0da3 100644 --- a/libraries/plugins/export/ExportTexytext.class.php +++ b/libraries/plugins/export/ExportTexytext.class.php @@ -430,7 +430,7 @@ class ExportTexytext extends ExportPlugin */ function getTriggers($db, $table) { - $text_output .= "|------\n"; + $text_output = "|------\n"; $text_output .= '|' . __('Column'); $dump = "|------\n"; $dump .= '|' . __('Name'); From ff715b1b90a9f8a61d3be1a88e880787b589fa95 Mon Sep 17 00:00:00 2001 From: ayushchd Date: Wed, 7 Aug 2013 00:00:51 +0530 Subject: [PATCH 02/53] UTs for export libraries --- .../plugin/export/PMA_ExportSql_test.php | 2102 +++++++++++++++++ .../plugin/export/PMA_ExportTexytext_test.php | 653 +++++ .../plugin/export/PMA_ExportXml_test.php | 704 ++++++ .../plugin/export/PMA_ExportYaml_test.php | 267 +++ 4 files changed, 3726 insertions(+) create mode 100644 test/classes/plugin/export/PMA_ExportSql_test.php create mode 100644 test/classes/plugin/export/PMA_ExportTexytext_test.php create mode 100644 test/classes/plugin/export/PMA_ExportXml_test.php create mode 100644 test/classes/plugin/export/PMA_ExportYaml_test.php diff --git a/test/classes/plugin/export/PMA_ExportSql_test.php b/test/classes/plugin/export/PMA_ExportSql_test.php new file mode 100644 index 0000000000..a6f706d88e --- /dev/null +++ b/test/classes/plugin/export/PMA_ExportSql_test.php @@ -0,0 +1,2102 @@ +object = new ExportSql(); + } + + /** + * tearDown for test cases + * + * @return void + */ + public function tearDown() + { + unset($this->object); + } + + /** + * Test for ExportSql::setProperties + * + * @return void + */ + public function testSetProperties() + { + $restoreDrizzle = $restoreMySQLIntVersion = 'PMANORESTORE'; + + if (PMA_DRIZZLE || PMA_MYSQL_INT_VERSION <= 50100) { + if (!PMA_HAS_RUNKIT) { + $this->markTestSkipped( + "Cannot redefine constant. Missing runkit extension" + ); + } else { + if (PMA_DRIZZLE) { + $restoreDrizzle = PMA_DRIZZLE; + runkit_constant_redefine('PMA_DRIZZLE', false); + } + if (PMA_MYSQL_INT_VERSION <= 50100) { + $restoreMySQLIntVersion = PMA_MYSQL_INT_VERSION; + runkit_constant_redefine('PMA_MYSQL_INT_VERSION', 50111); + } + } + } + // test with hide structure and hide sql as true + $GLOBALS['plugin_param']['export_type'] = 'table'; + $GLOBALS['plugin_param']['single_table'] = false; + $GLOBALS['cfgRelation']['mimework'] = true; + + $method = new ReflectionMethod('ExportSql', 'setProperties'); + $method->setAccessible(true); + $method->invoke($this->object, null); + + $attrProperties = new ReflectionProperty('ExportSql', 'properties'); + $attrProperties->setAccessible(true); + $properties = $attrProperties->getValue($this->object); + + $this->assertNull( + $properties + ); + + // test with hide structure and hide sql as false + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('getCompatibilities') + ->will($this->returnValue(array('v1', 'v2'))); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['plugin_param']['export_type'] = 'server'; + $GLOBALS['plugin_param']['single_table'] = false; + $GLOBALS['cfgRelation']['mimework'] = true; + $GLOBALS['cfgRelation']['relation'] = true; + + $method->invoke($this->object, null); + $properties = $attrProperties->getValue($this->object); + + $this->assertInstanceOf( + 'ExportPluginProperties', + $properties + ); + + $this->assertEquals( + 'SQL', + $properties->getText() + ); + + $options = $properties->getOptions(); + + $this->assertInstanceOf( + 'OptionsPropertyRootGroup', + $options + ); + + $generalOptionsArray = $options->getProperties(); + + $generalOptions = array_shift($generalOptionsArray); + + $this->assertInstanceOf( + 'OptionsPropertyMainGroup', + $generalOptions + ); + + $properties = $generalOptions->getProperties(); + + $property = array_shift($properties); + + $this->assertInstanceOf( + 'OptionsPropertySubgroup', + $property + ); + + $this->assertInstanceOf( + 'BoolPropertyItem', + $property->getSubgroupHeader() + ); + + $leaves = $property->getProperties(); + + $leaf = array_shift($leaves); + $this->assertInstanceOf( + 'TextPropertyItem', + $leaf + ); + + $leaf = array_shift($leaves); + $this->assertInstanceOf( + 'BoolPropertyItem', + $leaf + ); + + $leaf = array_shift($leaves); + $this->assertInstanceOf( + 'BoolPropertyItem', + $leaf + ); + + $leaf = array_shift($leaves); + $this->assertInstanceOf( + 'BoolPropertyItem', + $leaf + ); + + $property = array_shift($properties); + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + $property = array_shift($properties); + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + $property = array_shift($properties); + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + $property = array_shift($properties); + $this->assertInstanceOf( + 'SelectPropertyItem', + $property + ); + + $this->assertEquals( + array( + 'v1' => 'v1', + 'v2' => 'v2' + ), + $property->getValues() + ); + + $property = array_shift($properties); + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + $property = array_shift($properties); + $this->assertInstanceOf( + 'OptionsPropertySubgroup', + $property + ); + + $this->assertInstanceOf( + 'RadioPropertyItem', + $property->getSubgroupHeader() + ); + + $structureOptions = array_shift($generalOptionsArray); + + $this->assertInstanceOf( + 'OptionsPropertyMainGroup', + $structureOptions + ); + + $properties = $structureOptions->getProperties(); + + $property = array_shift($properties); + + $this->assertInstanceOf( + 'OptionsPropertySubgroup', + $property + ); + + $this->assertInstanceOf( + 'MessageOnlyPropertyItem', + $property->getSubgroupHeader() + ); + + $leaves = $property->getProperties(); + + $leaf = array_shift($leaves); + $this->assertInstanceOf( + 'BoolPropertyItem', + $leaf + ); + + $leaf = array_shift($leaves); + $this->assertInstanceOf( + 'BoolPropertyItem', + $leaf + ); + + $this->assertEquals( + 'Add DROP TABLE / VIEW / PROCEDURE / FUNCTION' . + ' / EVENT statement', + $leaf->getText() + ); + + $leaf = array_shift($leaves); + $this->assertInstanceOf( + 'BoolPropertyItem', + $leaf + ); + + $leaf = array_shift($leaves); + $this->assertInstanceOf( + 'OptionsPropertySubgroup', + $leaf + ); + + $this->assertCount( + 2, + $leaf->getProperties() + ); + + $this->assertInstanceOf( + 'BoolPropertyItem', + $leaf->getSubgroupHeader() + ); + + $property = array_shift($properties); + + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + $dataOptions = array_shift($generalOptionsArray); + $this->assertInstanceOf( + 'OptionsPropertyMainGroup', + $dataOptions + ); + + $properties = $dataOptions->getProperties(); + + $this->assertCount( + 7, + $properties + ); + + $this->assertCount( + 2, + $properties[1]->getProperties() + ); + + if ($restoreDrizzle !== 'PMANORESTORE') { + runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle); + } + + if ($restoreMySQLIntVersion !== 'PMANORESTORE') { + runkit_constant_redefine( + 'PMA_MYSQL_INT_VERSION', $restoreMySQLIntVersion + ); + } + } + + /** + * Test for ExportSql::setProperties + * + * @return void + */ + public function testSetPropertiesWithDrizzle() + { + $restoreDrizzle = $restoreMySQLIntVersion = 'PMANORESTORE'; + + if (!PMA_DRIZZLE || PMA_MYSQL_INT_VERSION > 50100) { + if (!PMA_HAS_RUNKIT) { + $this->markTestSkipped( + "Cannot redefine constant. Missing runkit extension" + ); + } else { + if (!PMA_DRIZZLE) { + $restoreDrizzle = PMA_DRIZZLE; + runkit_constant_redefine('PMA_DRIZZLE', true); + } + if (PMA_MYSQL_INT_VERSION > 50100) { + $restoreMySQLIntVersion = PMA_MYSQL_INT_VERSION; + runkit_constant_redefine('PMA_MYSQL_INT_VERSION', 50000); + } + } + } + + $GLOBALS['plugin_param']['export_type'] = 'tableNot'; + $GLOBALS['plugin_param']['single_table'] = true; + $GLOBALS['cfgRelation']['mimework'] = false; + $GLOBALS['cfgRelation']['relation'] = false; + + $method = new ReflectionMethod('ExportSql', 'setProperties'); + $method->setAccessible(true); + $method->invoke($this->object, null); + + $attrProperties = new ReflectionProperty('ExportSql', 'properties'); + $attrProperties->setAccessible(true); + $properties = $attrProperties->getValue($this->object); + + $options = $properties->getOptions(); + + $generalOptionsArray = $options->getProperties(); + + $this->assertCount( + 3, + $generalOptionsArray + ); + + // generalOptions + $option = array_shift($generalOptionsArray); + + $properties = $option->getProperties(); + + $this->assertCount( + 5, + $properties + ); + + $this->assertCount( + 2, + $properties[0]->getProperties() + ); + + // structureOptions + $option = array_shift($generalOptionsArray); + $properties = $option->getProperties(); + + $this->assertCount( + 2, + $properties + ); + + $properties = $properties[0]->getProperties(); + + $this->assertCount( + 3, + $properties + ); + + $this->assertNotcontains( + ' / EVENT ', + $properties[1]->getText() + ); + + // dataOptions + $option = array_shift($generalOptionsArray); + $properties = $option->getProperties(); + + $this->assertCount( + 6, + $properties + ); + + $properties = $properties[1]->getProperties(); + + $this->assertCount( + 1, + $properties + ); + + // case 2 with export type as table + $GLOBALS['plugin_param']['export_type'] = 'table'; + + $method->invoke($this->object, null); + $properties = $attrProperties->getValue($this->object); + + $options = $properties->getOptions(); + $generalOptionsArray = $options->getProperties(); + $structOption = $generalOptionsArray[1]; + $properties = $structOption->getProperties(); + $subgroupProps = $properties[0]->getProperties(); + + $this->assertContains( + 'DROP TABLE', + $subgroupProps[0]->getText() + ); + + if ($restoreDrizzle !== 'PMANORESTORE') { + runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle); + } + + if ($restoreMySQLIntVersion !== 'PMANORESTORE') { + runkit_constant_redefine( + 'PMA_MYSQL_INT_VERSION', $restoreMySQLIntVersion + ); + } + } + + /** + * Test for ExportSql::exportRoutines + * + * @return void + */ + public function testExportRoutines() + { + $GLOBALS['crlf'] = '##'; + $GLOBALS['sql_drop_table'] = true; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('getProceduresOrFunctions') + ->with('db', 'PROCEDURE') + ->will($this->returnValue(array('p1', 'p2'))); + + $dbi->expects($this->at(1)) + ->method('getProceduresOrFunctions') + ->with('db', 'FUNCTION') + ->will($this->returnValue(array('f1'))); + + $dbi->expects($this->at(2)) + ->method('getDefinition') + ->with('db', 'PROCEDURE', 'p1') + ->will($this->returnValue('testp1')); + + $dbi->expects($this->at(3)) + ->method('getDefinition') + ->with('db', 'PROCEDURE', 'p2') + ->will($this->returnValue('testp2')); + + $dbi->expects($this->at(4)) + ->method('getDefinition') + ->with('db', 'FUNCTION', 'f1') + ->will($this->returnValue('testf1')); + + $GLOBALS['dbi'] = $dbi; + + $this->expectOutputString( + '##DELIMITER $$##DROP PROCEDURE IF EXISTS `p1`$$##testp1$$####' . + 'DROP PROCEDURE IF EXISTS `p2`$$##testp2$$####DROP FUNCTION IF' . + ' EXISTS `f1`$$##testf1$$####DELIMITER ;##' + ); + + $this->object->exportRoutines('db'); + } + + /** + * Test for ExportSql::_exportComment + * + * @return void + */ + public function testExportComment() + { + $method = new ReflectionMethod('ExportSql', '_exportComment'); + $method->setAccessible(true); + + $GLOBALS['crlf'] = '##'; + $GLOBALS['sql_include_comments'] = true; + + $this->assertEquals( + '--##', + $method->invoke($this->object, '') + ); + + $this->assertEquals( + '-- Comment##', + $method->invoke($this->object, 'Comment') + ); + + $GLOBALS['sql_include_comments'] = false; + + $this->assertEquals( + '', + $method->invoke($this->object, 'Comment') + ); + + unset($GLOBALS['sql_include_comments']); + + $this->assertEquals( + '', + $method->invoke($this->object, 'Comment') + ); + } + + /** + * Test for ExportSql::_possibleCRLF + * + * @return void + */ + public function testPossibleCRLF() + { + $method = new ReflectionMethod('ExportSql', '_possibleCRLF'); + $method->setAccessible(true); + + $GLOBALS['crlf'] = '##'; + $GLOBALS['sql_include_comments'] = true; + + $this->assertEquals( + '##', + $method->invoke($this->object, '') + ); + + $this->assertEquals( + '##', + $method->invoke($this->object, 'Comment') + ); + + $GLOBALS['sql_include_comments'] = false; + + $this->assertEquals( + '', + $method->invoke($this->object, 'Comment') + ); + + unset($GLOBALS['sql_include_comments']); + + $this->assertEquals( + '', + $method->invoke($this->object, 'Comment') + ); + } + + /** + * Test for ExportSql::exportFooter + * + * @return void + */ + public function testExportFooter() + { + $restoreDrizzle = 'PMANORESTORE'; + + if (PMA_DRIZZLE) { + if (!PMA_HAS_RUNKIT) { + $this->markTestSkipped( + "Cannot redefine constant. Missing runkit extension" + ); + } else { + $restoreDrizzle = PMA_DRIZZLE; + runkit_constant_redefine('PMA_DRIZZLE', false); + } + } + + $GLOBALS['sql_disable_fk'] = true; + $GLOBALS['sql_use_transaction'] = true; + $GLOBALS['charset_of_file'] = 'utf-8'; + $GLOBALS['mysql_charset_map']['utf-8'] = true; + $GLOBALS['sql_utc_time'] = true; + $GLOBALS['old_tz'] = 'GMT'; + $GLOBALS['asfile'] = 'yes'; + $GLOBALS['output_charset_conversion'] = 'utf-8'; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('query') + ->with('SET time_zone = "GMT"'); + + $GLOBALS['dbi'] = $dbi; + + $this->expectOutputString( + 'SET FOREIGN_KEY_CHECKS=1;COMMIT;/*!40101 SET CHARACTER_SET_CLIENT' . + '=@OLD_CHARACTER_SET_CLIENT */;/*!40101 SET CHARACTER_SET_RESULTS=@' . + 'OLD_CHARACTER_SET_RESULTS */;/*!40101 SET COLLATION_CONNECTION=@OLD' . + '_COLLATION_CONNECTION */;' + ); + + $this->assertTrue( + $this->object->exportFooter() + ); + + if ($restoreDrizzle !== 'PMANORESTORE') { + runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle); + } + + } + + /** + * Test for ExportSql::exportHeader + * + * @return void + */ + public function testExportHeader() + { + $restoreDrizzle = 'PMANORESTORE'; + + if (PMA_DRIZZLE) { + if (!PMA_HAS_RUNKIT) { + $this->markTestSkipped( + "Cannot redefine constant. Missing runkit extension" + ); + } else { + $restoreDrizzle = PMA_DRIZZLE; + runkit_constant_redefine('PMA_DRIZZLE', false); + } + } + + $GLOBALS['crlf'] = "\n"; + $GLOBALS['sql_compatibility'] = 'NONE'; + $GLOBALS['cfg']['Server']['host'] = 'localhost'; + $GLOBALS['cfg']['Server']['port'] = 80; + $GLOBALS['sql_disable_fk'] = true; + $GLOBALS['sql_use_transaction'] = true; + $GLOBALS['sql_utc_time'] = true; + $GLOBALS['old_tz'] = 'GMT'; + $GLOBALS['asfile'] = 'yes'; + $GLOBALS['output_charset_conversion'] = 'utf-8'; + $GLOBALS['sql_header_comment'] = "h1C\nh2C"; + $GLOBALS['sql_use_transaction'] = true; + $GLOBALS['sql_include_comments'] = true; + $GLOBALS['charset_of_file'] = 'utf-8'; + $GLOBALS['mysql_charset_map']['utf-8'] = true; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('tryQuery') + ->with('SET SQL_MODE=""'); + + $dbi->expects($this->once()) + ->method('fetchValue') + ->with('SELECT @@session.time_zone') + ->will($this->returnValue('old_tz')); + + $dbi->expects($this->once()) + ->method('query') + ->with('SET time_zone = "+00:00"'); + + $GLOBALS['dbi'] = $dbi; + + ob_start(); + $this->assertTrue( + $this->object->exportHeader() + ); + $result = ob_get_clean(); + + $this->assertContains( + 'h1C', + $result + ); + + $this->assertContains( + 'h2C', + $result + ); + + $this->assertContains( + "SET FOREIGN_KEY_CHECKS=0;\n", + $result + ); + + $this->assertContains( + "40101 SET", + $result + ); + + $this->assertContains( + "SET FOREIGN_KEY_CHECKS=0;\n" . + "SET SQL_MODE = \"NO_AUTO_VALUE_ON_ZERO\";\n" . + "SET AUTOCOMMIT = 0;\n" . + "START TRANSACTION;\n" . + "SET time_zone = \"+00:00\";\n", + $result + ); + + if ($restoreDrizzle !== 'PMANORESTORE') { + runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle); + } + + } + + /** + * Test for ExportSql::exportDBCreate + * + * @return void + */ + public function testExportDBCreate() + { + $GLOBALS['sql_compatibility'] = 'NONE'; + $GLOBALS['sql_drop_database'] = true; + $GLOBALS['sql_backquotes'] = true; + $GLOBALS['sql_create_database'] = true; + $GLOBALS['crlf'] = "\n"; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('isSystemSchema') + ->with('db') + ->will($this->returnValue(true)); + + $GLOBALS['dbi'] = $dbi; + + ob_start(); + $this->assertTrue( + $this->object->exportDBCreate('db') + ); + $result = ob_get_clean(); + + $this->assertContains( + "DROP DATABASE `db`;\n", + $result + ); + + $this->assertContains( + 'CREATE DATABASE IF NOT EXISTS `db` DEFAULT CHARACTER ' . + 'SET utf8 COLLATE utf8_general_ci;', + $result + ); + + $this->assertContains( + 'USE `db`;', + $result + ); + + // case2: no backquotes + unset($GLOBALS['sql_compatibility']); + $GLOBALS['cfg']['Server']['DisableIS'] = true; + unset($GLOBALS['sql_backquotes']); + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('fetchValue') + ->with('SHOW VARIABLES LIKE \'collation_database\'', 0, 1) + ->will($this->returnValue('testcollation')); + + $GLOBALS['dbi'] = $dbi; + + ob_start(); + $this->assertTrue( + $this->object->exportDBCreate('db') + ); + $result = ob_get_clean(); + + $this->assertContains( + "DROP DATABASE db;\n", + $result + ); + + $this->assertContains( + 'CREATE DATABASE IF NOT EXISTS db DEFAULT CHARACTER SET testcollation;', + $result + ); + + $this->assertContains( + 'USE db;', + $result + ); + } + + /** + * Test for ExportSql::exportDBHeader + * + * @return void + */ + public function testExportDBHeader() + { + $GLOBALS['sql_compatibility'] = 'MSSQL'; + $GLOBALS['sql_backquotes'] = ''; + $GLOBALS['sql_include_comments'] = true; + $GLOBALS['crlf'] = "\n"; + + ob_start(); + $this->assertTrue( + $this->object->exportDBHeader('testDB') + ); + $result = ob_get_clean(); + + $this->assertContains( + ""testDB"", + $result + ); + + // case 2 + unset($GLOBALS['sql_compatibility']); + unset($GLOBALS['sql_backquotes']); + + ob_start(); + $this->assertTrue( + $this->object->exportDBHeader('testDB') + ); + $result = ob_get_clean(); + + $this->assertContains( + "'testDB'", + $result + ); + } + + /** + * Test for ExportSql::exportDBFooter + * + * @return void + */ + public function testExportDBFooterWithNewerMySQLVersion() + { + $restoreMySQLVersion = "PMANORESTORE"; + + if (PMA_MYSQL_INT_VERSION <= 50100) { + if (! PMA_HAS_RUNKIT) { + $this->markTestSkipped( + 'Cannot redefine constant. Missing runkit extension' + ); + } else { + $restoreMySQLVersion = PMA_MYSQL_INT_VERSION; + runkit_constant_redefine('PMA_MYSQL_INT_VERSION', 50101); + } + } + + $GLOBALS['crlf'] = "\n"; + $GLOBALS['sql_constraints'] = "SqlConstraints"; + $GLOBALS['sql_structure_or_data'] = 'structure'; + $GLOBALS['sql_procedure_function'] = true; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('fetchResult') + ->with( + 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE' + . ' EVENT_SCHEMA= \'db\';' + ) + ->will($this->returnValue(array('f1', 'f2'))); + + $dbi->expects($this->at(1)) + ->method('getDefinition') + ->with('db', 'EVENT', 'f1') + ->will($this->returnValue('f1event')); + + $dbi->expects($this->at(2)) + ->method('getDefinition') + ->with('db', 'EVENT', 'f2') + ->will($this->returnValue('f2event')); + + $GLOBALS['dbi'] = $dbi; + + ob_start(); + $this->assertTrue( + $this->object->exportDBFooter('db') + ); + $result = ob_get_clean(); + + $this->assertContains( + "DELIMITER $$\n", + $result + ); + + $this->assertContains( + "DELIMITER ;\n", + $result + ); + + $this->assertContains( + "f1event$$\n", + $result + ); + + $this->assertContains( + "f2event$$\n", + $result + ); + + $this->assertContains( + "SqlConstraints", + $result + ); + + if ($restoreMySQLVersion !== "PMANORESTORE") { + runkit_constant_redefine('PMA_MYSQL_INT_VERSION', $restoreMySQLVersion); + } + } + + /** + * Test for ExportSql::exportDBFooter + * + * @return void + */ + public function testExportDBFooterWithOlderMySQLVersion() + { + $restoreMySQLVersion = "PMANORESTORE"; + + if (PMA_MYSQL_INT_VERSION > 50100) { + if (! PMA_HAS_RUNKIT) { + $this->markTestSkipped( + 'Cannot redefine constant. Missing runkit extension' + ); + } else { + $restoreMySQLVersion = PMA_MYSQL_INT_VERSION; + runkit_constant_redefine('PMA_MYSQL_INT_VERSION', 50100); + } + } + + $GLOBALS['crlf'] = "\n"; + $GLOBALS['sql_constraints'] = "SqlConstraints"; + $GLOBALS['sql_structure_or_data'] = 'structure'; + $GLOBALS['sql_procedure_function'] = true; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $GLOBALS['dbi'] = $dbi; + + ob_start(); + $this->assertTrue( + $this->object->exportDBFooter('db') + ); + $result = ob_get_clean(); + + $this->assertEquals( + 'SqlConstraints', + $result + ); + + if ($restoreMySQLVersion !== "PMANORESTORE") { + runkit_constant_redefine('PMA_MYSQL_INT_VERSION', $restoreMySQLVersion); + } + } + + /** + * Test for ExportSql::getTableDefStandIn + * + * @return void + */ + public function testGetTableDefStandIn() + { + $GLOBALS['sql_drop_table'] = true; + $GLOBALS['sql_if_not_exists'] = true; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('getColumnsFull') + ->with('db', 'view') + ->will( + $this->returnValue( + array('cname' => array('Type' => 'int')) + ) + ); + + $GLOBALS['dbi'] = $dbi; + + $result = $this->object->getTableDefStandIn('db', 'view', ""); + + $this->assertContains( + "DROP VIEW IF EXISTS `view`;", + $result + ); + + $this->assertContains( + "CREATE TABLE IF NOT EXISTS `view` (`cname` int);", + $result + ); + } + + /** + * Test for ExportSql::_getTableDefForView + * + * @return void + */ + public function testGetTableDefForView() + { + $GLOBALS['sql_drop_table'] = true; + $GLOBALS['sql_if_not_exists'] = true; + $GLOBALS['cfg']['LimitChars'] = 40; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('getColumns') + ->with('db', 'view') + ->will( + $this->returnValue( + array( + 'cname' => array( + 'Type' => 'char', + 'Collation' => 'utf-8', + 'Null' => 'NO', + 'Default' => 'a', + 'Comment' => 'cmt', + 'Field' => 'fname' + ) + ) + ) + ); + + $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'; + + $method = new ReflectionMethod('ExportSql', '_getTableDefForView'); + $method->setAccessible(true); + $result = $method->invoke( + $this->object, 'db', 'view', "\n" + ); + + $this->assertEquals( + "CREATE TABLE `view`(\n" . + " `fname` char COLLATE utf-8 NOT NULL DEFAULT 'a' COMMENT 'cmt'\n" . + ");\n", + $result + ); + + // case 2 + unset($GLOBALS['sql_compatibility']); + $result = $method->invoke( + $this->object, 'db', 'view', "\n", false + ); + + $this->assertEquals( + "CREATE TABLE IF NOT EXISTS `view`(\n" . + " `fname` char COLLATE utf-8 DEFAULT NULL COMMENT 'cmt'\n" . + ")\n", + $result + ); + } + + + /** + * Test for ExportSql::getTableDef + * + * @return void + */ + public function testGetTableDefWithoutDrizzle() + { + $restoreDrizzle = 'PMANORESTORE'; + + if (PMA_DRIZZLE) { + if (!PMA_HAS_RUNKIT) { + $this->markTestSkipped( + "Cannot redefine constant. Missing runkit extension" + ); + } else { + $restoreDrizzle = PMA_DRIZZLE; + runkit_constant_redefine('PMA_DRIZZLE', false); + } + } + + $GLOBALS['sql_compatibility'] = 'MSSQL'; + $GLOBALS['sql_auto_increment'] = true; + $GLOBALS['sql_drop_table'] = true; + $GLOBALS['sql_backquotes'] = true; + $GLOBALS['sql_if_not_exists'] = true; + $GLOBALS['sql_include_comments'] = true; + $GLOBALS['crlf'] = "\n"; + if (isset($GLOBALS['sql_constraints'])) { + unset($GLOBALS['sql_constraints']); + } + + if (isset($GLOBALS['no_constraints_comments'])) { + unset($GLOBALS['no_constraints_comments']); + } + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('query') + ->with( + 'SHOW TABLE STATUS FROM `db` LIKE \'table\'', null, + PMA_DatabaseInterface::QUERY_STORE + ) + ->will($this->returnValue('res')); + + $dbi->expects($this->never()) + ->method('fetchSingleRow'); + + $dbi->expects($this->once()) + ->method('numRows') + ->with('res') + ->will($this->returnValue(2)); + + $dbi->expects($this->any()) + ->method('fetchValue') + ->will($this->returnValue(false)); + + $tmpres = array( + 'Auto_increment' => 1, + 'Create_time' => '2000-01-01 10:00:00', + 'Update_time' => '2000-01-02 12:00:00', + 'Check_time' => '2000-01-02 13:00:00', + ); + + $dbi->expects($this->once()) + ->method('fetchAssoc') + ->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`') + ->will($this->returnValue('res')); + + $row = array( + '', + "CREATE TABLE `db`.`table`,\n CONSTRAINT KEYS \nFOREIGN KEY\n) " . + "unsigned NOT NULL\n(\r\n" + ); + + $dbi->expects($this->once()) + ->method('fetchRow') + ->with('res') + ->will($this->returnValue($row)); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['cfg']['Server']['DisableIS'] = false; + + $result = $this->object->getTableDef( + 'db', 'table', "\n", "example.com/err", true, true, true + ); + + $this->assertContains( + '-- Creation: Jan 01, 2000 at 10:00 AM', + $result + ); + + $this->assertContains( + '-- Last update: Jan 02, 2000 at 12:00 PM', + $result + ); + + $this->assertContains( + '-- Last check: Jan 02, 2000 at 01:00 PM', + $result + ); + + $this->assertContains( + 'DROP TABLE IF EXISTS `table`;', + $result + ); + + $this->assertContains( + "CREATE TABLE `table`\n", + $result + ); + + $this->assertContains( + ") NOT NULL\n", + $result + ); + + $this->assertContains( + '-- Constraints for dumped tables', + $GLOBALS['sql_constraints'] + ); + + $this->assertContains( + '-- Constraints for table "table"', + $GLOBALS['sql_constraints'] + ); + + $this->assertContains( + 'ALTER TABLE "table"' . "\n", + $GLOBALS['sql_constraints'] + ); + + $this->assertContains( + 'ADD CONSTRAINT KEYS ' . "\n", + $GLOBALS['sql_constraints'] + ); + + $this->assertContains( + 'ADD FOREIGN KEY;', + $GLOBALS['sql_constraints'] + ); + + $this->assertContains( + 'ALTER TABLE "table"' . "\n", + $GLOBALS['sql_constraints_query'] + ); + + $this->assertContains( + 'ADD CONSTRAINT KEYS ADD FOREIGN KEY;', + $GLOBALS['sql_constraints_query'] + ); + + $this->assertContains( + 'ALTER TABLE "db"."table"' . "\n", + $GLOBALS['sql_drop_foreign_keys'] + ); + + $this->assertContains( + 'DROP FOREIGN KEY KEYS', + $GLOBALS['sql_drop_foreign_keys'] + ); + + if ($restoreDrizzle !== "PMANORESTORE") { + runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle); + } + } + + /** + * Test for ExportSql::getTableDef + * + * @return void + */ + public function testGetTableDefWithDrizzle() + { + $restoreDrizzle = 'PMANORESTORE'; + + if (!PMA_DRIZZLE) { + if (!PMA_HAS_RUNKIT) { + $this->markTestSkipped( + "Cannot redefine constant. Missing runkit extension" + ); + } else { + $restoreDrizzle = PMA_DRIZZLE; + runkit_constant_redefine('PMA_DRIZZLE', true); + } + } + + $GLOBALS['sql_auto_increment'] = true; + $GLOBALS['sql_drop_table'] = true; + $GLOBALS['sql_backquotes'] = true; + $GLOBALS['sql_if_not_exists'] = true; + $GLOBALS['sql_include_comments'] = true; + $GLOBALS['crlf'] = "\n"; + + if (isset($GLOBALS['sql_compatibility'])) { + unset($GLOBALS['sql_compatibility']); + } + + if (isset($GLOBALS['sql_constraints'])) { + unset($GLOBALS['sql_constraints']); + } + + $GLOBALS['no_constraints_comments'] = true; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('query') + ->with( + 'SHOW TABLE STATUS FROM `db` LIKE \'table\'', null, + PMA_DatabaseInterface::QUERY_STORE + ) + ->will($this->returnValue('res')); + + $dbi->expects($this->once()) + ->method('numRows') + ->with('res') + ->will($this->returnValue(2)); + + $dbi->expects($this->once()) + ->method('fetchSingleRow') + ->will($this->returnValue(array())); + + $dbi->expects($this->any()) + ->method('fetchValue') + ->will($this->returnValue(false)); + + $tmpres = array( + 'Auto_increment' => 1, + 'Create_time' => '2000-01-01 10:00:00', + 'Update_time' => '2000-01-02 12:00:00', + 'Check_time' => '2000-01-02 13:00:00', + ); + + $dbi->expects($this->once()) + ->method('fetchAssoc') + ->with('res') + ->will($this->returnValue($tmpres)); + + $dbi->expects($this->once()) + ->method('tryQuery') + ->with('SHOW CREATE TABLE `db`.`table`') + ->will($this->returnValue('res')); + + $row = array( + '', + "CREATE TABLE `db`.`table` ROW_FORMAT='row',\n CONSTRAINT " + . "KEYS \nFOREIGN KEY\n) unsigned NOT NULL\n(\r" + ); + + $dbi->expects($this->once()) + ->method('fetchRow') + ->with('res') + ->will($this->returnValue($row)); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['cfg']['Server']['DisableIS'] = false; + + $result = $this->object->getTableDef( + 'db', 'table', "\n", "example.com/err", true, true, true + ); + + $this->assertContains( + "CREATE TABLE IF NOT EXISTS `table` ROW_FORMAT=row", + $result + ); + + $this->assertContains( + ") unsigned NOT NULL\n", + $result + ); + + $this->assertContains( + "AUTO_INCREMENT=1 ;", + $result + ); + + $this->assertNotContains( + '-- Constraints for table', + $GLOBALS['sql_constraints'] + ); + + $this->assertNotContains( + '-- Constraints for table "table"', + $GLOBALS['sql_constraints'] + ); + + if ($restoreDrizzle !== "PMANORESTORE") { + runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle); + } + } + + /** + * Test for ExportSql::getTableDef + * + * @return void + */ + public function testGetTableDefWithError() + { + $restoreDrizzle = 'PMANORESTORE'; + + if (PMA_DRIZZLE) { + if (!PMA_HAS_RUNKIT) { + $this->markTestSkipped( + "Cannot redefine constant. Missing runkit extension" + ); + } else { + $restoreDrizzle = PMA_DRIZZLE; + runkit_constant_redefine('PMA_DRIZZLE', false); + } + } + + $GLOBALS['sql_compatibility'] = ''; + $GLOBALS['sql_auto_increment'] = true; + $GLOBALS['sql_drop_table'] = true; + $GLOBALS['sql_backquotes'] = false; + $GLOBALS['sql_if_not_exists'] = true; + $GLOBALS['sql_include_comments'] = true; + $GLOBALS['crlf'] = "\n"; + + if (isset($GLOBALS['sql_constraints'])) { + unset($GLOBALS['sql_constraints']); + } + + if (isset($GLOBALS['no_constraints_comments'])) { + unset($GLOBALS['no_constraints_comments']); + } + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('query') + ->with( + 'SHOW TABLE STATUS FROM `db` LIKE \'table\'', null, + PMA_DatabaseInterface::QUERY_STORE + ) + ->will($this->returnValue('res')); + + $dbi->expects($this->never()) + ->method('fetchSingleRow'); + + $dbi->expects($this->once()) + ->method('numRows') + ->with('res') + ->will($this->returnValue(2)); + + $dbi->expects($this->any()) + ->method('fetchValue') + ->will($this->returnValue(false)); + + $tmpres = array( + 'Auto_increment' => 1, + 'Create_time' => '2000-01-01 10:00:00', + 'Update_time' => '2000-01-02 12:00:00', + 'Check_time' => '2000-01-02 13:00:00', + ); + + $dbi->expects($this->once()) + ->method('fetchAssoc') + ->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`') + ->will($this->returnValue('res')); + + $dbi->expects($this->once()) + ->method('getError') + ->will($this->returnValue('error occurred')); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['cfg']['Server']['DisableIS'] = false; + + $result = $this->object->getTableDef( + 'db', 'table', "\n", "example.com/err", true, true, true + ); + + $this->assertContains( + '-- in use(error occurred)', + $result + ); + + if ($restoreDrizzle !== "PMANORESTORE") { + runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle); + } + } + + /** + * Test for ExportSql::_getTableComments + * + * @return void + */ + public function testGetTableComments() + { + $_SESSION['relation'][0] = array( + 'relwork' => true, + 'commwork' => true, + 'mimework' => true, + 'db' => 'database', + 'relation' => 'rel', + 'column_info' => 'col' + ); + $GLOBALS['sql_include_comments'] = true; + $GLOBALS['crlf'] = "\n"; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('fetchResult') + ->will( + $this->returnValue( + array( + 'foo' => array( + 'foreign_table' => 'ftable', + 'foreign_field' => 'ffield' + ) + ) + ) + ); + + $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('ExportSql', '_getTableComments'); + $method->setAccessible(true); + $result = $method->invoke( + $this->object, 'db', '', "\n", true, true + ); + + $this->assertContains( + "-- MIME TYPES FOR TABLE :\n" . + "-- fieldname\n" . + "-- Test<", + $result + ); + + $this->assertContains( + "-- RELATIONS FOR TABLE :\n" . + "-- foo\n" . + "-- ftable -> ffield", + $result + ); + } + + /** + * Test for ExportSql::exportStructure + * + * @return void + */ + public function testExportStructure() + { + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('getTriggers') + ->with('db', 't&bl') + ->will( + $this->returnValue( + array( + array('create' => 'bar', 'drop' => 'foo') + ) + ) + ); + + $this->object = $this->getMockBuilder('ExportSql') + ->setMethods(array('getTableDef', 'getTriggers', 'getTableDefStandIn')) + ->getMock(); + + $this->object->expects($this->at(0)) + ->method('getTableDef') + ->with('db', 't&bl', "\n", "example.com", false) + ->will($this->returnValue('dumpText1')); + + $this->object->expects($this->at(1)) + ->method('getTableDef') + ->with( + 'db', 't&bl', "\n", "example.com", false + ) + ->will($this->returnValue('dumpText3')); + + $this->object->expects($this->once()) + ->method('getTableDefStandIn') + ->with('db', 't&bl', "\n") + ->will($this->returnValue('dumpText4')); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['sql_compatibility'] = 'MSSQL'; + $GLOBALS['sql_backquotes'] = true; + $GLOBALS['sql_include_comments'] = true; + $GLOBALS['crlf'] = "\n"; + + // case 1 + ob_start(); + $this->assertTrue( + $this->object->exportStructure( + 'db', 't&bl', "\n", "example.com", "create_table", "test" + ) + ); + $result = ob_get_clean(); + + $this->assertContains( + '-- Table structure for table "t&bl"', + $result + ); + + $this->assertContains( + 'dumpText1', + $result + ); + + // case 2 + unset($GLOBALS['sql_compatibility']); + unset($GLOBALS['sql_backquotes']); + + ob_start(); + $this->assertTrue( + $this->object->exportStructure( + 'db', 't&bl', "\n", "example.com", "triggers", "test" + ) + ); + $result = ob_get_clean(); + + $this->assertContains( + "-- Triggers 't&bl'\n", + $result + ); + + $this->assertContains( + "foo;\nDELIMITER //\nbarDELIMITER ;\n", + $result + ); + + // case 3 + $GLOBALS['sql_views_as_tables'] = false; + + ob_start(); + $this->assertTrue( + $this->object->exportStructure( + 'db', 't&bl', "\n", "example.com", "create_view", "test" + ) + ); + $result = ob_get_clean(); + + $this->assertContains( + "-- Structure for view 't&bl'\n", + $result + ); + + $this->assertContains( + "DROP TABLE IF EXISTS `t&bl`;\n" . + "dumpText3", + $result + ); + + // case 4 + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('getColumns') + ->will( + $this->returnValue( + array() + ) + ); + $GLOBALS['dbi'] = $dbi; + $GLOBALS['sql_views_as_tables'] = true; + + ob_start(); + $this->assertTrue( + $this->object->exportStructure( + 'db', 't&bl', "\n", "example.com", "create_view", "test" + ) + ); + $result = ob_get_clean(); + + $this->assertContains( + "CREATE TABLE`t&bl`(\n\n);", + $result + ); + + $this->assertContains( + "DROP TABLE IF EXISTS `t&bl`;\n", + $result + ); + + // case 5 + + ob_start(); + $this->assertTrue( + $this->object->exportStructure( + 'db', 't&bl', "\n", "example.com", "stand_in", "test" + ) + ); + $result = ob_get_clean(); + + $this->assertContains( + "dumpText4", + $result + ); + } + + /** + * Test for ExportSql::exportData + * + * @return void + */ + public function testExportData() + { + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $flags = array(); + $a = new StdClass; + $a->blob = false; + $a->numeric = true; + $a->type = 'ts'; + $a->name = 'name'; + $a->length = 2; + $flags[] = $a; + + $a = new StdClass; + $a->blob = false; + $a->numeric = true; + $a->type = 'ts'; + $a->name = 'name'; + $a->length = 2; + $flags[] = $a; + + $a = new StdClass; + $a->blob = true; + $a->numeric = false; + $a->type = 'ts'; + $a->name = 'name'; + $a->length = 2; + $flags[] = $a; + + $a = new StdClass; + $a->type = "bit"; + $a->blob = false; + $a->numeric = false; + $a->name = 'name'; + $a->length = 2; + $flags[] = $a; + + $a = new StdClass; + $a->blob = false; + $a->numeric = true; + $a->type = 'timestamp'; + $a->name = 'name'; + $a->length = 2; + $flags[] = $a; + + $dbi->expects($this->once()) + ->method('getFieldsMeta') + ->with('res') + ->will($this->returnValue($flags)); + + $dbi->expects($this->any()) + ->method('fieldFlags') + ->will($this->returnValue('biNAry')); + + $dbi->expects($this->once()) + ->method('tryQuery') + ->with( + "SELECT a FROM b WHERE 1", + null, + PMA_DatabaseInterface::QUERY_UNBUFFERED + ) + ->will($this->returnValue('res')); + + $dbi->expects($this->once()) + ->method('numFields') + ->with('res') + ->will($this->returnValue(5)); + + $dbi->expects($this->at(10)) + ->method('fetchRow') + ->with('res') + ->will( + $this->returnValue( + array(null, 'test', '10', 'foo', "\x00\x0a\x0d\x1a") + ) + ); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['sql_compatibility'] = 'MSSQL'; + $GLOBALS['sql_backquotes'] = true; + $GLOBALS['sql_views_as_tables'] = true; + $GLOBALS['sql_type'] = 'INSERT'; + $GLOBALS['sql_delayed'] = ' DELAYED'; + $GLOBALS['sql_ignore'] = true; + $GLOBALS['sql_truncate'] = true; + $GLOBALS['sql_insert_syntax'] = 'both'; + $GLOBALS['sql_hex_for_blob'] = true; + $GLOBALS['cfg']['Server']['DisableIS'] = false; + + ob_start(); + $this->object->exportData( + 'db', 'table', "\n", "example.com/err", + "SELECT a FROM b WHERE 1" + ); + $result = ob_get_clean(); + + $this->assertContains( + 'TRUNCATE TABLE "table";', + $result + ); + + $this->assertContains( + 'SET IDENTITY_INSERT "table" ON ;', + $result + ); + + $this->assertContains( + 'INSERT DELAYED IGNORE INTO "table" ("a", ' . + '"name", "name", "name", ' . + '"name") VALUES', + $result + ); + + $this->assertContains( + "(NULL, test, 0x3130, b'10', " . '\'\0\n\r\Z\');', + $result + ); + + $this->assertContains( + "SET IDENTITY_INSERT "table" OFF;", + $result + ); + + } + + /** + * Test for ExportSql::exportData + * + * @return void + */ + public function testExportDataWithUpdate() + { + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $flags = array(); + $a = new StdClass; + $a->blob = false; + $a->numeric = true; + $a->type = 'real'; + $a->name = 'name'; + $a->length = 2; + $a->table = 'tbl'; + $a->orgname = 'pma'; + $a->primary_key = 1; + $flags[] = $a; + + $a = new StdClass; + $a->blob = false; + $a->numeric = true; + $a->type = ''; + $a->name = 'name'; + $a->table = 'tbl'; + $a->orgname = 'pma'; + $a->length = 2; + $a->primary_key = 0; + $a->unique_key = 1; + $flags[] = $a; + + $dbi->expects($this->once()) + ->method('getFieldsMeta') + ->with('res') + ->will($this->returnValue($flags)); + + $dbi->expects($this->any()) + ->method('fieldFlags') + ->will($this->returnValue('biNAry')); + + $dbi->expects($this->once()) + ->method('tryQuery') + ->with( + "SELECT a FROM b WHERE 1", + null, + PMA_DatabaseInterface::QUERY_UNBUFFERED + ) + ->will($this->returnValue('res')); + + $dbi->expects($this->once()) + ->method('numFields') + ->with('res') + ->will($this->returnValue(2)); + + $dbi->expects($this->at(7)) + ->method('fetchRow') + ->with('res') + ->will( + $this->returnValue( + array(null, null) + ) + ); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['sql_compatibility'] = 'MSSQL'; + $GLOBALS['sql_backquotes'] = true; + $GLOBALS['sql_views_as_tables'] = true; + $GLOBALS['sql_type'] = 'UPDATE'; + $GLOBALS['sql_delayed'] = ' DELAYED'; + $GLOBALS['sql_ignore'] = true; + $GLOBALS['sql_truncate'] = true; + $GLOBALS['sql_insert_syntax'] = 'both'; + $GLOBALS['sql_hex_for_blob'] = true; + $GLOBALS['cfg']['Server']['DisableIS'] = false; + + ob_start(); + $this->object->exportData( + 'db', 'table', "\n", "example.com/err", + "SELECT a FROM b WHERE 1" + ); + $result = ob_get_clean(); + + $this->assertContains( + 'UPDATE IGNORE "table" SET "a" = NULL,' . + '"name" = NULL WHERE CONCAT(`tbl`.`pma`) IS NULL;', + $result + ); + + } + + /** + * Test for ExportSql::exportData + * + * @return void + */ + public function testExportDataWithIsView() + { + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('fetchResult') + ->will($this->returnValue(true)); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['cfg']['Server']['DisableIS'] = false; + $GLOBALS['sql_views_as_tables'] = false; + $GLOBALS['sql_include_comments'] = true; + $GLOBALS['crlf'] = "\n"; + + ob_start(); + $this->assertTrue( + $this->object->exportData('db', 'table', "\n", "err.com", "SELECT") + ); + $result = ob_get_clean(); + + $this->assertContains( + "-- VIEW 'table'\n", + $result + ); + + $this->assertContains( + "-- Data: None\n", + $result + ); + } + + /** + * Test for ExportSql::exportData + * + * @return void + */ + public function testExportDataWithError() + { + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('getError') + ->will($this->returnValue('err')); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['cfg']['Server']['DisableIS'] = false; + $GLOBALS['sql_views_as_tables'] = true; + $GLOBALS['sql_include_comments'] = true; + $GLOBALS['crlf'] = "\n"; + + ob_start(); + $this->assertTrue( + $this->object->exportData('db', 'table', "\n", "err.com", "SELECT") + ); + $result = ob_get_clean(); + + $this->assertContains( + "-- Error reading data: (err)\n", + $result + ); + } + + /** + * Test for ExportSql::_makeCreateTableMSSQLCompatible + * + * @return void + */ + public function testMakeCreateTableMSSQLCompatible() + { + + $query = "CREATE TABLE IF NOT EXISTS (\" date DEFAULT NULL,\n" . + "\" date DEFAULT NULL\n\" date NOT NULL,\n\" date NOT NULL\n," . + " \" date NOT NULL DEFAULT 'asd'," . + " ) unsigned NOT NULL\n, ) unsigned NOT NULL,\n" . + " ) unsigned DEFAULT NULL\n, ) unsigned DEFAULT NULL,\n" . + " ) unsigned NOT NULL DEFAULT 'dsa',\n" . + " \" int(10) DEFAULT NULL,\n" . + " \" tinyint(0) DEFAULT NULL\n" . + " \" smallint(10) NOT NULL,\n" . + " \" bigint(0) NOT NULL\n" . + " \" bigint(0) NOT NULL DEFAULT '12'\n" . + " \" float(22,2,) DEFAULT NULL,\n" . + " \" double DEFAULT NULL\n" . + " \" float(22,2,) NOT NULL,\n" . + " \" double NOT NULL\n" . + " \" double NOT NULL DEFAULT '213'\n"; + + $method = new ReflectionMethod( + 'ExportSql', '_makeCreateTableMSSQLCompatible' + ); + $method->setAccessible(true); + $result = $method->invoke( + $this->object, $query + ); + + $this->assertEquals( + "CREATE TABLE (\" datetime DEFAULT NULL,\n" . + "\" datetime DEFAULT NULL\n" . + "\" datetime NOT NULL,\n" . + "\" datetime NOT NULL\n" . + ", \" datetime NOT NULL DEFAULT 'asd', ) NOT NULL\n" . + ", ) NOT NULL,\n" . + " ) DEFAULT NULL\n" . + ", ) DEFAULT NULL,\n" . + " ) NOT NULL DEFAULT 'dsa',\n" . + " \" int DEFAULT NULL,\n" . + " \" tinyint DEFAULT NULL\n" . + " \" smallint NOT NULL,\n" . + " \" bigint NOT NULL\n" . + " \" bigint NOT NULL DEFAULT '12'\n" . + " \" float DEFAULT NULL,\n" . + " \" float DEFAULT NULL\n" . + " \" float NOT NULL,\n" . + " \" float NOT NULL\n" . + " \" float NOT NULL DEFAULT '213'\n", + $result + ); + } +} +?> diff --git a/test/classes/plugin/export/PMA_ExportTexytext_test.php b/test/classes/plugin/export/PMA_ExportTexytext_test.php new file mode 100644 index 0000000000..733a46ae94 --- /dev/null +++ b/test/classes/plugin/export/PMA_ExportTexytext_test.php @@ -0,0 +1,653 @@ +object = new ExportTexytext(); + } + + /** + * tearDown for test cases + * + * @return void + */ + public function tearDown() + { + unset($this->object); + } + + /** + * Test for ExportTexytext::setProperties + * + * @return void + */ + public function testSetProperties() + { + $method = new ReflectionMethod('ExportTexytext', 'setProperties'); + $method->setAccessible(true); + $method->invoke($this->object, null); + + $attrProperties = new ReflectionProperty('ExportTexytext', 'properties'); + $attrProperties->setAccessible(true); + $properties = $attrProperties->getValue($this->object); + + $this->assertInstanceOf( + 'ExportPluginProperties', + $properties + ); + + $this->assertEquals( + 'Texy! text', + $properties->getText() + ); + + $this->assertEquals( + 'txt', + $properties->getExtension() + ); + + $this->assertEquals( + 'text/plain', + $properties->getMimeType() + ); + + $options = $properties->getOptions(); + + $this->assertInstanceOf( + 'OptionsPropertyRootGroup', + $options + ); + + $this->assertEquals( + 'Format Specific Options', + $options->getName() + ); + + $generalOptionsArray = $options->getProperties(); + + $generalOptions = array_shift($generalOptionsArray); + + $this->assertInstanceOf( + 'OptionsPropertyMainGroup', + $generalOptions + ); + + $this->assertEquals( + 'general_opts', + $generalOptions->getName() + ); + + $this->assertEquals( + "Dump table", + $generalOptions->getText() + ); + + $generalProperties = $generalOptions->getProperties(); + + $property = array_shift($generalProperties); + + $this->assertInstanceOf( + 'RadioPropertyItem', + $property + ); + + $generalOptions = array_shift($generalOptionsArray); + + $this->assertInstanceOf( + 'OptionsPropertyMainGroup', + $generalOptions + ); + + $this->assertEquals( + 'data', + $generalOptions->getName() + ); + + $generalProperties = $generalOptions->getProperties(); + + $property = array_shift($generalProperties); + + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + $this->assertEquals( + 'columns', + $property->getName() + ); + + $property = array_shift($generalProperties); + + $this->assertInstanceOf( + 'TextPropertyItem', + $property + ); + + $this->assertEquals( + 'null', + $property->getName() + ); + } + + /** + * Test for ExportTexytext::exportHeader + * + * @return void + */ + public function testExportHeader() + { + $this->assertTrue( + $this->object->exportHeader() + ); + } + + /** + * Test for ExportTexytext::exportFooter + * + * @return void + */ + public function testExportFooter() + { + $this->assertTrue( + $this->object->exportFooter() + ); + } + + /** + * Test for ExportTexytext::exportDBHeader + * + * @return void + */ + public function testExportDBHeader() + { + $this->expectOutputString( + "===Database testDb\n\n" + ); + $this->assertTrue( + $this->object->exportDBHeader('testDb') + ); + } + + /** + * Test for ExportTexytext::exportDBFooter + * + * @return void + */ + public function testExportDBFooter() + { + $this->assertTrue( + $this->object->exportDBFooter('testDB') + ); + } + + /** + * Test for ExportTexytext::exportDBCreate + * + * @return void + */ + public function testExportDBCreate() + { + $this->assertTrue( + $this->object->exportDBCreate('testDB') + ); + } + + /** + * Test for ExportTexytext::exportData + * + * @return void + */ + public function testExportData() + { + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('query') + ->with('SELECT', null, PMA_DatabaseInterface::QUERY_UNBUFFERED) + ->will($this->returnValue(true)); + + $dbi->expects($this->once()) + ->method('numFields') + ->with(true) + ->will($this->returnValue(3)); + + $dbi->expects($this->at(2)) + ->method('fieldName') + ->will($this->returnValue('fName1')); + + $dbi->expects($this->at(3)) + ->method('fieldName') + ->will($this->returnValue('fNa"me2')); + + $dbi->expects($this->at(4)) + ->method('fieldName') + ->will($this->returnValue('fName3')); + + $dbi->expects($this->at(5)) + ->method('fetchRow') + ->with(true) + ->will($this->returnValue(array(null, '0', 'test'))); + + $GLOBALS['dbi'] = $dbi; + $GLOBALS['what'] = 'foo'; + $GLOBALS['foo_columns'] = "&"; + $GLOBALS['foo_null'] = ">"; + + ob_start(); + $this->assertTrue( + $this->object->exportData( + 'db', 'taassertContains( + "|fName1|fNa&quot;me2|fName3", + $result + ); + + $this->assertContains( + "|&gt;|0|test", + $result + ); + + } + + /** + * Test for ExportTexytext::getTableDefStandIn + * + * @return void + */ + public function testGetTableDefStandIn() + { + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('getColumns') + ->with('db', 'view') + ->will($this->returnValue(array(1, 2))); + + $keys = array( + array( + 'Non_unique' => 0, + 'Column_name' => 'cname' + ), + array( + 'Non_unique' => 1, + 'Column_name' => 'cname2' + ) + ); + + $dbi->expects($this->once()) + ->method('getTableIndexes') + ->with('db', 'view') + ->will($this->returnValue($keys)); + + $dbi->expects($this->once()) + ->method('selectDb') + ->with('db'); + + $GLOBALS['dbi'] = $dbi; + + $this->object = $this->getMockBuilder('ExportTexytext') + ->disableOriginalConstructor() + ->setMethods(array('formatOneColumnDefinition')) + ->getMock(); + + $this->object->expects($this->at(0)) + ->method('formatOneColumnDefinition') + ->with(1, array('cname')) + ->will($this->returnValue('c1')); + + $this->object->expects($this->at(1)) + ->method('formatOneColumnDefinition') + ->with(2, array('cname')) + ->will($this->returnValue('c2')); + + $result = $this->object->getTableDefStandIn('db', 'view', '#'); + + $this->assertContains( + "c1\nc2", + $result + ); + } + + /** + * Test for ExportTexytext::getTableDef + * + * @return void + */ + public function testGetTableDef() + { + $this->object = $this->getMockBuilder('ExportTexytext') + ->setMethods(array('formatOneColumnDefinition')) + ->getMock(); + + // case 1 + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $keys = array( + array( + 'Non_unique' => 0, + 'Column_name' => 'cname' + ), + array( + 'Non_unique' => 1, + 'Column_name' => 'cname2' + ) + ); + + $dbi->expects($this->once()) + ->method('getTableIndexes') + ->with('db', 'table') + ->will($this->returnValue($keys)); + + $dbi->expects($this->at(2)) + ->method('fetchResult') + ->will( + $this->returnValue( + array( + 'fname' => array( + 'foreign_table' => ' 'ffield>' + ) + ) + ) + ); + + $dbi->expects($this->at(3)) + ->method('fetchValue') + ->will( + $this->returnValue( + 'SELECT a FROM b' + ) + ); + + $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' + ); + + $dbi->expects($this->exactly(2)) + ->method('getColumns') + ->with('db', 'table') + ->will($this->returnValue(array($columns))); + + $GLOBALS['dbi'] = $dbi; + + $this->object->expects($this->exactly(1)) + ->method('formatOneColumnDefinition') + ->with(array('Field' => 'fname', 'Comment' => 'comm'), array('cname')) + ->will($this->returnValue(1)); + + $GLOBALS['cfgRelation']['relation'] = true; + $_SESSION['relation'][0] = array( + 'relwork' => true, + 'commwork' => true, + 'mimework' => true, + 'db' => 'db', + 'relation' => 'rel', + 'column_info' => 'col' + ); + + $result = $this->object->getTableDef( + 'db', + 'table', + "\n", + "example.com", + true, + true, + true + ); + + $this->assertContains( + '1|<ftable (ffield>)|comm|Test<', + $result + ); + } + + /** + * Test for ExportTexytext::getTriggers + * + * @return void + */ + public function testGetTriggers() + { + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $triggers = array( + array( + 'name' => 'tna"me', + 'action_timing' => 'ac>t', + 'event_manipulation' => 'manip&', + 'definition' => 'def' + ) + ); + + $dbi->expects($this->once()) + ->method('getTriggers') + ->with('database', 'tawill($this->returnValue($triggers)); + + $GLOBALS['dbi'] = $dbi; + + $result = $this->object->getTriggers('database', 'taassertContains( + '|tna"me|ac>t|manip&|def', + $result + ); + + $this->assertContains( + '|Name|Time|Event|Definition', + $result + ); + + } + + /** + * Test for ExportTexytext::exportStructure + * + * @return void + */ + public function testExportStructure() + { + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('getTriggers') + ->with('db', 't&bl') + ->will($this->returnValue(1)); + + $this->object = $this->getMockBuilder('ExportTexytext') + ->setMethods(array('getTableDef', 'getTriggers', 'getTableDefStandIn')) + ->getMock(); + + $this->object->expects($this->at(0)) + ->method('getTableDef') + ->with('db', 't&bl', "\n", "example.com", false, false, false, false) + ->will($this->returnValue('dumpText1')); + + $this->object->expects($this->once()) + ->method('getTriggers') + ->with('db', 't&bl') + ->will($this->returnValue('dumpText2')); + + $this->object->expects($this->at(2)) + ->method('getTableDef') + ->with( + 'db', 't&bl', "\n", "example.com", + false, false, false, false, true, true + ) + ->will($this->returnValue('dumpText3')); + + $this->object->expects($this->once()) + ->method('getTableDefStandIn') + ->with('db', 't&bl', "\n") + ->will($this->returnValue('dumpText4')); + + $GLOBALS['dbi'] = $dbi; + + // case 1 + ob_start(); + $this->assertTrue( + $this->object->exportStructure( + 'db', 't&bl', "\n", "example.com", "create_table", "test" + ) + ); + $result = ob_get_clean(); + + $this->assertContains( + '== Table structure for table t&bl' . "\n\ndumpText1", + $result + ); + + // case 2 + ob_start(); + $this->assertTrue( + $this->object->exportStructure( + 'db', 't&bl', "\n", "example.com", "triggers", "test" + ) + ); + $result = ob_get_clean(); + + $this->assertEquals( + '== Triggers t&bl' . "\n\ndumpText2", + $result + ); + + // case 3 + ob_start(); + $this->assertTrue( + $this->object->exportStructure( + 'db', 't&bl', "\n", "example.com", "create_view", "test" + ) + ); + $result = ob_get_clean(); + + $this->assertEquals( + '== Structure for view t&bl' . "\n\ndumpText3", + $result + ); + + // case 4 + ob_start(); + $this->assertTrue( + $this->object->exportStructure( + 'db', 't&bl', "\n", "example.com", "stand_in", "test" + ) + ); + $result = ob_get_clean(); + + $this->assertEquals( + '== Stand-in structure for view t&bl' . "\n\ndumpText4", + $result + ); + } + + /** + * Test for ExportTexytext::formatOneColumnDefinition + * + * @return void + */ + public function testFormatOneColumnDefinition() + { + $GLOBALS['cfg']['LimitChars'] = 40; + + $cols = array( + 'Null' => 'Yes', + 'Field' => 'field', + 'Key' => 'PRI', + 'Type' => 'set(abc)enum123' + ); + + $unique_keys = array( + 'field' + ); + + $this->assertEquals( + '|//**field**//|set(abc)|Yes|NULL', + $this->object->formatOneColumnDefinition($cols, $unique_keys) + ); + + $cols = array( + 'Null' => 'NO', + 'Field' => 'fields', + 'Key' => 'COMP', + 'Type' => '', + 'Default' => 'def' + ); + + $unique_keys = array( + 'field' + ); + + $this->assertEquals( + '|fields|&nbsp;|No|def', + $this->object->formatOneColumnDefinition($cols, $unique_keys) + ); + } +} +?> diff --git a/test/classes/plugin/export/PMA_ExportXml_test.php b/test/classes/plugin/export/PMA_ExportXml_test.php new file mode 100644 index 0000000000..822edd042c --- /dev/null +++ b/test/classes/plugin/export/PMA_ExportXml_test.php @@ -0,0 +1,704 @@ +object = new ExportXml(); + } + + /** + * tearDown for test cases + * + * @return void + */ + public function tearDown() + { + unset($this->object); + } + + /** + * Test for ExportXml::setProperties + * + * @return void + */ + public function testSetProperties() + { + $restoreDrizzle = 'PMANORESTORE'; + + if (PMA_DRIZZLE) { + if (!PMA_HAS_RUNKIT) { + $this->markTestSkipped( + "Cannot redefine constant. Missing runkit extension" + ); + } else { + $restoreDrizzle = PMA_DRIZZLE; + runkit_constant_redefine('PMA_DRIZZLE', false); + } + } + + $method = new ReflectionMethod('ExportXml', 'setProperties'); + $method->setAccessible(true); + $method->invoke($this->object, null); + + $attrProperties = new ReflectionProperty('ExportXml', 'properties'); + $attrProperties->setAccessible(true); + $properties = $attrProperties->getValue($this->object); + + $this->assertInstanceOf( + 'ExportPluginProperties', + $properties + ); + + $this->assertEquals( + 'XML', + $properties->getText() + ); + + $this->assertEquals( + 'xml', + $properties->getExtension() + ); + + $this->assertEquals( + 'text/xml', + $properties->getMimeType() + ); + + $options = $properties->getOptions(); + + $this->assertInstanceOf( + 'OptionsPropertyRootGroup', + $options + ); + + $this->assertEquals( + 'Format Specific Options', + $options->getName() + ); + + $generalOptionsArray = $options->getProperties(); + + $generalOptions = array_shift($generalOptionsArray); + + $this->assertInstanceOf( + 'OptionsPropertyMainGroup', + $generalOptions + ); + + $this->assertEquals( + 'general_opts', + $generalOptions->getName() + ); + + $generalProperties = $generalOptions->getProperties(); + + $property = array_shift($generalProperties); + + $this->assertInstanceOf( + 'HiddenPropertyItem', + $property + ); + + $generalOptions = array_shift($generalOptionsArray); + + $this->assertInstanceOf( + 'OptionsPropertyMainGroup', + $generalOptions + ); + + $this->assertEquals( + 'structure', + $generalOptions->getName() + ); + + $generalProperties = $generalOptions->getProperties(); + + $property = array_shift($generalProperties); + + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + $property = array_shift($generalProperties); + + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + $property = array_shift($generalProperties); + + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + $property = array_shift($generalProperties); + + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + $property = array_shift($generalProperties); + + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + $generalOptions = array_shift($generalOptionsArray); + + $this->assertInstanceOf( + 'OptionsPropertyMainGroup', + $generalOptions + ); + + $this->assertEquals( + 'data', + $generalOptions->getName() + ); + + $generalProperties = $generalOptions->getProperties(); + + $property = array_shift($generalProperties); + + $this->assertInstanceOf( + 'BoolPropertyItem', + $property + ); + + if ($restoreDrizzle !== "PMANORESTORE") { + runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle); + } + } + + /** + * Test for ExportXml::exportHeader + * + * @return void + */ + public function testExportHeaderWithoutDrizzle() + { + $restoreDrizzle = 'PMANORESTORE'; + + if (PMA_DRIZZLE) { + if (!PMA_HAS_RUNKIT) { + $this->markTestSkipped( + "Cannot redefine constant. Missing runkit extension" + ); + } else { + $restoreDrizzle = PMA_DRIZZLE; + runkit_constant_redefine('PMA_DRIZZLE', false); + } + } + + $GLOBALS['xml_export_functions'] = 1; + $GLOBALS['xml_export_contents'] = 1; + $GLOBALS['output_charset_conversion'] = 1; + $GLOBALS['charset_of_file'] = 'iso-8859-1'; + $GLOBALS['cfg']['Server']['port'] = 80; + $GLOBALS['cfg']['Server']['host'] = 'localhost'; + $GLOBALS['cfg']['Server']['DisableIS'] = false; + $GLOBALS['xml_export_tables'] = 1; + $GLOBALS['xml_export_triggers'] = 1; + $GLOBALS['xml_export_procedures'] = 1; + $GLOBALS['xml_export_functions'] = 1; + $GLOBALS['crlf'] = "\n"; + $GLOBALS['db'] = 'd<"b'; + + $result = array( + 0 => array( + 'DEFAULT_COLLATION_NAME' => 'utf8_general_ci', + 'DEFAULT_CHARACTER_SET_NAME' => 'utf-8', + + ), + 'table' => array(null, '"tbl"') + ); + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('fetchResult') + ->with( + 'SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`' + . ' FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`' + . ' = \'d<"b\' LIMIT 1' + ) + ->will($this->returnValue($result)); + + $dbi->expects($this->at(1)) + ->method('fetchResult') + ->with( + 'SHOW CREATE TABLE `d<"b`.`table`', + 0 + ) + ->will($this->returnValue($result)); + + // isView + $dbi->expects($this->at(2)) + ->method('fetchResult') + ->will($this->returnValue(false)); + + $dbi->expects($this->at(3)) + ->method('getTriggers') + ->with('d<"b', 'table') + ->will( + $this->returnValue( + array( + array( + 'create' => 'crt', + 'name' => 'trname' + ) + ) + ) + ); + + $dbi->expects($this->at(4)) + ->method('getProceduresOrFunctions') + ->with('d<"b', 'FUNCTION') + ->will( + $this->returnValue( + array( + 'fn' + ) + ) + ); + + $dbi->expects($this->at(5)) + ->method('getDefinition') + ->with('d<"b', 'FUNCTION', 'fn') + ->will( + $this->returnValue( + 'fndef' + ) + ); + + $dbi->expects($this->at(6)) + ->method('getProceduresOrFunctions') + ->with('d<"b', 'PROCEDURE') + ->will( + $this->returnValue( + array( + 'pr' + ) + ) + ); + + $dbi->expects($this->at(7)) + ->method('getDefinition') + ->with('d<"b', 'PROCEDURE', 'pr') + ->will( + $this->returnValue( + 'prdef' + ) + ); + + $GLOBALS['dbi'] = $dbi; + + $GLOBALS['tables'] = array(); + $GLOBALS['table'] = 'table'; + + ob_start(); + $this->assertTrue( + $this->object->exportHeader() + ); + $result = ob_get_clean(); + + $this->assertContains( + '<pma_xml_export version="1.0" xmlns:pma="' . + 'http://www.phpmyadmin.net/some_doc_url/">', + $result + ); + + $this->assertContains( + '<pma:structure_schemas>' . "\n" . + ' <pma:database name="d&lt;&quot;b" collat' . + 'ion="utf8_general_ci" charset="utf-8">' . "\n" . + ' <pma:table name="table">' . "\n" . + ' &quot;tbl&quot;;' . "\n" . + ' </pma:table>' . "\n" . + ' <pma:trigger name="trname">' . "\n" . + ' ' . "\n" . + ' </pma:trigger>' . "\n" . + ' <pma:function name="fn">' . "\n" . + ' fndef' . "\n" . + ' </pma:function>' . "\n" . + ' <pma:procedure name="pr">' . "\n" . + ' prdef' . "\n" . + ' </pma:procedure>' . "\n" . + ' </pma:database>' . "\n" . + ' </pma:structure_schemas>', + $result + ); + + // case 2 with isView as true and false + + unset($GLOBALS['xml_export_contents']); + unset($GLOBALS['xml_export_views']); + unset($GLOBALS['xml_export_tables']); + unset($GLOBALS['xml_export_functions']); + unset($GLOBALS['xml_export_procedures']); + $GLOBALS['output_charset_conversion'] = 0; + + $result = array( + array( + 'DEFAULT_COLLATION_NAME' => 'utf8_general_ci', + 'DEFAULT_CHARACTER_SET_NAME' => 'utf-8', + + ) + ); + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('fetchResult') + ->with( + 'SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`' + . ' FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`' + . ' = \'d<"b\' LIMIT 1' + ) + ->will($this->returnValue($result)); + + $result = array( + 't1' => array(null, '"tbl"') + ); + + $dbi->expects($this->at(1)) + ->method('fetchResult') + ->with( + 'SHOW CREATE TABLE `d<"b`.`t1`', + 0 + ) + ->will($this->returnValue($result)); + + // isView + $dbi->expects($this->at(2)) + ->method('fetchResult') + ->will($this->returnValue(true)); + + $result = array( + 't2' => array(null, '"tbl"') + ); + + $dbi->expects($this->at(3)) + ->method('fetchResult') + ->with( + 'SHOW CREATE TABLE `d<"b`.`t2`', + 0 + ) + ->will($this->returnValue($result)); + + // isView + $dbi->expects($this->at(4)) + ->method('fetchResult') + ->will($this->returnValue(false)); + + $GLOBALS['dbi'] = $dbi; + + $GLOBALS['tables'] = array('t1', 't2'); + + ob_start(); + $this->assertTrue( + $this->object->exportHeader() + ); + $result = ob_get_clean(); + + //echo $result; die; + $this->assertContains( + '<pma:structure_schemas>' . "\n" . + ' <pma:database name="d&lt;&quot;b" collat' . + 'ion="utf8_general_ci" charset="utf-8">' . "\n" . + ' </pma:database>' . "\n" . + ' </pma:structure_schemas>', + $result + ); + + if ($restoreDrizzle !== "PMANORESTORE") { + runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle); + } + } + + /** + * Test for ExportXml::exportHeader + * + * @return void + */ + public function testExportHeaderWithDrizzle() + { + $restoreDrizzle = 'PMANORESTORE'; + + if (!PMA_DRIZZLE) { + if (!PMA_HAS_RUNKIT) { + $this->markTestSkipped( + "Cannot redefine constant. Missing runkit extension" + ); + } else { + $restoreDrizzle = PMA_DRIZZLE; + runkit_constant_redefine('PMA_DRIZZLE', true); + } + } + + $GLOBALS['output_charset_conversion'] = false; + $GLOBALS['xml_export_triggers'] = true; + $GLOBALS['cfg']['Server']['port'] = 80; + $GLOBALS['cfg']['Server']['host'] = 'localhost'; + $GLOBALS['cfg']['Server']['DisableIS'] = false; + $GLOBALS['crlf'] = "\n"; + $GLOBALS['db'] = 'd array( + 'DEFAULT_COLLATION_NAME' => 'utf8_general_ci', + 'DEFAULT_CHARACTER_SET_NAME' => 'utf-8', + + ), + 'table' => array(null, '"tbl"') + ); + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('fetchResult') + ->with( + "SELECT + 'utf8' AS DEFAULT_CHARACTER_SET_NAME, + DEFAULT_COLLATION_NAME + FROM data_dictionary.SCHEMAS + WHERE SCHEMA_NAME = 'dwill($this->returnValue($result)); + + $dbi->expects($this->at(1)) + ->method('fetchResult') + ->with( + 'SHOW CREATE TABLE `dwill($this->returnValue($result)); + + // isView + $dbi->expects($this->at(2)) + ->method('fetchResult') + ->will($this->returnValue(false)); + + + $GLOBALS['dbi'] = $dbi; + + $GLOBALS['tables'] = array(); + $GLOBALS['table'] = 'table'; + + ob_start(); + $this->assertTrue( + $this->object->exportHeader() + ); + $result = ob_get_clean(); + + if ($restoreDrizzle !== "PMANORESTORE") { + runkit_constant_redefine('PMA_DRIZZLE', $restoreDrizzle); + } + } + + /** + * Test for ExportXml::exportFooter + * + * @return void + */ + public function testExportFooter() + { + $this->expectOutputString( + '</pma_xml_export>' + ); + $this->assertTrue( + $this->object->exportFooter() + ); + } + + /** + * Test for ExportXml::exportDBHeader + * + * @return void + */ + public function testExportDBHeader() + { + $GLOBALS['xml_export_contents'] = true; + + ob_start(); + $this->assertTrue( + $this->object->exportDBHeader('&db') + ); + $result = ob_get_clean(); + + $this->assertContains( + '<database name="&amp;db">', + $result + ); + + $GLOBALS['xml_export_contents'] = false; + + $this->assertTrue( + $this->object->exportDBHeader('&db') + ); + } + + /** + * Test for ExportXml::exportDBFooter + * + * @return void + */ + public function testExportDBFooter() + { + $GLOBALS['xml_export_contents'] = true; + + ob_start(); + $this->assertTrue( + $this->object->exportDBFooter('&db') + ); + $result = ob_get_clean(); + + $this->assertContains( + '</database>', + $result + ); + + $GLOBALS['xml_export_contents'] = false; + + $this->assertTrue( + $this->object->exportDBFooter('&db') + ); + } + + /** + * Test for ExportXml::exportDBCreate + * + * @return void + */ + public function testExportDBCreate() + { + $this->assertTrue( + $this->object->exportDBCreate('testDB') + ); + } + + /** + * Test for ExportXml::exportData + * + * @return void + */ + public function testExportData() + { + $GLOBALS['xml_export_contents'] = true; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('query') + ->with('SELECT', null, PMA_DatabaseInterface::QUERY_UNBUFFERED) + ->will($this->returnValue(true)); + + $dbi->expects($this->once()) + ->method('numFields') + ->with(true) + ->will($this->returnValue(3)); + + $dbi->expects($this->at(2)) + ->method('fieldName') + ->will($this->returnValue('fName1')); + + $dbi->expects($this->at(3)) + ->method('fieldName') + ->will($this->returnValue('fNa"me2')); + + $dbi->expects($this->at(4)) + ->method('fieldName') + ->will($this->returnValue('fNa\\me3')); + + $dbi->expects($this->at(5)) + ->method('fetchRow') + ->with(true) + ->will($this->returnValue(array(null, ''))); + + $GLOBALS['dbi'] = $dbi; + + ob_start(); + $this->assertTrue( + $this->object->exportData( + 'db', 'taassertContains( + "<!-- Table ta<ble -->", + $result + ); + + $this->assertContains( + "<table name="ta&lt;ble">", + $result + ); + + $this->assertContains( + "<column name="fName1">NULL</column>", + $result + ); + + $this->assertContains( + "<column name="fNa&quot;me2">&lt;a&gt;" . + "</column>", + $result + ); + + $this->assertContains( + "<column name="fName3">NULL</column>", + $result + ); + + $this->assertContains( + "</table>", + $result + ); + } +} +?> diff --git a/test/classes/plugin/export/PMA_ExportYaml_test.php b/test/classes/plugin/export/PMA_ExportYaml_test.php new file mode 100644 index 0000000000..eeeb75f034 --- /dev/null +++ b/test/classes/plugin/export/PMA_ExportYaml_test.php @@ -0,0 +1,267 @@ +object = new ExportYaml(); + } + + /** + * tearDown for test cases + * + * @return void + */ + public function tearDown() + { + unset($this->object); + } + + /** + * Test for ExportYaml::setProperties + * + * @return void + */ + public function testSetProperties() + { + $method = new ReflectionMethod('ExportYaml', 'setProperties'); + $method->setAccessible(true); + $method->invoke($this->object, null); + + $attrProperties = new ReflectionProperty('ExportYaml', 'properties'); + $attrProperties->setAccessible(true); + $properties = $attrProperties->getValue($this->object); + + $this->assertInstanceOf( + 'ExportPluginProperties', + $properties + ); + + $this->assertEquals( + 'YAML', + $properties->getText() + ); + + $this->assertEquals( + 'yml', + $properties->getExtension() + ); + + $this->assertEquals( + 'text/yaml', + $properties->getMimeType() + ); + + $options = $properties->getOptions(); + + $this->assertInstanceOf( + 'OptionsPropertyRootGroup', + $options + ); + + $this->assertEquals( + 'Format Specific Options', + $options->getName() + ); + + $generalOptionsArray = $options->getProperties(); + + $generalOptions = array_shift($generalOptionsArray); + + $this->assertInstanceOf( + 'OptionsPropertyMainGroup', + $generalOptions + ); + + $this->assertEquals( + 'general_opts', + $generalOptions->getName() + ); + + $generalProperties = $generalOptions->getProperties(); + + $property = array_shift($generalProperties); + + $this->assertInstanceOf( + 'HiddenPropertyItem', + $property + ); + } + + /** + * Test for ExportYaml::exportHeader + * + * @return void + */ + public function testExportHeader() + { + ob_start(); + $this->assertTrue( + $this->object->exportHeader() + ); + $result = ob_get_clean(); + + $this->assertContains( + "%YAML 1.1\n---\n", + $result + ); + } + + /** + * Test for ExportYaml::exportFooter + * + * @return void + */ + public function testExportFooter() + { + $this->expectOutputString( + "...\n" + ); + $this->assertTrue( + $this->object->exportFooter() + ); + } + + /** + * Test for ExportYaml::exportDBHeader + * + * @return void + */ + public function testExportDBHeader() + { + $this->assertTrue( + $this->object->exportDBHeader('&db') + ); + } + + /** + * Test for ExportYaml::exportDBFooter + * + * @return void + */ + public function testExportDBFooter() + { + $this->assertTrue( + $this->object->exportDBFooter('&db') + ); + } + + /** + * Test for ExportYaml::exportDBCreate + * + * @return void + */ + public function testExportDBCreate() + { + $this->assertTrue( + $this->object->exportDBCreate('testDB') + ); + } + + /** + * Test for ExportYaml::exportData + * + * @return void + */ + public function testExportData() + { + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('query') + ->with('SELECT', null, PMA_DatabaseInterface::QUERY_UNBUFFERED) + ->will($this->returnValue(true)); + + $dbi->expects($this->once()) + ->method('numFields') + ->with(true) + ->will($this->returnValue(4)); + + $dbi->expects($this->at(2)) + ->method('fieldName') + ->will($this->returnValue('fName1')); + + $dbi->expects($this->at(3)) + ->method('fieldName') + ->will($this->returnValue('fNa"me2')); + + $dbi->expects($this->at(4)) + ->method('fieldName') + ->will($this->returnValue('fNa\\me3')); + + $dbi->expects($this->at(5)) + ->method('fieldName') + ->will($this->returnValue('fName4')); + + $dbi->expects($this->at(6)) + ->method('fetchRow') + ->with(true) + ->will( + $this->returnValue( + array(null, '123', "\"c\\a\nb\r") + ) + ); + + $dbi->expects($this->at(7)) + ->method('fetchRow') + ->with(true) + ->will( + $this->returnValue( + array(null) + ) + ); + + $GLOBALS['dbi'] = $dbi; + + ob_start(); + $this->assertTrue( + $this->object->exportData( + 'db', 'taassertEquals( + '# db.ta<ble' . "\n" . + '-' . "\n" . + ' fNa"me2: 123' . "\n" . + ' fName3: "\"c\\\\a\nb\r"' . "\n" . + '-' . "\n", + $result + ); + } +} +?> From 6fa3f66d86090d736a671ba3724a58a9df869d4d Mon Sep 17 00:00:00 2001 From: ayushchd Date: Wed, 7 Aug 2013 00:01:19 +0530 Subject: [PATCH 03/53] Test for TableProperty class --- .../plugin/export/PMA_TableProperty_test.php | 346 ++++++++++++++++++ 1 file changed, 346 insertions(+) create mode 100644 test/classes/plugin/export/PMA_TableProperty_test.php diff --git a/test/classes/plugin/export/PMA_TableProperty_test.php b/test/classes/plugin/export/PMA_TableProperty_test.php new file mode 100644 index 0000000000..a62441004e --- /dev/null +++ b/test/classes/plugin/export/PMA_TableProperty_test.php @@ -0,0 +1,346 @@ +object = new TableProperty($row); + } + + /** + * tearDown for test cases + * + * @return void + */ + public function tearDown() + { + unset($this->object); + } + + /** + * Test for TableProperty::__construct + * + * @return void + */ + public function testConstructor() + { + $this->assertEquals( + 'name', + $this->object->name + ); + + $this->assertEquals( + 'int', + $this->object->type + ); + + $this->assertEquals( + 1, + $this->object->nullable + ); + + $this->assertEquals( + 'PRI', + $this->object->key + ); + + $this->assertEquals( + '0', + $this->object->defaultValue + ); + + $this->assertEquals( + 'mysql', + $this->object->ext + ); + } + + /** + * Test for TableProperty::getPureType + * + * @return void + */ + public function testGetPureType() + { + $this->object->type = "int(10)"; + + $this->assertEquals( + "int", + $this->object->getPureType() + ); + + $this->object->type = "char"; + + $this->assertEquals( + "char", + $this->object->getPureType() + ); + } + + /** + * Test for TableProperty::isNotNull + * + * @param string $nullable nullable value + * @param string $expected expected output + * + * @return void + * @dataProvider isNotNullProvider + */ + public function testIsNotNull($nullable, $expected) + { + $this->object->nullable = $nullable; + + $this->assertEquals( + $expected, + $this->object->isNotNull() + ); + } + + /** + * Data provider for testIsNotNull + * + * @return array Test Data + */ + public function isNotNullProvider() + { + return array( + array("NO", "true"), + array("", "false"), + array("no", "false") + ); + } + + /** + * Test for TableProperty::isUnique + * + * @param string $key key value + * @param string $expected expected output + * + * @return void + * @dataProvider isUniqueProvider + */ + public function testIsUnique($key, $expected) + { + $this->object->key = $key; + + $this->assertEquals( + $expected, + $this->object->isUnique() + ); + } + + /** + * Data provider for testIsUnique + * + * @return array Test Data + */ + public function isUniqueProvider() + { + return array( + array("PRI", "true"), + array("UNI", "true"), + array("", "false"), + array("pri", "false"), + array("uni", "false"), + ); + } + + /** + * Test for TableProperty::getDotNetPrimitiveType + * + * @param string $type type value + * @param string $expected expected output + * + * @return void + * @dataProvider getDotNetPrimitiveTypeProvider + */ + public function testGetDotNetPrimitiveType($type, $expected) + { + $this->object->type = $type; + + $this->assertEquals( + $expected, + $this->object->getDotNetPrimitiveType() + ); + } + + /** + * Data provider for testGetDotNetPrimitiveType + * + * @return array Test Data + */ + public function getDotNetPrimitiveTypeProvider() + { + return array( + array("int", "int"), + array("long", "long"), + array("char", "string"), + array("varchar", "string"), + array("text", "string"), + array("longtext", "long"), // TODO: seemingly wrong, should be string + array("tinyint", "bool"), + array("datetime", "DateTime"), + array("", "unknown"), + array("dummy", "unknown"), + array("INT", "unknown") + ); + } + + /** + * Test for TableProperty::getDotNetObjectType + * + * @param string $type type value + * @param string $expected expected output + * + * @return void + * @dataProvider getDotNetObjectTypeProvider + */ + public function testGetDotNetObjectType($type, $expected) + { + $this->object->type = $type; + + $this->assertEquals( + $expected, + $this->object->getDotNetObjectType() + ); + } + + /** + * Data provider for testGetDotNetObjectType + * + * @return array Test Data + */ + public function getDotNetObjectTypeProvider() + { + return array( + array("int", "Int32"), + array("long", "Long"), + array("char", "String"), + array("varchar", "String"), + array("text", "String"), + array("longtext", "Long"), // TODO: seemingly wrong, should be string + array("tinyint", "Boolean"), + array("datetime", "DateTime"), + array("", "Unknown"), + array("dummy", "Unknown"), + array("INT", "Unknown") + ); + } + + /** + * Test for TableProperty::getIndexName + * + * @return void + */ + public function testGetIndexName() + { + $this->object->name = "ä'7"; + $this->object->key = "PRI"; + + $this->assertEquals( + "index=\"ä'7<ab>\"", + $this->object->getIndexName() + ); + + $this->object->key = ""; + + $this->assertEquals( + "", + $this->object->getIndexName() + ); + } + + /** + * Test for TableProperty::isPK + * + * @return void + */ + public function testIsPK() + { + $this->object->key = "PRI"; + + $this->assertTrue( + $this->object->isPK() + ); + + $this->object->key = ""; + + $this->assertFalse( + $this->object->isPK() + ); + } + + /** + * Test for TableProperty::formatCs + * + * @return void + */ + public function testFormatCs() + { + $this->object->name = 'Name#name#123'; + + $this->assertEquals( + 'text123Namename', + $this->object->formatCs("text123#name#") + ); + } + + /** + * Test for TableProperty::formatXml + * + * @return void + */ + public function testFormatXml() + { + $this->object->name = '"a\''; + + $this->assertEquals( + '"a\'index=""a\'"', + $this->object->formatXml("#name##indexName#") + ); + } + + /** + * Test for TableProperty::format + * + * @return void + */ + public function testFormat() + { + $this->assertEquals( + 'NameintInt32intfalsetrue', + $this->object->format( + "#ucfirstName##dotNetPrimitiveType##dotNetObjectType##type#" . + "#notNull##unique#" + ) + ); + } + +} +?> From b9d42e27939cac6beb47b9dc40d85faf9476f82a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jouni=20K=C3=A4hk=C3=B6nen?= Date: Thu, 8 Aug 2013 12:25:55 +0200 Subject: [PATCH 04/53] Translated using Weblate (Finnish) Currently translated at 74.6% (1947 of 2609) --- po/fi.po | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/po/fi.po b/po/fi.po index aa6ef3a7df..479f0f5025 100644 --- a/po/fi.po +++ b/po/fi.po @@ -4,8 +4,8 @@ msgstr "" "Project-Id-Version: phpMyAdmin 4.0.6-dev\n" "Report-Msgid-Bugs-To: phpmyadmin-devel@lists.sourceforge.net\n" "POT-Creation-Date: 2013-07-29 15:07+0200\n" -"PO-Revision-Date: 2013-08-01 14:07+0200\n" -"Last-Translator: Michal Čihař \n" +"PO-Revision-Date: 2013-08-08 12:25+0200\n" +"Last-Translator: Jouni Kähkönen \n" "Language-Team: Finnish \n" "Language: fi\n" "MIME-Version: 1.0\n" @@ -718,7 +718,7 @@ msgstr "Palvelinyhteyden aakkosjärjestys" #: index.php:185 msgid "Appearance Settings" -msgstr "Näkymäasetukset" +msgstr "Ulkoasuasetukset" #: index.php:215 prefs_manage.php:275 msgid "More settings" @@ -4652,7 +4652,7 @@ msgstr "Navigointi paneeli" #: libraries/config/messages.inc.php:180 #| msgid "Customize appearance of the navigation frame" msgid "Customize appearance of the navigation panel" -msgstr "Mukauta navigointi paneelin näkymää" +msgstr "Mukauta navigointipalkin näkymää" #: libraries/config/messages.inc.php:181 libraries/select_server.lib.php:42 #: setup/frames/index.inc.php:117 From 2784f4b6f432c35a682bcddafb0a0d04650e150f Mon Sep 17 00:00:00 2001 From: Supun Nakandala Date: Sun, 11 Aug 2013 21:11:42 +0530 Subject: [PATCH 05/53] no need to initialize --- libraries/tbl_columns_definition_form.inc.php | 415 +++++++++--------- 1 file changed, 206 insertions(+), 209 deletions(-) diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 8f99660713..51ffa49747 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -1,209 +1,206 @@ - $fulltext_indexkey) { - $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey; - } -} - -for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { - if (! empty($regenerate)) { - list($columnMeta, $submit_length, $submit_attribute, - $submit_default_current_timestamp, $comments_map, $mime_map) - = PMA_handleRegeneration( - isset($available_mime) ? $mime_map : null, - $comments_map, $mime_map - ); - } elseif (isset($fields_meta[$columnNumber])) { - $columnMeta = PMA_getColumnMetaForDefault( - $fields_meta[$columnNumber], - isset($analyzed_sql[0]['create_table_fields'] - [$fields_meta[$columnNumber]['Field']]['default_value']) - ); - } - - if (isset($columnMeta['Type'])) { - $extracted_columnspec = PMA_Util::extractColumnSpec($columnMeta['Type']); - if ($extracted_columnspec['type'] == 'bit') { - $columnMeta['Default'] - = PMA_Util::convertBitDefaultValue($columnMeta['Default']); - } - } - - if (empty($columnMeta['Type'])) { - // creating a column - $columnMeta['Type'] = ''; - $type = ''; - $length = ''; - } else { - $type = $extracted_columnspec['type']; - $length = $extracted_columnspec['spec_in_brackets']; - } - - // some types, for example longtext, are reported as - // "longtext character set latin7" when their charset and / or collation - // differs from the ones of the corresponding database. - $tmp = strpos($type, 'character set'); - if ($tmp) { - $type = substr($type, 0, $tmp - 1); - } - - if (isset($submit_length) && $submit_length != false) { - $length = $submit_length; - } - - // rtrim the type, for cases like "float unsigned" - $type = rtrim($type); - $type_upper = strtoupper($type); - - - // old column attributes - if ($is_backup) { - if (isset($columnMeta['Field'])) { - $_form_params['field_orig[' . $columnNumber . ']'] - = $columnMeta['Field']; - } else { - $_form_params['field_orig[' . $columnNumber . ']'] = ''; - } - // old column length - $_form_params['field_length_orig[' . $columnNumber . ']'] = $length; - - // old column default - $_form_params['field_default_orig[' . $columnNumber . ']'] - = (isset($columnMeta['Default']) ? $columnMeta['Default'] : ''); - } - - $content_cells[$columnNumber] = PMA_getHtmlForColumnAttributes( - $columnNumber, isset($columnMeta) ? $columnMeta : null, $type_upper, - $length_values_input_size, $length, - isset($default_current_timestamp) ? $default_current_timestamp : null, - isset($extracted_columnspec) ? $extracted_columnspec : null, - isset($submit_attribute) ? $submit_attribute : null, - isset($analyzed_sql) ? $analyzed_sql : null, - isset($submit_default_current_timestamp) - ? $submit_default_current_timestamp : null, - $comments_map, isset($fields_meta) ? $fields_meta : null, $is_backup, - isset($move_columns) ? $move_columns : null, $cfgRelation, $available_mime, - $mime_map - ); -} // end for - -/** - * needs to be finished - * - * -if ($display_type == 'horizontal') { - $new_field = ''; - foreach ($empty_row as $content_row_val) { - $new_field .= '' . $content_row_val . ''; - } - ?> - - addHTML($html); -?> + $fulltext_indexkey) { + $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey; + } +} + +for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { + if (! empty($regenerate)) { + list($columnMeta, $submit_length, $submit_attribute, + $submit_default_current_timestamp, $comments_map, $mime_map) + = PMA_handleRegeneration( + isset($available_mime) ? $mime_map : null, + $comments_map, $mime_map + ); + } elseif (isset($fields_meta[$columnNumber])) { + $columnMeta = PMA_getColumnMetaForDefault( + $fields_meta[$columnNumber], + isset($analyzed_sql[0]['create_table_fields'] + [$fields_meta[$columnNumber]['Field']]['default_value']) + ); + } + + if (isset($columnMeta['Type'])) { + $extracted_columnspec = PMA_Util::extractColumnSpec($columnMeta['Type']); + if ($extracted_columnspec['type'] == 'bit') { + $columnMeta['Default'] + = PMA_Util::convertBitDefaultValue($columnMeta['Default']); + } + } + + if (empty($columnMeta['Type'])) { + // creating a column + $columnMeta['Type'] = ''; + $type = ''; + $length = ''; + } else { + $type = $extracted_columnspec['type']; + $length = $extracted_columnspec['spec_in_brackets']; + } + + // some types, for example longtext, are reported as + // "longtext character set latin7" when their charset and / or collation + // differs from the ones of the corresponding database. + $tmp = strpos($type, 'character set'); + if ($tmp) { + $type = substr($type, 0, $tmp - 1); + } + + if (isset($submit_length) && $submit_length != false) { + $length = $submit_length; + } + + // rtrim the type, for cases like "float unsigned" + $type = rtrim($type); + $type_upper = strtoupper($type); + + + // old column attributes + if ($is_backup) { + if (isset($columnMeta['Field'])) { + $_form_params['field_orig[' . $columnNumber . ']'] + = $columnMeta['Field']; + } else { + $_form_params['field_orig[' . $columnNumber . ']'] = ''; + } + // old column length + $_form_params['field_length_orig[' . $columnNumber . ']'] = $length; + + // old column default + $_form_params['field_default_orig[' . $columnNumber . ']'] + = (isset($columnMeta['Default']) ? $columnMeta['Default'] : ''); + } + + $content_cells[$columnNumber] = PMA_getHtmlForColumnAttributes( + $columnNumber, isset($columnMeta) ? $columnMeta : null, $type_upper, + $length_values_input_size, $length, + isset($default_current_timestamp) ? $default_current_timestamp : null, + isset($extracted_columnspec) ? $extracted_columnspec : null, + isset($submit_attribute) ? $submit_attribute : null, + isset($analyzed_sql) ? $analyzed_sql : null, + isset($submit_default_current_timestamp) + ? $submit_default_current_timestamp : null, + $comments_map, isset($fields_meta) ? $fields_meta : null, $is_backup, + isset($move_columns) ? $move_columns : null, $cfgRelation, $available_mime, + $mime_map + ); +} // end for + +/** + * needs to be finished + * + * +if ($display_type == 'horizontal') { + $new_field = ''; + foreach ($empty_row as $content_row_val) { + $new_field .= '' . $content_row_val . ''; + } + ?> + + addHTML($html); +?> From d0e360fb501f051e57151dc3b2e959f4360e1cfe Mon Sep 17 00:00:00 2001 From: Supun Nakandala Date: Sun, 11 Aug 2013 21:12:48 +0530 Subject: [PATCH 06/53] no need to initialize --- libraries/tbl_columns_definition_form.inc.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 51ffa49747..e0c2765725 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -37,7 +37,6 @@ require_once './libraries/tbl_columns_definition_form.lib.php'; * Initialize $html in case this variable was used by a caller * (yes, this script should be refactored into functions) */ -$html = ''; $length_values_input_size = 8; @@ -196,7 +195,7 @@ function addField() } */ -$html .= PMA_getHtmlForTableCreateOrAddField( +$html = PMA_getHtmlForTableCreateOrAddField( $action, $_form_params, $content_cells, $header_cells ); From 62ac05fe752584bfdbcc7fcaae20518c81c4cf0d Mon Sep 17 00:00:00 2001 From: Supun Nakandala Date: Sun, 11 Aug 2013 21:21:07 +0530 Subject: [PATCH 07/53] $display_type is not set table create definition. So removed. --- libraries/tbl_columns_definition_form.inc.php | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index e0c2765725..78516a94bd 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -158,43 +158,6 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { ); } // end for -/** - * needs to be finished - * - * -if ($display_type == 'horizontal') { - $new_field = ''; - foreach ($empty_row as $content_row_val) { - $new_field .= '' . $content_row_val . ''; - } - ?> - - Date: Sun, 11 Aug 2013 21:31:31 +0530 Subject: [PATCH 08/53] added method PMA_getFormParamsForOldColumn --- libraries/tbl_columns_definition_form.inc.php | 15 +++-------- libraries/tbl_columns_definition_form.lib.php | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 78516a94bd..45609f42a6 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -129,18 +129,9 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { // old column attributes if ($is_backup) { - if (isset($columnMeta['Field'])) { - $_form_params['field_orig[' . $columnNumber . ']'] - = $columnMeta['Field']; - } else { - $_form_params['field_orig[' . $columnNumber . ']'] = ''; - } - // old column length - $_form_params['field_length_orig[' . $columnNumber . ']'] = $length; - - // old column default - $_form_params['field_default_orig[' . $columnNumber . ']'] - = (isset($columnMeta['Default']) ? $columnMeta['Default'] : ''); + $_form_params = PMA_getFormParamsForOldColumn( + $columnMeta, $length, $_form_params + ); } $content_cells[$columnNumber] = PMA_getHtmlForColumnAttributes( diff --git a/libraries/tbl_columns_definition_form.lib.php b/libraries/tbl_columns_definition_form.lib.php index 9159ccf77c..3c265fd487 100644 --- a/libraries/tbl_columns_definition_form.lib.php +++ b/libraries/tbl_columns_definition_form.lib.php @@ -1261,4 +1261,31 @@ function PMA_getHtmlForColumnAttributes($columnNumber, $columnMeta, $type_upper, return $content_cell; } + +/** + * Function to get form parameters for old column + * + * @param array $columnMeta column meta + * @param int $length length + * @param array $form_params form parameters + * + * @return array + */ +function PMA_getFormParamsForOldColumn($columnMeta, $length, $form_params) +{ + if (isset($columnMeta['Field'])) { + $form_params['field_orig[' . $columnNumber . ']'] + = $columnMeta['Field']; + } else { + $form_params['field_orig[' . $columnNumber . ']'] = ''; + } + // old column length + $form_params['field_length_orig[' . $columnNumber . ']'] = $length; + + // old column default + $form_params['field_default_orig[' . $columnNumber . ']'] + = (isset($columnMeta['Default']) ? $columnMeta['Default'] : ''); + + return $form_params; +} ?> From 0dbbe1d3606cbb3e3d02d06660c98e1ff0d93b27 Mon Sep 17 00:00:00 2001 From: Supun Nakandala Date: Sun, 11 Aug 2013 21:37:38 +0530 Subject: [PATCH 09/53] removed duplication --- libraries/tbl_columns_definition_form.inc.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 45609f42a6..6466fec30e 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -98,18 +98,15 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { $columnMeta['Default'] = PMA_Util::convertBitDefaultValue($columnMeta['Default']); } - } - - if (empty($columnMeta['Type'])) { + $type = $extracted_columnspec['type']; + $length = $extracted_columnspec['spec_in_brackets']; + } else { // creating a column $columnMeta['Type'] = ''; $type = ''; $length = ''; - } else { - $type = $extracted_columnspec['type']; - $length = $extracted_columnspec['spec_in_brackets']; } - + // some types, for example longtext, are reported as // "longtext character set latin7" when their charset and / or collation // differs from the ones of the corresponding database. @@ -124,8 +121,6 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { // rtrim the type, for cases like "float unsigned" $type = rtrim($type); - $type_upper = strtoupper($type); - // old column attributes if ($is_backup) { @@ -135,7 +130,7 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { } $content_cells[$columnNumber] = PMA_getHtmlForColumnAttributes( - $columnNumber, isset($columnMeta) ? $columnMeta : null, $type_upper, + $columnNumber, isset($columnMeta) ? $columnMeta : null, strtoupper($type), $length_values_input_size, $length, isset($default_current_timestamp) ? $default_current_timestamp : null, isset($extracted_columnspec) ? $extracted_columnspec : null, From 6bf2ee2192aae7e4d846214e6a2c16e8462ca516 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Sun, 11 Aug 2013 21:44:22 +0530 Subject: [PATCH 10/53] moved related stuff together --- libraries/tbl_columns_definition_form.inc.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 6466fec30e..024f8d033c 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -114,14 +114,15 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { if ($tmp) { $type = substr($type, 0, $tmp - 1); } + // rtrim the type, for cases like "float unsigned" + $type = rtrim($type); + if (isset($submit_length) && $submit_length != false) { $length = $submit_length; } - // rtrim the type, for cases like "float unsigned" - $type = rtrim($type); - + // old column attributes if ($is_backup) { $_form_params = PMA_getFormParamsForOldColumn( From 96c777b0685cc91631d3f6e6524a4e7c57b5a408 Mon Sep 17 00:00:00 2001 From: adamgsoc2013 Date: Mon, 12 Aug 2013 20:12:00 +0800 Subject: [PATCH 11/53] fix the DBI mocking on Pdf_Relation_Schema_test --- .../schema/Pdf_Relation_Schema_test.php | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/test/classes/schema/Pdf_Relation_Schema_test.php b/test/classes/schema/Pdf_Relation_Schema_test.php index 9ad7a76eeb..46499c2bcb 100644 --- a/test/classes/schema/Pdf_Relation_Schema_test.php +++ b/test/classes/schema/Pdf_Relation_Schema_test.php @@ -16,6 +16,7 @@ require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/Index.class.php'; require_once 'libraries/Table.class.php'; require_once 'libraries/database_interface.inc.php'; +require_once 'libraries/transformations.lib.php'; require_once 'libraries/schema/Pdf_Relation_Schema.class.php'; /** @@ -51,6 +52,8 @@ class PMA_Pdf_Relation_Schema_Test extends PHPUnit_Framework_TestCase $_POST['with_doc'] = 'on'; $GLOBALS['server'] = 1; + $GLOBALS['controllink'] = null; + $GLOBALS['db'] = 'information_schema'; $GLOBALS['cfg']['Server']['pmadb'] = "pmadb"; $GLOBALS['cfg']['LimitChars'] = 100; $GLOBALS['cfg']['ServerDefault'] = 1; @@ -58,11 +61,20 @@ class PMA_Pdf_Relation_Schema_Test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['Server']['table_coords'] = "table_name"; $GLOBALS['cfg']['Server']['bookmarktable'] = "bookmarktable"; $GLOBALS['cfg']['Server']['relation'] = "relation"; - $GLOBALS['cfg']['Server']['relation'] = "relation"; $GLOBALS['cfg']['Server']['table_info'] = "table_info"; - - $GLOBALS['cfgRelation']['db'] = "PMA"; - $GLOBALS['cfgRelation']['table_coords'] = "table_name"; + + //_SESSION + $_SESSION['relation'][$GLOBALS['server']] = array( + 'table_coords' => "table_name", + 'displaywork' => 'displaywork', + 'db' => "information_schema", + 'table_info' => 'table_info', + 'relwork' => false, + 'relation' => 'relation', + 'mimework' => 'mimework', + 'commwork' => 'commwork', + 'column_info' => 'column_info' + ); $dbi = $this->getMockBuilder('PMA_DatabaseInterface') ->disableOriginalConstructor() @@ -79,15 +91,24 @@ class PMA_Pdf_Relation_Schema_Test extends PHPUnit_Framework_TestCase $dbi->expects($this->any()) ->method('tryQuery') ->will($this->returnValue("executed_1")); - + $fetchArrayReturn = array( - 'table_name' => 'pma_table_name' + //table name in information_schema_relations + 'table_name' => 'CHARACTER_SETS' + ); + + $fetchArrayReturn2 = array( + //table name in information_schema_relations + 'table_name' => 'COLLATIONS' ); $dbi->expects($this->at(2)) ->method('fetchAssoc') ->will($this->returnValue($fetchArrayReturn)); $dbi->expects($this->at(3)) + ->method('fetchAssoc') + ->will($this->returnValue($fetchArrayReturn2)); + $dbi->expects($this->at(4)) ->method('fetchAssoc') ->will($this->returnValue(false)); @@ -142,10 +163,19 @@ class PMA_Pdf_Relation_Schema_Test extends PHPUnit_Framework_TestCase ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 " . "COLLATE=utf8_bin COMMENT='Bookmarks'"; - $dbi->expects($this->once()) + $dbi->expects($this->any()) ->method('fetchValue') ->will($this->returnValue($fetchValue)); + + $fetchResult = array( + 'column1' => array('mimetype' => 'value1', 'transformation'=> 'pdf'), + 'column2' => array('mimetype' => 'value2', 'transformation'=> 'xml'), + ); + + $dbi->expects($this->any())->method('fetchResult') + ->will($this->returnValue($fetchResult)); + $GLOBALS['dbi'] = $dbi; $this->object = new PMA_Pdf_Relation_Schema(); From 7f652aaca6ee17ddb47accb791672adedde79d99 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Mon, 12 Aug 2013 14:40:10 +0200 Subject: [PATCH 12/53] Translated using Weblate (French) Currently translated at 100.0% (2719.0 of 2719) --- po/fr.po | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/po/fr.po b/po/fr.po index cfa415a0a2..55fa9a2461 100644 --- a/po/fr.po +++ b/po/fr.po @@ -4,10 +4,9 @@ msgstr "" "Project-Id-Version: phpMyAdmin-docs 4.0.0-dev\n" "Report-Msgid-Bugs-To: phpmyadmin-devel@lists.sourceforge.net\n" "POT-Creation-Date: 2013-08-11 13:17+0200\n" -"PO-Revision-Date: 2013-08-01 14:19+0200\n" -"Last-Translator: Michal Čihař \n" -"Language-Team: French \n" +"PO-Revision-Date: 2013-08-12 14:40+0200\n" +"Last-Translator: Marc Delisle \n" +"Language-Team: French \n" "Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -914,7 +913,7 @@ msgstr "La commande «DROP DATABASE» est désactivée." #: js/messages.php:35 msgid "Confirm" -msgstr "" +msgstr "Confirmer" #: js/messages.php:36 #, php-format @@ -946,10 +945,10 @@ msgid "This operation could take a long time. Proceed anyway?" msgstr "Cette opération pourrait être longue. Procéder quand même ?" #: js/messages.php:44 -#, fuzzy, php-format +#, php-format #| msgid "Do you really want to execute \"%s\"?" msgid "Do you really want to delete user group \"%s\"?" -msgstr "Voulez-vous vraiment exécuter «%s» ?" +msgstr "Voulez-vous vraiment supprimer le groupe «%s» ?" #: js/messages.php:47 msgid "Missing value in the form!" @@ -6971,7 +6970,6 @@ msgid "%s of %s" msgstr "%s sur %s" #: libraries/display_import.lib.php:454 -#, fuzzy #| msgid "Uploading your import file..." msgid "Uploading your import file…" msgstr "Téléversement du fichier d'importation en cours …" @@ -10375,19 +10373,16 @@ msgid "User groups" msgstr "Groupes d'utilisateurs" #: libraries/server_privileges.lib.php:3268 -#, fuzzy #| msgid "Server-level tabs" msgid "Server level tabs" msgstr "Onglets de niveau serveur" #: libraries/server_privileges.lib.php:3269 -#, fuzzy #| msgid "Database-level tabs" msgid "Database level tabs" msgstr "Onglets de niveau base de données" #: libraries/server_privileges.lib.php:3270 -#, fuzzy #| msgid "Table-level tabs" msgid "Table level tabs" msgstr "Onglets de niveau table" @@ -12625,7 +12620,7 @@ msgstr "" "disponibles sur ce serveur." #: setup/lib/index.lib.php:226 -#, fuzzy, php-format +#, php-format #| msgid "" #| "%sLogin cookie validity%s greater than 1440 seconds may cause random " #| "session invalidation if %ssession.gc_maxlifetime%s is lower than its " @@ -12634,10 +12629,9 @@ msgid "" "%sLogin cookie validity%s greater than %ssession.gc_maxlifetime%s may cause " "random session invalidation (currently session.gc_maxlifetime is %d)." msgstr "" -"Le paramètre %sLogin cookie validity%s avec une valeur de plus de 1440 " -"secondes peut causer des interruptions de la session de travail si le " -"paramètre %ssession.gc_maxlifetime%s a une plus petite valeur (actuellement " -"%d)." +"Le paramètre %sLogin cookie validity%s avec une valeur plus grande que celle " +"de %ssession.gc_maxlifetime%s peut causer des interruptions de la session " +"de travail (la valeur courante de session.gc_maxlifetime est de %d)." #: setup/lib/index.lib.php:228 #, php-format From f0a225f516afd6a050c1c249c70c7334f19ed11e Mon Sep 17 00:00:00 2001 From: xmujay Date: Mon, 12 Aug 2013 21:32:37 +0800 Subject: [PATCH 13/53] Uts for PMA_server_privileges --- test/libraries/PMA_server_privileges_test.php | 293 +++++++++++++++++- 1 file changed, 283 insertions(+), 10 deletions(-) diff --git a/test/libraries/PMA_server_privileges_test.php b/test/libraries/PMA_server_privileges_test.php index 66dfe5ba04..d5bf25ca0c 100644 --- a/test/libraries/PMA_server_privileges_test.php +++ b/test/libraries/PMA_server_privileges_test.php @@ -19,6 +19,7 @@ require_once 'libraries/sanitizing.lib.php'; require_once 'libraries/sqlparser.lib.php'; require_once 'libraries/js_escape.lib.php'; require_once 'libraries/Message.class.php'; +require_once 'libraries/Response.class.php'; require_once 'libraries/server_privileges.lib.php'; /** @@ -51,6 +52,7 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons'; $GLOBALS['cfg']['LimitChars'] = 100; $GLOBALS['cfg']['DBG']['sql'] = false; + $GLOBALS['cfg']['AllowThirdPartyFraming'] = false; $GLOBALS['table'] = "table"; $GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF'); @@ -79,11 +81,110 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase ) ); + $fetchSingleRow = array('password' => 'pma_password'); + $dbi->expects($this->any())->method('fetchSingleRow') + ->will($this->returnValue($fetchSingleRow)); + + $fetchValue = array('key1' => 'value1'); + $dbi->expects($this->any())->method('fetchValue') + ->will($this->returnValue($fetchValue)); + + $dbi->expects($this->any())->method('tryQuery') + ->will($this->returnValue(true)); + $GLOBALS['dbi'] = $dbi; } /** - * Test for PMA_getHtmlForExportUserDefinition + * Test for PMA_getDataForDBInfo + * + * @return void + */ + public function testPMAGetDataForDBInfo() + { + $_REQUEST['tablename'] = "PMA_tablename"; + $_REQUEST['dbname'] = "PMA_dbname"; + list($dbname, $tablename, $db_and_table, $dbname_is_wildcard) + = PMA_getDataForDBInfo(); + $this->assertEquals( + "PMA_dbname", + $dbname + ); + $this->assertEquals( + "PMA_tablename", + $tablename + ); + $this->assertEquals( + "`PMA_dbname`.`PMA_tablename`", + $db_and_table + ); + $this->assertEquals( + true, + $dbname_is_wildcard + ); + + //pre variable have been defined + $_REQUEST['pred_tablename'] = "PMA_pred__tablename"; + $_REQUEST['pred_dbname'] = "PMA_pred_dbname"; + list($dbname, $tablename, $db_and_table, $dbname_is_wildcard) + = PMA_getDataForDBInfo(); + $this->assertEquals( + "PMA_pred_dbname", + $dbname + ); + $this->assertEquals( + "PMA_pred__tablename", + $tablename + ); + $this->assertEquals( + "`PMA_pred_dbname`.`PMA_pred__tablename`", + $db_and_table + ); + $this->assertEquals( + true, + $dbname_is_wildcard + ); + + } + + + /** + * Test for PMA_getDataForChangeOrCopyUser + * + * @return void + */ + public function testPMAGetDataForChangeOrCopyUser() + { + //$_REQUEST['change_copy'] not set + list($queries, $password) = PMA_getDataForChangeOrCopyUser(); + $this->assertEquals( + null, + $queries + ); + $this->assertEquals( + null, + $queries + ); + + //$_REQUEST['change_copy'] is set + $_REQUEST['change_copy'] = true; + $_REQUEST['old_username'] = 'PMA_old_username'; + $_REQUEST['old_hostname'] = 'PMA_old_hostname'; + list($queries, $password) = PMA_getDataForChangeOrCopyUser(); + $this->assertEquals( + 'pma_password', + $password + ); + $this->assertEquals( + array(), + $queries + ); + unset($_REQUEST['change_copy']); + } + + + /** + * Test for PMA_getListForExportUserDefinition * * @return void */ @@ -98,7 +199,7 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['TextareaRows'] = 'TextareaCols'; list($title, $export) - = PMA_getHtmlForExportUserDefinition($username, $hostname); + = PMA_getListForExportUserDefinition($username, $hostname); //validate 1: $export $result = '