diff --git a/libraries/classes/Plugins/Export/ExportJson.php b/libraries/classes/Plugins/Export/ExportJson.php index 5f5efea00a..14042b3457 100644 --- a/libraries/classes/Plugins/Export/ExportJson.php +++ b/libraries/classes/Plugins/Export/ExportJson.php @@ -270,8 +270,9 @@ class ExportJson extends ExportPlugin $data = []; for ($i = 0; $i < $columns_cnt; $i++) { - if ($fieldsMeta[$i]->isMappedTypeGeometry - || $fieldsMeta[$i]->isType(FieldMetadata::TYPE_BLOB)) { + if (isset($fieldsMeta[$i]) && ($fieldsMeta[$i]->isMappedTypeGeometry + || $fieldsMeta[$i]->isType(FieldMetadata::TYPE_BLOB)) + ) { // export GIS and blob types as hex $record[$i] = '0x' . bin2hex($record[$i]); } diff --git a/libraries/classes/Plugins/Export/ExportSql.php b/libraries/classes/Plugins/Export/ExportSql.php index 415c44f8bd..830d79f1a5 100644 --- a/libraries/classes/Plugins/Export/ExportSql.php +++ b/libraries/classes/Plugins/Export/ExportSql.php @@ -601,8 +601,7 @@ class ExportSql extends ExportPlugin $text = ''; $delimiter = '$$'; - $procedure_names = $dbi - ->getProceduresOrFunctions($db, 'PROCEDURE'); + $procedure_names = $dbi->getProceduresOrFunctions($db, 'PROCEDURE'); $function_names = $dbi->getProceduresOrFunctions($db, 'FUNCTION'); if ($procedure_names || $function_names) { diff --git a/test/classes/Plugins/Export/ExportCodegenTest.php b/test/classes/Plugins/Export/ExportCodegenTest.php index 94f5c149a4..7e99233f2c 100644 --- a/test/classes/Plugins/Export/ExportCodegenTest.php +++ b/test/classes/Plugins/Export/ExportCodegenTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Plugins\Export; -use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Plugins\Export\ExportCodegen; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; @@ -199,52 +198,45 @@ class ExportCodegenTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = true; $GLOBALS['save_on_server'] = false; - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $GLOBALS['dbi'] = $dbi; ob_start(); $this->object->exportData( - 'testDB', - 'testTable', + 'test_db', + 'test_table', "\n", - 'example.com', - 'test' + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' ); $result = ob_get_clean(); $this->assertIsString($result); - - $this->assertStringContainsString( - '', - $result - ); - - $this->assertStringContainsString( - '', - $result - ); - - $this->assertStringContainsString( - '', - $result - ); - - $this->assertStringContainsString( - '', + $this->assertEquals( + '' . "\n" + . '' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . ' ' . "\n" + . '', $result ); $GLOBALS['codegen_format'] = 4; $this->object->exportData( - 'testDB', - 'testTable', + 'test_db', + 'test_table', "\n", - 'example.com', - 'test' + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' ); $this->expectOutputString( @@ -272,59 +264,52 @@ class ExportCodegenTest extends AbstractTestCase public function testHandleNHibernateCSBody(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('DESC `db`.`table`') - ->will($this->returnValue(true)); - - $dbi->expects($this->at(1)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(['a', 'b', 'c', false, 'e', 'f'])); - - $dbi->expects($this->at(2)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(null)); - - $GLOBALS['dbi'] = $dbi; $method = new ReflectionMethod(ExportCodegen::class, 'handleNHibernateCSBody'); $method->setAccessible(true); - $result = $method->invoke($this->object, 'db', 'table', "\n"); + $result = $method->invoke($this->object, 'test_db', 'test_table', "\n"); $this->assertEquals( - "using System;\n" . - "using System.Collections;\n" . - "using System.Collections.Generic;\n" . - "using System.Text;\n" . - "namespace Db\n" . - "{\n" . - " #region Table\n" . - " public class Table\n" . - " {\n" . - " #region Member Variables\n" . - " protected unknown _a;\n" . - " #endregion\n" . - " #region Constructors\n" . - " public Table() { }\n" . - " public Table(unknown a)\n" . - " {\n" . - " this._a=a;\n" . - " }\n" . - " #endregion\n" . - " #region Public Properties\n" . - " public virtual unknown A\n" . - " {\n" . - " get {return _a;}\n" . - " set {_a=value;}\n" . - " }\n" . - " #endregion\n" . - " }\n" . - " #endregion\n" . + 'using System;' . "\n" . + 'using System.Collections;' . "\n" . + 'using System.Collections.Generic;' . "\n" . + 'using System.Text;' . "\n" . + 'namespace Test_db' . "\n" . + '{' . "\n" . + ' #region Test_table' . "\n" . + ' public class Test_table' . "\n" . + ' {' . "\n" . + ' #region Member Variables' . "\n" . + ' protected int _id;' . "\n" . + ' protected string _name;' . "\n" . + ' protected DateTime _datetimefield;' . "\n" . + ' #endregion' . "\n" . + ' #region Constructors' . "\n" . + ' public Test_table() { }' . "\n" . + ' public Test_table(string name, DateTime datetimefield)' . "\n" . + ' {' . "\n" . + ' this._name=name;' . "\n" . + ' this._datetimefield=datetimefield;' . "\n" . + ' }' . "\n" . + ' #endregion' . "\n" . + ' #region Public Properties' . "\n" . + ' public virtual int Id' . "\n" . + ' {' . "\n" . + ' get {return _id;}' . "\n" . + ' set {_id=value;}' . "\n" . + ' }' . "\n" . + ' public virtual string Name' . "\n" . + ' {' . "\n" . + ' get {return _name;}' . "\n" . + ' set {_name=value;}' . "\n" . + ' }' . "\n" . + ' public virtual DateTime Datetimefield' . "\n" . + ' {' . "\n" . + ' get {return _datetimefield;}' . "\n" . + ' set {_datetimefield=value;}' . "\n" . + ' }' . "\n" . + ' #endregion' . "\n" . + ' }' . "\n" . + ' #endregion' . "\n" . '}', $result ); @@ -332,48 +317,24 @@ class ExportCodegenTest extends AbstractTestCase public function testHandleNHibernateXMLBody(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('DESC `db`.`table`') - ->will($this->returnValue(true)); - - $dbi->expects($this->at(1)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(['a', 'b', 'c', false, 'e', 'f'])); - - $dbi->expects($this->at(2)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(['g', 'h', 'i', 'PRI', 'j', 'k'])); - - $dbi->expects($this->at(3)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(null)); - - $GLOBALS['dbi'] = $dbi; $method = new ReflectionMethod(ExportCodegen::class, 'handleNHibernateXMLBody'); $method->setAccessible(true); - $result = $method->invoke($this->object, 'db', 'table', "\n"); + $result = $method->invoke($this->object, 'test_db', 'test_table', "\n"); $this->assertEquals( '' . "\n" . - '' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . + '' . "\n" . + ' ' . "\n" . + ' ' . "\n" . + ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . + ' ' . "\n" . + ' ' . "\n" . + ' ' . "\n" . + ' ' . "\n" . + ' ' . "\n" . + ' ' . "\n" . ' ' . "\n" . '', $result diff --git a/test/classes/Plugins/Export/ExportCsvTest.php b/test/classes/Plugins/Export/ExportCsvTest.php index 1e2c7e7db5..3d74b16240 100644 --- a/test/classes/Plugins/Export/ExportCsvTest.php +++ b/test/classes/Plugins/Export/ExportCsvTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Plugins\Export; -use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Plugins\Export\ExportCsv; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; @@ -33,7 +32,14 @@ class ExportCsvTest extends AbstractTestCase protected function setUp(): void { parent::setUp(); + parent::defineVersionConstants(); + parent::loadDefaultConfig(); $GLOBALS['server'] = 0; + $GLOBALS['db'] = ''; + $GLOBALS['table'] = ''; + $GLOBALS['lang'] = ''; + $GLOBALS['text_dir'] = ''; + $GLOBALS['PMA_PHP_SELF'] = ''; $this->object = new ExportCsv(); } @@ -443,11 +449,6 @@ class ExportCsvTest extends AbstractTestCase public function testExportData(): void { // case 1 - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $GLOBALS['dbi'] = $dbi; - $GLOBALS['csv_columns'] = 'yes'; $GLOBALS['csv_terminated'] = ';'; @@ -459,48 +460,16 @@ class ExportCsvTest extends AbstractTestCase $GLOBALS['file_handle'] = null; ob_start(); - $this->assertFalse( - $this->object->exportData( - 'testDB', - 'testTable', - "\n", - 'example.com', - 'test' - ) - ); + $this->assertFalse($this->object->exportData( + 'test_db', + 'test_table', + "\n", + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' + )); ob_get_clean(); // case 2 - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('test', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_UNBUFFERED) - ->will($this->returnValue(true)); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(true) - ->will($this->returnValue(1)); - - $dbi->expects($this->once()) - ->method('fieldName') - ->with(true, 0) - ->will($this->returnValue("foo'\\bar")); - - $dbi->expects($this->at(3)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue([null, 'b', 'c', false, 'e', 'f'])); - - $dbi->expects($this->at(4)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(null)); - $GLOBALS['dbi'] = $dbi; - $GLOBALS['what'] = 'UT'; $GLOBALS['UT_null'] = 'customNull'; $GLOBALS['output_kanji_conversion'] = false; @@ -512,232 +481,102 @@ class ExportCsvTest extends AbstractTestCase $GLOBALS['csv_separator'] = ''; ob_start(); - $this->assertTrue( - $this->object->exportData( - 'testDB', - 'testTable', - "\n", - 'example.com', - 'test' - ) - ); + $this->assertTrue($this->object->exportData( + 'test_db', + 'test_table', + "\n", + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' + )); $result = ob_get_clean(); $this->assertEquals( - "foo'ba;customNull;", + 'idnamedatetimefiel;1abcd2011-01-20 02:00:02;' + . '2foo2010-01-20 02:00:02;3Abcd2012-01-20 02:00:02;', $result ); // case 3 - - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('test', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_UNBUFFERED) - ->will($this->returnValue(true)); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(true) - ->will($this->returnValue(1)); - - $dbi->expects($this->once()) - ->method('fieldName') - ->with(true, 0) - ->will($this->returnValue("foo\"\\bar")); - - $dbi->expects($this->at(3)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue([1 => 'a'])); - - $dbi->expects($this->at(4)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(null)); - $GLOBALS['dbi'] = $dbi; - $GLOBALS['csv_enclosed'] = '"'; $GLOBALS['csv_escaped'] = ''; ob_start(); - $this->assertTrue( - $this->object->exportData( - 'testDB', - 'testTable', - "\n", - 'example.com', - 'test' - ) - ); + $this->assertTrue($this->object->exportData( + 'test_db', + 'test_table', + "\n", + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' + )); $result = ob_get_clean(); $this->assertEquals( - '"foo"bar;customNull;', + '"id""name""datetimefield;"1""abcd""2011-01-20 02:00:02";' + . '"2""foo""2010-01-20 02:00:02";"3""Abcd""2012-01-20 02:00:02";', $result ); // case 4 - - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('test', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_UNBUFFERED) - ->will($this->returnValue(true)); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(true) - ->will($this->returnValue(1)); - - $dbi->expects($this->once()) - ->method('fieldName') - ->with(true, 0) - ->will($this->returnValue("foo\"\\bar")); - - $dbi->expects($this->at(3)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(["test\015\012\n"])); - - $dbi->expects($this->at(4)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(null)); - $GLOBALS['dbi'] = $dbi; - $GLOBALS['csv_enclosed'] = '"'; $GLOBALS['what'] = 'excel'; $GLOBALS['excel_removeCRLF'] = true; $GLOBALS['csv_escaped'] = '"'; ob_start(); - $this->assertTrue( - $this->object->exportData( - 'testDB', - 'testTable', - "\n", - 'example.com', - 'test' - ) - ); + $this->assertTrue($this->object->exportData( + 'test_db', + 'test_table', + "\n", + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' + )); $result = ob_get_clean(); $this->assertEquals( - '"foo""bar;"test";', + '"id""name""datetimefield;"1""abcd""2011-01-20 02:00:02";' + . '"2""foo""2010-01-20 02:00:02";"3""Abcd""2012-01-20 02:00:02";', $result ); // case 5 - - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('test', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_UNBUFFERED) - ->will($this->returnValue(true)); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(true) - ->will($this->returnValue(1)); - - $dbi->expects($this->once()) - ->method('fieldName') - ->with(true, 0) - ->will($this->returnValue("foo\"\\bar")); - - $dbi->expects($this->at(3)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(["test\015\n"])); - - $dbi->expects($this->at(4)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(null)); - $GLOBALS['dbi'] = $dbi; - $GLOBALS['csv_enclosed'] = '"'; unset($GLOBALS['excel_removeCRLF']); $GLOBALS['csv_escaped'] = ';'; ob_start(); - $this->assertTrue( - $this->object->exportData( - 'testDB', - 'testTable', - "\n", - 'example.com', - 'test' - ) - ); + $this->assertTrue($this->object->exportData( + 'test_db', + 'test_table', + "\n", + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' + )); $result = ob_get_clean(); $this->assertEquals( - "\"foo;\"bar;\"test\n\";", + '"id""name""datetimefield;"1""abcd""2011-01-20 02:00:02";' + . '"2""foo""2010-01-20 02:00:02";"3""Abcd""2012-01-20 02:00:02";', $result ); // case 6 - - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('test', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_UNBUFFERED) - ->will($this->returnValue(true)); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(true) - ->will($this->returnValue(2)); - - $dbi->expects($this->any()) - ->method('fieldName') - ->will($this->returnValue("foo\"\\bar")); - - $dbi->expects($this->at(4)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(["test\015\n", "test\n"])); - - $dbi->expects($this->at(5)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(null)); - $GLOBALS['dbi'] = $dbi; - $GLOBALS['csv_enclosed'] = '"'; $GLOBALS['csv_escaped'] = ';'; $GLOBALS['csv_escaped'] = '#'; ob_start(); - $this->assertTrue( - $this->object->exportData( - 'testDB', - 'testTable', - "\n", - 'example.com', - 'test' - ) - ); + $this->assertTrue($this->object->exportData( + 'test_db', + 'test_table', + "\n", + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' + )); $result = ob_get_clean(); $this->assertEquals( - "\"foo#\"bar\"\"foo#\"bar;\"test\n" . - "\"\"test\n" . - '";', + '"id""name""datetimefield;"1""abcd""2011-01-20 02:00:02";' + . '"2""foo""2010-01-20 02:00:02";"3""Abcd""2012-01-20 02:00:02";', $result ); } diff --git a/test/classes/Plugins/Export/ExportHtmlwordTest.php b/test/classes/Plugins/Export/ExportHtmlwordTest.php index 9674022c7a..ff668d81c7 100644 --- a/test/classes/Plugins/Export/ExportHtmlwordTest.php +++ b/test/classes/Plugins/Export/ExportHtmlwordTest.php @@ -17,7 +17,6 @@ use PhpMyAdmin\Tests\AbstractTestCase; use ReflectionMethod; use ReflectionProperty; use function array_shift; -use function htmlspecialchars_decode; use function ob_get_clean; use function ob_start; @@ -44,6 +43,12 @@ class ExportHtmlwordTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = true; $GLOBALS['save_on_server'] = false; + $GLOBALS['db'] = ''; + $GLOBALS['table'] = ''; + $GLOBALS['lang'] = ''; + $GLOBALS['text_dir'] = ''; + $GLOBALS['PMA_PHP_SELF'] = ''; + $GLOBALS['cfg']['Server']['DisableIS'] = true; } /** @@ -303,36 +308,6 @@ class ExportHtmlwordTest extends AbstractTestCase public function testExportData(): void { // case 1 - - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('test', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_UNBUFFERED) - ->will($this->returnValue(true)); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(true) - ->will($this->returnValue(5)); - - $dbi->expects($this->any()) - ->method('fieldName') - ->will($this->returnValue("foo\\bar")); - - $dbi->expects($this->at(7)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue([null, '0', 'test', false])); - - $dbi->expects($this->at(8)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(null)); - $GLOBALS['dbi'] = $dbi; - $GLOBALS['htmlword_columns'] = true; $GLOBALS['what'] = 'UT'; $GLOBALS['UT_null'] = 'customNull'; @@ -343,28 +318,28 @@ class ExportHtmlwordTest extends AbstractTestCase $GLOBALS['save_on_server'] = false; ob_start(); - $this->assertTrue( - $this->object->exportData( - 'testDB', - 'testTable', - "\n", - 'example.com', - 'test' - ) - ); - $result = htmlspecialchars_decode((string) ob_get_clean()); + $this->assertTrue($this->object->exportData( + 'test_db', + 'test_table', + "\n", + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' + )); + $result = ob_get_clean(); $this->assertEquals( - '

Dumping data for table testTable

' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '
', + '

Dumping data for table test_table

' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '
', $result ); } @@ -720,48 +695,13 @@ class ExportHtmlwordTest extends AbstractTestCase public function testExportStructure(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('getTriggers') - ->with('db', 'tbl') - ->will($this->returnValue(1)); - - $this->object = $this->getMockBuilder(ExportHtmlword::class) - ->onlyMethods(['getTableDef', 'getTriggers', 'getTableDefStandIn']) - ->getMock(); - - $this->object->expects($this->at(0)) - ->method('getTableDef') - ->with('db', 'tbl', false, false, false, false) - ->will($this->returnValue('dumpText1')); - - $this->object->expects($this->once()) - ->method('getTriggers') - ->with('db', 'tbl') - ->will($this->returnValue('dumpText2')); - - $this->object->expects($this->at(2)) - ->method('getTableDef') - ->with('db', 'tbl', false, false, false, true, []) - ->will($this->returnValue('dumpText3')); - - $this->object->expects($this->once()) - ->method('getTableDefStandIn') - ->with('db', 'tbl', "\n") - ->will($this->returnValue('dumpText4')); - - $GLOBALS['dbi'] = $dbi; - ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 'tbl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'create_table', 'test' ) @@ -769,17 +709,26 @@ class ExportHtmlwordTest extends AbstractTestCase $result = ob_get_clean(); $this->assertEquals( - '

Table structure for table tbl

dumpText1', + '

Table structure for table test_table

' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '
', $result ); ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 'tbl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'triggers', 'test' ) @@ -787,17 +736,22 @@ class ExportHtmlwordTest extends AbstractTestCase $result = ob_get_clean(); $this->assertEquals( - '

Triggers tbl

dumpText2', + '

Triggers test_table

' + . '' + . '' + . '' + . '' + . '
', $result ); ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 'tbl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'create_view', 'test' ) @@ -805,17 +759,26 @@ class ExportHtmlwordTest extends AbstractTestCase $result = ob_get_clean(); $this->assertEquals( - '

Structure for view tbl

dumpText3', + '

Structure for view test_table

' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '
', $result ); ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 'tbl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'stand_in', 'test' ) @@ -823,7 +786,17 @@ class ExportHtmlwordTest extends AbstractTestCase $result = ob_get_clean(); $this->assertEquals( - '

Stand-in structure for view tbl

dumpText4', + '

Stand-in structure for view test_table

' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '
', $result ); } diff --git a/test/classes/Plugins/Export/ExportJsonTest.php b/test/classes/Plugins/Export/ExportJsonTest.php index 4839c356ca..e5cf69a771 100644 --- a/test/classes/Plugins/Export/ExportJsonTest.php +++ b/test/classes/Plugins/Export/ExportJsonTest.php @@ -4,8 +4,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Plugins\Export; -use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\FieldMetadata; use PhpMyAdmin\Plugins\Export\ExportJson; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; @@ -14,9 +12,7 @@ use PhpMyAdmin\Properties\Plugins\ExportPluginProperties; use PhpMyAdmin\Tests\AbstractTestCase; use ReflectionMethod; use ReflectionProperty; -use stdClass; use function array_shift; -use const MYSQLI_TYPE_STRING; /** * @group medium @@ -184,59 +180,22 @@ class ExportJsonTest extends AbstractTestCase public function testExportData(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $flags = []; - $a = new stdClass(); - $a->name = 'f1'; - $a->length = 20; - $flags[] = new FieldMetadata(MYSQLI_TYPE_STRING, 0, $a); - - $dbi->expects($this->once()) - ->method('getFieldsMeta') - ->with(null) - ->will($this->returnValue($flags)); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(null) - ->will($this->returnValue(1)); - - $dbi->expects($this->at(3)) - ->method('fieldName') - ->with(null, 0) - ->will($this->returnValue('f1')); - - $dbi->expects($this->at(4)) - ->method('fetchRow') - ->with(null) - ->will($this->returnValue(['foo'])); - - $dbi->expects($this->at(5)) - ->method('fetchRow') - ->with(null) - ->will($this->returnValue(['bar'])); - - $dbi->expects($this->at(6)) - ->method('fetchRow') - ->with(null) - ->will($this->returnValue(null)); - - $GLOBALS['dbi'] = $dbi; - $this->expectOutputString( - '{"type":"table","name":"tbl","database":"db","data":' - . "\n[\n" - . '{"f1":"foo"},' - . "\n" - . '{"f1":"bar"}' - . "\n]\n}\n" + '{"type":"table","name":"test_table","database":"test_db","data":' . "\n" + . '[' . "\n" + . '{"id":"1","name":"abcd","datetimefield":"2011-01-20 02:00:02"},' . "\n" + . '{"id":"2","name":"foo","datetimefield":"2010-01-20 02:00:02"},' . "\n" + . '{"id":"3","name":"Abcd","datetimefield":"2012-01-20 02:00:02"}' . "\n" + . ']' . "\n" + . '}' . "\n" ); - $this->assertTrue( - $this->object->exportData('db', 'tbl', "\n", 'example.com', 'SELECT') - ); + $this->assertTrue($this->object->exportData( + 'test_db', + 'test_table', + "\n", + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' + )); } } diff --git a/test/classes/Plugins/Export/ExportLatexTest.php b/test/classes/Plugins/Export/ExportLatexTest.php index 110b629a5c..31e1c9d520 100644 --- a/test/classes/Plugins/Export/ExportLatexTest.php +++ b/test/classes/Plugins/Export/ExportLatexTest.php @@ -529,103 +529,61 @@ class ExportLatexTest extends AbstractTestCase $GLOBALS['latex_null'] = 'null'; $GLOBALS['cfg']['Server']['host'] = 'localhost'; $GLOBALS['cfg']['Server']['verbose'] = 'verb'; - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(null) - ->will($this->returnValue(1)); - - $dbi->expects($this->at(2)) - ->method('fieldName') - ->with(null, 0) - ->will($this->returnValue('f1')); - - $dbi->expects($this->at(3)) - ->method('fetchAssoc') - ->with(null) - ->will($this->returnValue(['f1' => 'foo$%'])); - - $dbi->expects($this->at(4)) - ->method('fetchAssoc') - ->with(null) - ->will($this->returnValue(['f1' => null])); - - $dbi->expects($this->at(5)) - ->method('fetchAssoc') - ->with(null) - ->will($this->returnValue(null)); - - $GLOBALS['dbi'] = $dbi; ob_start(); - $this->assertTrue( - $this->object->exportData('db', 'tbl', "\n", 'example.com', 'SELECT') - ); + $this->assertTrue($this->object->exportData( + 'test_db', + 'test_table', + "\n", + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' + )); $result = ob_get_clean(); $this->assertEquals( "\n" . '%' . "\n" . - '% Data: tbl' . "\n" . + '% Data: test_table' . "\n" . '%' . "\n" . - ' \\begin{longtable}{|l|} ' . "\n" . - ' \\hline \\endhead \\hline \\endfoot \\hline ' . "\n" . - ' \\caption{latex data caption} \\label{datalabel} ' . - '\\\\\\hline \\multicolumn{1}{|c|}{\\textbf{f1}} ' . - '\\\\ \\hline \hline \\endfirsthead ' . "\n" . - '\caption{continued caption} \\\\ \hline \multicolumn{1}' . - '{|c|}{\textbf{f1}} \\\\ \hline \hline \endhead \endfoot' . "\n" . - 'foo\$\% \\\\ \hline ' . "\n" . - 'null \\\\ \hline ' . "\n" . + ' \begin{longtable}{|l|l|l|} ' . "\n" . + ' \hline \endhead \hline \endfoot \hline ' . "\n" . + ' \caption{latex data caption} \label{datalabel} \\\\\hline \multicolumn{1}{|c|}' . + '{\textbf{id}} & \multicolumn{1}{|c|}{\textbf{name}} & \multicolumn{1}{|c|}' . + '{\textbf{datetimefield}} \\\ \hline \hline \endfirsthead ' . "\n" . + '\caption{continued caption} \\\ \hline \multicolumn{1}{|c|}{\textbf{id}} & \multicolumn{1}' . + '{|c|}{\textbf{name}} & \multicolumn{1}{|c|}{\textbf{datetimefield}}' . + ' \\\ \hline \hline \endhead \endfoot' . "\n" . + '1 & abcd & 2011-01-20 02:00:02 \\\\ \hline ' . "\n" . + '2 & foo & 2010-01-20 02:00:02 \\\\ \hline ' . "\n" . + '3 & Abcd & 2012-01-20 02:00:02 \\\\ \hline ' . "\n" . ' \end{longtable}' . "\n", $result ); // case 2 unset($GLOBALS['latex_columns']); - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(null) - ->will($this->returnValue(1)); - - $dbi->expects($this->at(2)) - ->method('fieldName') - ->with(null, 0) - ->will($this->returnValue('f1')); - - $dbi->expects($this->at(3)) - ->method('fetchAssoc') - ->with(null) - ->will($this->returnValue(['f1' => 'foo$%'])); - - $dbi->expects($this->at(4)) - ->method('fetchAssoc') - ->with(null) - ->will($this->returnValue(['f1' => null])); - - $dbi->expects($this->at(5)) - ->method('fetchAssoc') - ->with(null) - ->will($this->returnValue(null)); - - $GLOBALS['dbi'] = $dbi; ob_start(); - $this->assertTrue( - $this->object->exportData('db', 'tbl', "\n", 'example.com', 'SELECT') - ); + $this->assertTrue($this->object->exportData( + 'test_db', + 'test_table', + "\n", + 'localhost', + 'SELECT * FROM `test_db`.`test_table`;' + )); $result = ob_get_clean(); $this->assertIsString($result); - - $this->assertStringContainsString( - '{datalabel} \\\\\\\\ \hlinefoo', + $this->assertEquals( + "\n" . '%' . "\n" . + '% Data: test_table' . "\n" . + '%' . "\n" . + ' \begin{longtable}{|l|l|l|} ' . "\n" . + ' \hline \endhead \hline \endfoot \hline ' . "\n" . + ' \caption{latex data caption} \label{datalabel} \\\\\\\\ \hline' . + '1 & abcd & 2011-01-20 02:00:02 \\\\ \hline ' . "\n" . + '2 & foo & 2010-01-20 02:00:02 \\\\ \hline ' . "\n" . + '3 & Abcd & 2012-01-20 02:00:02 \\\\ \hline ' . "\n" . + ' \end{longtable}' . "\n", $result ); } diff --git a/test/classes/Plugins/Export/ExportMediawikiTest.php b/test/classes/Plugins/Export/ExportMediawikiTest.php index edcc810257..6f138c2757 100644 --- a/test/classes/Plugins/Export/ExportMediawikiTest.php +++ b/test/classes/Plugins/Export/ExportMediawikiTest.php @@ -326,7 +326,7 @@ class ExportMediawikiTest extends AbstractTestCase 'test_db', 'test_table', "\n", - 'example.com', + 'localhost', 'SELECT * FROM `test_db`.`test_table`;' ) ); @@ -351,11 +351,11 @@ class ExportMediawikiTest extends AbstractTestCase "|-\n" . " | 2\n" . " | foo\n" . - " | 2011-01-20 02:00:02\n" . + " | 2010-01-20 02:00:02\n" . "|-\n" . " | 3\n" . " | Abcd\n" . - " | 2011-01-20 02:00:02\n" . + " | 2012-01-20 02:00:02\n" . "|}\n\n", $result ); diff --git a/test/classes/Plugins/Export/ExportOdtTest.php b/test/classes/Plugins/Export/ExportOdtTest.php index 215a4a5131..4a92e0c459 100644 --- a/test/classes/Plugins/Export/ExportOdtTest.php +++ b/test/classes/Plugins/Export/ExportOdtTest.php @@ -52,6 +52,7 @@ class ExportOdtTest extends AbstractTestCase $GLOBALS['plugin_param']['export_type'] = 'table'; $GLOBALS['plugin_param']['single_table'] = false; $GLOBALS['cfgRelation']['relation'] = true; + $GLOBALS['cfg']['Server']['DisableIS'] = true; $this->object = new ExportOdt(); } @@ -589,45 +590,34 @@ class ExportOdtTest extends AbstractTestCase public function testGetTableDefStandIn(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('getColumns') - ->with('db', 'v&w') - ->will($this->returnValue([1, 2])); - - $GLOBALS['dbi'] = $dbi; - - $this->object = $this->getMockBuilder(ExportOdt::class) - ->disableOriginalConstructor() - ->onlyMethods(['formatOneColumnDefinition']) - ->getMock(); - - $this->object->expects($this->at(0)) - ->method('formatOneColumnDefinition') - ->with(1) - ->will($this->returnValue('c1')); - - $this->object->expects($this->at(1)) - ->method('formatOneColumnDefinition') - ->with(2) - ->will($this->returnValue('c2')); - $this->assertSame( - $this->object->getTableDefStandIn('db', 'v&w', '#'), + $this->object->getTableDefStandIn('test_db', 'test_table', "\n"), '' ); - $this->assertStringContainsString( - '', - $GLOBALS['odt_buffer'] - ); - - $this->assertStringContainsString( - 'c1c2' . - '', + $this->assertEquals( + '' + . '' + . 'Column' + . 'Type' + . 'Null' + . 'Default' + . '' + . 'id' + . 'int(11)' + . 'No' + . 'NULL' + . '' + . 'name' + . 'varchar(20)' + . 'No' + . 'NULL' + . '' + . 'datetimefield' + . 'datetime' + . 'No' + . 'NULL' + . '', $GLOBALS['odt_buffer'] ); } @@ -874,67 +864,42 @@ class ExportOdtTest extends AbstractTestCase public function testExportStructure(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('getTriggers') - ->with('db', 't&bl') - ->will($this->returnValue(1)); - - $this->object = $this->getMockBuilder(ExportOdt::class) - ->onlyMethods(['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 $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'create_table', 'test' ) ); - $this->assertStringContainsString( - 'Table structure for table t&bl', + $this->assertEquals( + '' + . 'Table structure for table test_table' + . '' + . 'Column' + . 'Type' + . 'Null' + . 'Default' + . '' + . 'id' + . 'int(11)' + . 'No' + . 'NULL' + . '' + . 'name' + . 'varchar(20)' + . 'No' + . 'NULL' + . '' + . 'datetimefield' + . 'datetime' + . 'No' + . 'NULL' + . '', $GLOBALS['odt_buffer'] ); @@ -943,18 +908,29 @@ class ExportOdtTest extends AbstractTestCase $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'triggers', 'test' ) ); $this->assertEquals( - 'Triggers t&bl', + '' + . 'Triggers test_table' + . '' + . 'Name' + . 'Time' + . 'Event' + . 'Definition' + . '' + . 'test_trigger' + . 'AFTER' + . 'INSERT' + . 'BEGIN END' + . '', $GLOBALS['odt_buffer'] ); @@ -963,18 +939,39 @@ class ExportOdtTest extends AbstractTestCase $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'create_view', 'test' ) ); $this->assertEquals( - 'Structure for view t&bl', + '' + . 'Structure for view test_table' + . '' + . 'Column' + . 'Type' + . 'Null' + . 'Default' + . '' + . 'id' + . 'int(11)' + . 'No' + . 'NULL' + . '' + . 'name' + . 'varchar(20)' + . 'No' + . 'NULL' + . '' + . 'datetimefield' + . 'datetime' + . 'No' + . 'NULL' + . '', $GLOBALS['odt_buffer'] ); @@ -982,18 +979,39 @@ class ExportOdtTest extends AbstractTestCase $GLOBALS['odt_buffer'] = ''; $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'stand_in', 'test' ) ); $this->assertEquals( - 'Stand-in structure for view t&bl', + '' + . 'Stand-in structure for view test_table' + . '' + . 'Column' + . 'Type' + . 'Null' + . 'Default' + . '' + . 'id' + . 'int(11)' + . 'No' + . 'NULL' + . '' + . 'name' + . 'varchar(20)' + . 'No' + . 'NULL' + . '' + . 'datetimefield' + . 'datetime' + . 'No' + . 'NULL' + . '', $GLOBALS['odt_buffer'] ); } diff --git a/test/classes/Plugins/Export/ExportPhparrayTest.php b/test/classes/Plugins/Export/ExportPhparrayTest.php index 6eebe3ed84..6615436352 100644 --- a/test/classes/Plugins/Export/ExportPhparrayTest.php +++ b/test/classes/Plugins/Export/ExportPhparrayTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Plugins\Export; -use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Plugins\Export\ExportPhparray; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; @@ -32,12 +31,18 @@ class ExportPhparrayTest extends AbstractTestCase { parent::setUp(); parent::defineVersionConstants(); + parent::loadDefaultConfig(); $GLOBALS['server'] = 0; $GLOBALS['output_kanji_conversion'] = false; $GLOBALS['output_charset_conversion'] = false; $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = true; $GLOBALS['save_on_server'] = false; + $GLOBALS['db'] = ''; + $GLOBALS['table'] = ''; + $GLOBALS['lang'] = 'en'; + $GLOBALS['text_dir'] = 'ltr'; + $GLOBALS['PMA_PHP_SELF'] = ''; $this->object = new ExportPhparray(); } @@ -179,100 +184,49 @@ class ExportPhparrayTest extends AbstractTestCase public function testExportData(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('SELECT', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_UNBUFFERED) - ->will($this->returnValue(true)); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(true) - ->will($this->returnValue(2)); - - $dbi->expects($this->at(2)) - ->method('fieldName') - ->with(true, 0) - ->will($this->returnValue('c1')); - - $dbi->expects($this->at(3)) - ->method('fieldName') - ->with(true, 1) - ->will($this->returnValue('')); - - $dbi->expects($this->at(4)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue([1, 'a'])); - - $dbi->expects($this->at(5)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(null)); - - $GLOBALS['dbi'] = $dbi; - ob_start(); $this->assertTrue( $this->object->exportData( - 'db', - 'table', + 'test_db', + 'test_table', "\n", 'phpmyadmin.net/err', - 'SELECT' + 'SELECT * FROM `test_db`.`test_table`;' ) ); $result = ob_get_clean(); $this->assertEquals( - "\n" . '/* `db`.`table` */' . "\n" . - '$table = array(' . "\n" . - ' array(\'c1\' => 1,\'\' => \'a\')' . "\n" . + "\n" . '/* `test_db`.`test_table` */' . "\n" . + '$test_table = array(' . "\n" . + ' array(\'id\' => \'1\',\'name\' => \'abcd\',\'datetimefield\' => \'2011-01-20 02:00:02\'),' . "\n" . + ' array(\'id\' => \'2\',\'name\' => \'foo\',\'datetimefield\' => \'2010-01-20 02:00:02\'),' . "\n" . + ' array(\'id\' => \'3\',\'name\' => \'Abcd\',\'datetimefield\' => \'2012-01-20 02:00:02\')' . "\n" . ');' . "\n", $result ); // case 2: test invalid variable name fix - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('SELECT', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_UNBUFFERED) - ->will($this->returnValue(true)); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(true) - ->will($this->returnValue(0)); - - $dbi->expects($this->at(2)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue(null)); - - $GLOBALS['dbi'] = $dbi; - ob_start(); $this->assertTrue( $this->object->exportData( - 'db', + 'test_db', '0`932table', "\n", 'phpmyadmin.net/err', - 'SELECT' + 'SELECT * FROM `test_db`.`test_table`;' ) ); $result = ob_get_clean(); $this->assertIsString($result); - - $this->assertStringContainsString( - '$_0_932table', + $this->assertEquals( + "\n" . '/* `test_db`.`0``932table` */' . "\n" . + '$_0_932table = array(' . "\n" . + ' array(\'id\' => \'1\',\'name\' => \'abcd\',\'datetimefield\' => \'2011-01-20 02:00:02\'),' . "\n" . + ' array(\'id\' => \'2\',\'name\' => \'foo\',\'datetimefield\' => \'2010-01-20 02:00:02\'),' . "\n" . + ' array(\'id\' => \'3\',\'name\' => \'Abcd\',\'datetimefield\' => \'2012-01-20 02:00:02\')' . "\n" . + ');' . "\n", $result ); } diff --git a/test/classes/Plugins/Export/ExportSqlTest.php b/test/classes/Plugins/Export/ExportSqlTest.php index ea1504f489..005441d9ee 100644 --- a/test/classes/Plugins/Export/ExportSqlTest.php +++ b/test/classes/Plugins/Export/ExportSqlTest.php @@ -50,7 +50,12 @@ class ExportSqlTest extends AbstractTestCase parent::defineVersionConstants(); parent::loadDefaultConfig(); $GLOBALS['server'] = 0; - $GLOBALS['db'] = 'db'; + $GLOBALS['db'] = ''; + $GLOBALS['table'] = ''; + $GLOBALS['lang'] = 'en'; + $GLOBALS['text_dir'] = 'ltr'; + $GLOBALS['PMA_PHP_SELF'] = ''; + $GLOBALS['cfg']['Server']['DisableIS'] = true; $GLOBALS['output_kanji_conversion'] = false; $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = false; @@ -344,44 +349,15 @@ class ExportSqlTest extends AbstractTestCase $GLOBALS['crlf'] = '##'; $GLOBALS['sql_drop_table'] = true; - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->at(0)) - ->method('getProceduresOrFunctions') - ->with('db', 'PROCEDURE') - ->will($this->returnValue(['p1', 'p2'])); - - $dbi->expects($this->at(1)) - ->method('getProceduresOrFunctions') - ->with('db', 'FUNCTION') - ->will($this->returnValue(['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 ;##' + '##DELIMITER $$##DROP PROCEDURE IF EXISTS `test_proc1`$$##CREATE PROCEDURE' + . ' `test_proc1` (`p` INT) BEGIN END$$####DROP PROCEDURE IF EXISTS' + . ' `test_proc2`$$##CREATE PROCEDURE `test_proc2` (`p` INT) BEGIN END$$####DROP' + . ' FUNCTION IF EXISTS `test_func`$$##CREATE FUNCTION' + . ' `test_func` (`p` INT) RETURNS INT(11) BEGIN END$$####DELIMITER ;##' ); - $this->object->exportRoutines('db'); + $this->object->exportRoutines('test_db'); } public function testExportComment(): void @@ -1258,52 +1234,6 @@ class ExportSqlTest extends AbstractTestCase */ public function testExportStructure(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $dbi->expects($this->any())->method('escapeString') - ->will($this->returnArgument(0)); - - $dbi->expects($this->once()) - ->method('getTriggers') - ->with('db', 't&bl') - ->will( - $this->returnValue( - [ - [ - 'create' => 'bar', - 'drop' => 'foo', - ], - ] - ) - ); - - $this->object = $this->getMockBuilder(ExportSql::class) - ->onlyMethods(['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; @@ -1313,10 +1243,10 @@ class ExportSqlTest extends AbstractTestCase ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'create_table', 'test' ) @@ -1324,16 +1254,8 @@ class ExportSqlTest extends AbstractTestCase $result = ob_get_clean(); $this->assertIsString($result); - - $this->assertStringContainsString( - '-- Table structure for table "t&bl"', - $result - ); - - $this->assertStringContainsString( - 'dumpText1', - $result - ); + $this->assertStringContainsString('-- Table structure for table "test_table"', $result); + $this->assertStringContainsString('CREATE TABLE `test_table`', $result); // case 2 unset($GLOBALS['sql_compatibility']); @@ -1345,10 +1267,10 @@ class ExportSqlTest extends AbstractTestCase ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'triggers', 'test' ) @@ -1356,14 +1278,9 @@ class ExportSqlTest extends AbstractTestCase $result = ob_get_clean(); $this->assertIsString($result); - + $this->assertStringContainsString('-- Triggers test_table', $result); $this->assertStringContainsString( - "-- Triggers t&bl\n", - $result - ); - - $this->assertStringContainsString( - "foo;\nDELIMITER $$\nbarDELIMITER ;\n", + 'CREATE TRIGGER `test_trigger` AFTER INSERT ON `test_table` FOR EACH ROW BEGIN END', $result ); @@ -1376,10 +1293,10 @@ class ExportSqlTest extends AbstractTestCase ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'create_view', 'test' ) @@ -1387,43 +1304,21 @@ class ExportSqlTest extends AbstractTestCase $result = ob_get_clean(); $this->assertIsString($result); - - $this->assertStringContainsString( - "-- Structure for view t&bl\n", - $result - ); - - $this->assertStringContainsString( - "DROP TABLE IF EXISTS `t&bl`;\n" . - 'dumpText3', - $result - ); + $this->assertStringContainsString('-- Structure for view test_table', $result); + $this->assertStringContainsString('DROP TABLE IF EXISTS `test_table`;', $result); + $this->assertStringContainsString('CREATE TABLE `test_table`', $result); // case 4 - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $dbi->expects($this->any())->method('escapeString') - ->will($this->returnArgument(0)); - - $dbi->expects($this->once()) - ->method('getColumns') - ->will( - $this->returnValue( - [] - ) - ); - $GLOBALS['dbi'] = $dbi; $GLOBALS['sql_views_as_tables'] = true; unset($GLOBALS['sql_if_not_exists']); ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'create_view', 'test' ) @@ -1431,26 +1326,18 @@ class ExportSqlTest extends AbstractTestCase $result = ob_get_clean(); $this->assertIsString($result); - - $this->assertStringContainsString( - "CREATE TABLE`t&bl`(\n\n);", - $result - ); - - $this->assertStringContainsString( - "DROP TABLE IF EXISTS `t&bl`;\n", - $result - ); + $this->assertStringContainsString('-- Structure for view test_table exported as a table', $result); + $this->assertStringContainsString('DROP TABLE IF EXISTS `test_table`;', $result); + $this->assertStringContainsString('CREATE TABLE`test_table`', $result); // case 5 - ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'stand_in', 'test' ) @@ -1458,11 +1345,8 @@ class ExportSqlTest extends AbstractTestCase $result = ob_get_clean(); $this->assertIsString($result); - - $this->assertStringContainsString( - 'dumpText4', - $result - ); + $this->assertStringContainsString('-- Stand-in structure for view test_table', $result); + $this->assertStringContainsString('CREATE TABLE `test_table`', $result); } /** diff --git a/test/classes/Plugins/Export/ExportTexytextTest.php b/test/classes/Plugins/Export/ExportTexytextTest.php index 897b3167f3..5e4c72c3d8 100644 --- a/test/classes/Plugins/Export/ExportTexytextTest.php +++ b/test/classes/Plugins/Export/ExportTexytextTest.php @@ -45,6 +45,12 @@ class ExportTexytextTest extends AbstractTestCase $GLOBALS['plugin_param']['export_type'] = 'table'; $GLOBALS['plugin_param']['single_table'] = false; $GLOBALS['cfgRelation']['relation'] = true; + $GLOBALS['db'] = ''; + $GLOBALS['table'] = ''; + $GLOBALS['lang'] = 'en'; + $GLOBALS['text_dir'] = 'ltr'; + $GLOBALS['PMA_PHP_SELF'] = ''; + $GLOBALS['cfg']['Server']['DisableIS'] = true; $this->object = new ExportTexytext(); } @@ -206,38 +212,6 @@ class ExportTexytextTest extends AbstractTestCase public function testExportData(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('SELECT', DatabaseInterface::CONNECT_USER, 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([null, '0', 'test'])); - - $GLOBALS['dbi'] = $dbi; $GLOBALS['what'] = 'foo'; $GLOBALS['foo_columns'] = '&'; $GLOBALS['foo_null'] = '>'; @@ -245,80 +219,39 @@ class ExportTexytextTest extends AbstractTestCase ob_start(); $this->assertTrue( $this->object->exportData( - 'db', - 'taassertIsString($result); - - $this->assertStringContainsString( - '|fName1|fNa&quot;me2|fName3', - $result - ); - - $this->assertStringContainsString( - '|&gt;|0|test', + $this->assertEquals( + '== Dumping data for table test_table' . "\n\n" + . '|------' . "\n" + . '|id|name|datetimefield' . "\n" + . '|------' . "\n" + . '|1|abcd|2011-01-20 02:00:02' . "\n" + . '|2|foo|2010-01-20 02:00:02' . "\n" + . '|3|Abcd|2012-01-20 02:00:02' . "\n", $result ); } public function testGetTableDefStandIn(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $result = $this->object->getTableDefStandIn('test_db', 'test_table', "\n"); - $dbi->expects($this->once()) - ->method('getColumns') - ->with('db', 'view') - ->will($this->returnValue([1, 2])); - - $keys = [ - [ - 'Non_unique' => 0, - 'Column_name' => 'cname', - ], - [ - '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::class) - ->disableOriginalConstructor() - ->onlyMethods(['formatOneColumnDefinition']) - ->getMock(); - - $this->object->expects($this->at(0)) - ->method('formatOneColumnDefinition') - ->with(1, ['cname']) - ->will($this->returnValue('c1')); - - $this->object->expects($this->at(1)) - ->method('formatOneColumnDefinition') - ->with(2, ['cname']) - ->will($this->returnValue('c2')); - - $result = $this->object->getTableDefStandIn('db', 'view', '#'); - - $this->assertStringContainsString( - "c1\nc2", + $this->assertEquals( + '|------' . "\n" + . '|Column|Type|Null|Default' . "\n" + . '|------' . "\n" + . '|//**id**//|int(11)|No|NULL' . "\n" + . '|name|varchar(20)|No|NULL' . "\n" + . '|datetimefield|datetime|No|NULL' . "\n", $result ); } @@ -459,60 +392,14 @@ class ExportTexytextTest extends AbstractTestCase public function testExportStructure(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('getTriggers') - ->with('db', 't&bl') - ->will($this->returnValue(1)); - - $this->object = $this->getMockBuilder(ExportTexytext::class) - ->onlyMethods(['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', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'create_table', 'test' ) @@ -520,9 +407,14 @@ class ExportTexytextTest extends AbstractTestCase $result = ob_get_clean(); $this->assertIsString($result); - - $this->assertStringContainsString( - '== Table structure for table t&bl' . "\n\ndumpText1", + $this->assertEquals( + '== Table structure for table test_table' . "\n\n" + . '|------' . "\n" + . '|Column|Type|Null|Default' . "\n" + . '|------' . "\n" + . '|//**id**//|int(11)|No|NULL' . "\n" + . '|name|varchar(20)|No|NULL' . "\n" + . '|datetimefield|datetime|No|NULL' . "\n", $result ); @@ -530,10 +422,10 @@ class ExportTexytextTest extends AbstractTestCase ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'triggers', 'test' ) @@ -541,7 +433,11 @@ class ExportTexytextTest extends AbstractTestCase $result = ob_get_clean(); $this->assertEquals( - '== Triggers t&bl' . "\n\ndumpText2", + '== Triggers test_table' . "\n\n" + . '|------' . "\n" + . '|Name|Time|Event|Definition' . "\n" + . '|------' . "\n" + . '|test_trigger|AFTER|INSERT|BEGIN END' . "\n", $result ); @@ -549,10 +445,10 @@ class ExportTexytextTest extends AbstractTestCase ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'create_view', 'test' ) @@ -560,7 +456,13 @@ class ExportTexytextTest extends AbstractTestCase $result = ob_get_clean(); $this->assertEquals( - '== Structure for view t&bl' . "\n\ndumpText3", + '== Structure for view test_table' . "\n\n" + . '|------' . "\n" + . '|Column|Type|Null|Default' . "\n" + . '|------' . "\n" + . '|//**id**//|int(11)|No|NULL' . "\n" + . '|name|varchar(20)|No|NULL' . "\n" + . '|datetimefield|datetime|No|NULL' . "\n", $result ); @@ -568,10 +470,10 @@ class ExportTexytextTest extends AbstractTestCase ob_start(); $this->assertTrue( $this->object->exportStructure( - 'db', - 't&bl', + 'test_db', + 'test_table', "\n", - 'example.com', + 'localhost', 'stand_in', 'test' ) @@ -579,7 +481,13 @@ class ExportTexytextTest extends AbstractTestCase $result = ob_get_clean(); $this->assertEquals( - '== Stand-in structure for view t&bl' . "\n\ndumpText4", + '== Stand-in structure for view test_table' . "\n\n" + . '|------' . "\n" + . '|Column|Type|Null|Default' . "\n" + . '|------' . "\n" + . '|//**id**//|int(11)|No|NULL' . "\n" + . '|name|varchar(20)|No|NULL' . "\n" + . '|datetimefield|datetime|No|NULL' . "\n", $result ); } diff --git a/test/classes/Plugins/Export/ExportXmlTest.php b/test/classes/Plugins/Export/ExportXmlTest.php index a951b05d22..01411a26f3 100644 --- a/test/classes/Plugins/Export/ExportXmlTest.php +++ b/test/classes/Plugins/Export/ExportXmlTest.php @@ -34,6 +34,7 @@ class ExportXmlTest extends AbstractTestCase { parent::setUp(); parent::defineVersionConstants(); + parent::loadDefaultConfig(); $GLOBALS['server'] = 0; $GLOBALS['output_kanji_conversion'] = false; $GLOBALS['buffer_needed'] = false; @@ -44,6 +45,7 @@ class ExportXmlTest extends AbstractTestCase $GLOBALS['plugin_param']['single_table'] = false; $GLOBALS['cfgRelation']['relation'] = true; $GLOBALS['db'] = 'db'; + $GLOBALS['cfg']['Server']['DisableIS'] = true; $this->object = new ExportXml(); } @@ -455,96 +457,36 @@ class ExportXmlTest extends AbstractTestCase $GLOBALS['asfile'] = true; $GLOBALS['output_charset_conversion'] = false; - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $_table = $this->getMockBuilder(Table::class) - ->disableOriginalConstructor() - ->getMock(); - $_table->expects($this->once()) - ->method('isMerge') - ->will($this->returnValue(false)); - - $dbi->expects($this->any()) - ->method('getTable') - ->will($this->returnValue($_table)); - - $dbi->expects($this->once()) - ->method('getTable') - ->will($this->returnValue($_table)); - - $dbi->expects($this->once()) - ->method('query') - ->with('SELECT', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_UNBUFFERED) - ->will($this->returnValue(true)); - - $dbi->expects($this->once()) - ->method('numFields') - ->with(true) - ->will($this->returnValue(3)); - - $dbi->expects($this->at(3)) - ->method('fieldName') - ->will($this->returnValue('fName1')); - - $dbi->expects($this->at(4)) - ->method('fieldName') - ->will($this->returnValue('fNa"me2')); - - $dbi->expects($this->at(5)) - ->method('fieldName') - ->will($this->returnValue('fNa\\me3')); - - $dbi->expects($this->at(6)) - ->method('fetchRow') - ->with(true) - ->will($this->returnValue([null, ''])); - - $GLOBALS['dbi'] = $dbi; - ob_start(); $this->assertTrue( $this->object->exportData( - 'db', - 'taassertIsString($result); - - $this->assertStringContainsString( - '', - $result - ); - - $this->assertStringContainsString( - '', - $result - ); - - $this->assertStringContainsString( - 'NULL', - $result - ); - - $this->assertStringContainsString( - '<a>' . - '', - $result - ); - - $this->assertStringContainsString( - 'NULL', - $result - ); - - $this->assertStringContainsString( - '
', + $this->assertEquals( + ' ' . "\n" + . ' ' . "\n" + . ' 1' . "\n" + . ' abcd' . "\n" + . ' 2011-01-20 02:00:02' . "\n" + . '
' . "\n" + . ' ' . "\n" + . ' 2' . "\n" + . ' foo' . "\n" + . ' 2010-01-20 02:00:02' . "\n" + . '
' . "\n" + . ' ' . "\n" + . ' 3' . "\n" + . ' Abcd' . "\n" + . ' 2012-01-20 02:00:02' . "\n" + . '
' . "\n", $result ); } diff --git a/test/classes/Plugins/Export/ExportYamlTest.php b/test/classes/Plugins/Export/ExportYamlTest.php index b767aa4210..1765d81612 100644 --- a/test/classes/Plugins/Export/ExportYamlTest.php +++ b/test/classes/Plugins/Export/ExportYamlTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Plugins\Export; -use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Plugins\Export\ExportYaml; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; @@ -31,6 +30,8 @@ class ExportYamlTest extends AbstractTestCase protected function setUp(): void { parent::setUp(); + parent::defineVersionConstants(); + parent::loadDefaultConfig(); $GLOBALS['server'] = 0; $GLOBALS['output_kanji_conversion'] = false; $GLOBALS['buffer_needed'] = false; @@ -38,6 +39,11 @@ class ExportYamlTest extends AbstractTestCase $GLOBALS['save_on_server'] = false; $GLOBALS['crlf'] = "\n"; $GLOBALS['cfgRelation']['relation'] = true; + $GLOBALS['db'] = ''; + $GLOBALS['table'] = ''; + $GLOBALS['lang'] = 'en'; + $GLOBALS['text_dir'] = 'ltr'; + $GLOBALS['PMA_PHP_SELF'] = ''; $this->object = new ExportYaml(); } @@ -165,78 +171,32 @@ class ExportYamlTest extends AbstractTestCase public function testExportData(): void { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->with('SELECT', DatabaseInterface::CONNECT_USER, 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( - [ - null, - '123', - "\"c\\a\nb\r", - ] - ) - ); - - $dbi->expects($this->at(7)) - ->method('fetchRow') - ->with(true) - ->will( - $this->returnValue( - [null] - ) - ); - - $GLOBALS['dbi'] = $dbi; - ob_start(); $this->assertTrue( $this->object->exportData( - 'db', - 'taassertEquals( - '# db.ta<ble' . "\n" . + '# test_db.test_table' . "\n" . '-' . "\n" . - ' fNa"me2: 123' . "\n" . - ' fName3: "\"c\\\\a\nb\r"' . "\n" . - '-' . "\n", + ' id: 1' . "\n" . + ' name: "abcd"' . "\n" . + ' datetimefield: "2011-01-20 02:00:02"' . "\n" . + '-' . "\n" . + ' id: 2' . "\n" . + ' name: "foo"' . "\n" . + ' datetimefield: "2010-01-20 02:00:02"' . "\n" . + '-' . "\n" . + ' id: 3' . "\n" . + ' name: "Abcd"' . "\n" . + ' datetimefield: "2012-01-20 02:00:02"' . "\n", $result ); } diff --git a/test/classes/Stubs/DbiDummy.php b/test/classes/Stubs/DbiDummy.php index c480b74a48..f5fcd06f07 100644 --- a/test/classes/Stubs/DbiDummy.php +++ b/test/classes/Stubs/DbiDummy.php @@ -396,7 +396,12 @@ class DbiDummy implements DbiExtension */ public function fieldName($result, $i) { - return ''; + $query_data = &$this->getQueryData($result); + if (! isset($query_data['columns'])) { + return ''; + } + + return $query_data['columns'][$i]; } /** @@ -2182,63 +2187,106 @@ class DbiDummy implements DbiExtension ], ], [ - 'query' => 'SHOW COLUMNS FROM `test_db`.`test_table`', - 'columns' => [ - 'Field', - 'Type', - 'Null', - 'Key', - 'Default', - 'Extra', + 'query' => 'SHOW CREATE TABLE `test_db`.`test_table`', + 'columns' => ['Table', 'Create Table'], + 'result' => [['test_table', 'CREATE TABLE `test_table`']], + ], + [ + 'query' => 'SHOW COLUMNS FROM `test_db`.`test_table`', + 'columns' => ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra'], + 'result' => [ + ['id', 'int(11)', 'NO', 'PRI', 'NULL', 'auto_increment'], + ['name', 'varchar(20)', 'NO', '', 'NULL', ''], + ['datetimefield', 'datetime', 'NO', '', 'NULL', ''], ], - 'result' => [ - [ - 'id', - 'int(11)', - 'NO', - 'PRI', - 'NULL', - 'auto_increment', - ], - [ - 'name', - 'varchar(20)', - 'NO', - '', - 'NULL', - '', - ], - [ - 'datetimefield', - 'datetime', - 'NO', - '', - 'NULL', - '', - ], + ], + [ + 'query' => 'SHOW FULL COLUMNS FROM `test_db`.`test_table`', + 'columns' => ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra'], + 'result' => [ + ['id', 'int(11)', 'NO', 'PRI', 'NULL', 'auto_increment'], + ['name', 'varchar(20)', 'NO', '', 'NULL', ''], + ['datetimefield', 'datetime', 'NO', '', 'NULL', ''], ], ], + [ + 'query' => 'DESC `test_db`.`test_table`', + 'columns' => ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra'], + 'result' => [ + ['id', 'int(11)', 'NO', 'PRI', 'NULL', 'auto_increment'], + ['name', 'varchar(20)', 'NO', '', 'NULL', ''], + ['datetimefield', 'datetime', 'NO', '', 'NULL', ''], + ], + ], + [ + 'query' => 'SHOW TABLE STATUS FROM `test_db` WHERE `Name` LIKE \'test\_table%\'', + 'columns' => ['Name', 'Engine', 'Rows'], + 'result' => [['test_table', 'InnoDB', '3']], + ], + [ + 'query' => 'SHOW TABLE STATUS FROM `test_db` WHERE Name = \'test_table\'', + 'columns' => ['Name', 'Engine', 'Rows'], + 'result' => [['test_table', 'InnoDB', '3']], + ], + [ + 'query' => 'SHOW INDEXES FROM `test_db`.`test_table`', + 'columns' => ['Table', 'Non_unique', 'Key_name', 'Column_name'], + 'result' => [['test_table', '0', 'PRIMARY', 'id']], + ], + [ + 'query' => 'SHOW TRIGGERS FROM `test_db` LIKE \'test_table\';', + 'columns' => ['Trigger', 'Event', 'Table', 'Statement', 'Timing', 'Definer'], + 'result' => [['test_trigger', 'INSERT', 'test_table', 'BEGIN END', 'AFTER', 'definer@localhost']], + ], [ 'query' => 'SELECT * FROM `test_db`.`test_table`;', 'columns' => ['id', 'name', 'datetimefield'], 'result' => [ - [ - '1', - 'abcd', - '2011-01-20 02:00:02', - ], - [ - '2', - 'foo', - '2011-01-20 02:00:02', - ], - [ - '3', - 'Abcd', - '2011-01-20 02:00:02', - ], + ['1', 'abcd', '2011-01-20 02:00:02'], + ['2', 'foo', '2010-01-20 02:00:02'], + ['3', 'Abcd', '2012-01-20 02:00:02'], ], ], + [ + 'query' => 'SHOW PROCEDURE STATUS;', + 'columns' => ['Db', 'Name', 'Type'], + 'result' => [ + ['test_db', 'test_proc1', 'PROCEDURE'], + ['test_db', 'test_proc2', 'PROCEDURE'], + ], + ], + [ + 'query' => 'SHOW FUNCTION STATUS;', + 'columns' => ['Db', 'Name', 'Type'], + 'result' => [['test_db', 'test_func', 'FUNCTION']], + ], + [ + 'query' => 'SHOW CREATE PROCEDURE `test_db`.`test_proc1`', + 'columns' => ['Procedure', 'Create Procedure'], + 'result' => [['test_proc1', 'CREATE PROCEDURE `test_proc1` (p INT) BEGIN END']], + ], + [ + 'query' => 'SHOW CREATE PROCEDURE `test_db`.`test_proc2`', + 'columns' => ['Procedure', 'Create Procedure'], + 'result' => [['test_proc2', 'CREATE PROCEDURE `test_proc2` (p INT) BEGIN END']], + ], + [ + 'query' => 'SHOW CREATE FUNCTION `test_db`.`test_func`', + 'columns' => ['Function', 'Create Function'], + 'result' => [['test_func', 'CREATE FUNCTION `test_func` (p INT) RETURNS int(11) BEGIN END']], + ], + [ + 'query' => 'USE `test_db`', + 'result' => [], + ], + [ + 'query' => 'SET SQL_QUOTE_SHOW_CREATE = 0', + 'result' => [], + ], + [ + 'query' => 'SET SQL_QUOTE_SHOW_CREATE = 1', + 'result' => [], + ], ]; /** * Current database.