Merge pull request #16707 from mauriciofauth/export-plugins-tests
Remove PHPUnit's at matcher from Export plugins tests
This commit is contained in:
commit
5574b7c423
@ -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]);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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(
|
||||
'<?xml version="1.0" encoding="utf-8" ?>',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'<class name="TestTable" table="TestTable">',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'</class>',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'</hibernate-mapping>',
|
||||
$this->assertEquals(
|
||||
'<?xml version="1.0" encoding="utf-8" ?>' . "\n"
|
||||
. '<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Test_db" assembly="Test_db">' . "\n"
|
||||
. ' <class name="Test_table" table="Test_table">' . "\n"
|
||||
. ' <id name="Id" type="Int32" unsaved-value="0">' . "\n"
|
||||
. ' <column name="id" sql-type="int" not-null="true" unique="true" index="PRIMARY"/>' . "\n"
|
||||
. ' <generator class="native" />' . "\n"
|
||||
. ' </id>' . "\n"
|
||||
. ' <property name="Name" type="String">' . "\n"
|
||||
. ' <column name="name" sql-type="varchar" not-null="true" />' . "\n"
|
||||
. ' </property>' . "\n"
|
||||
. ' <property name="Datetimefield" type="DateTime">' . "\n"
|
||||
. ' <column name="datetimefield" sql-type="datetime" not-null="true" />' . "\n"
|
||||
. ' </property>' . "\n"
|
||||
. ' </class>' . "\n"
|
||||
. '</hibernate-mapping>',
|
||||
$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(
|
||||
'<?xml version="1.0" encoding="utf-8" ?>' . "\n" .
|
||||
'<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Db" ' .
|
||||
'assembly="Db">' . "\n" .
|
||||
' <class name="Table" table="Table">' . "\n" .
|
||||
' <property name="A" type="Unknown">' . "\n" .
|
||||
' <column name="a" sql-type="b" not-null="false" />' . "\n" .
|
||||
' </property>' . "\n" .
|
||||
' <id name="G" type="Unknown" unsaved-value="0">' . "\n" .
|
||||
' <column name="g" sql-type="h" not-null="false" ' .
|
||||
'unique="true" index="PRIMARY"/>' . "\n" .
|
||||
'<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Test_db" assembly="Test_db">' . "\n" .
|
||||
' <class name="Test_table" table="Test_table">' . "\n" .
|
||||
' <id name="Id" type="Int32" unsaved-value="0">' . "\n" .
|
||||
' <column name="id" sql-type="int" not-null="true" unique="true" index="PRIMARY"/>' . "\n" .
|
||||
' <generator class="native" />' . "\n" .
|
||||
' </id>' . "\n" .
|
||||
' <property name="Name" type="String">' . "\n" .
|
||||
' <column name="name" sql-type="varchar" not-null="true" />' . "\n" .
|
||||
' </property>' . "\n" .
|
||||
' <property name="Datetimefield" type="DateTime">' . "\n" .
|
||||
' <column name="datetimefield" sql-type="datetime" not-null="true" />' . "\n" .
|
||||
' </property>' . "\n" .
|
||||
' </class>' . "\n" .
|
||||
'</hibernate-mapping>',
|
||||
$result
|
||||
|
||||
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@ -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(
|
||||
'<h2>Dumping data for table testTable</h2>' .
|
||||
'<table class="pma-table w-100" cellspacing="1"><tr class="print-category">' .
|
||||
'<td class="print"><strong>foobar</strong></td>' .
|
||||
'<td class="print"><strong>foobar</strong></td>' .
|
||||
'<td class="print"><strong>foobar</strong></td>' .
|
||||
'<td class="print"><strong>foobar</strong></td>' .
|
||||
'<td class="print"><strong>foobar</strong></td>' .
|
||||
'</tr><tr class="print-category"><td class="print">' .
|
||||
'customNull</td><td class="print">0</td><td class="print">test</td>' .
|
||||
'<td class="print"></td><td class="print">customNull</td></tr></table>',
|
||||
'<h2>Dumping data for table test_table</h2>'
|
||||
. '<table class="pma-table w-100" cellspacing="1"><tr class="print-category">'
|
||||
. '<td class="print"><strong>id</strong></td>'
|
||||
. '<td class="print"><strong>name</strong></td>'
|
||||
. '<td class="print"><strong>datetimefield</strong></td>'
|
||||
. '</tr><tr class="print-category">'
|
||||
. '<td class="print">1</td><td class="print">abcd</td><td class="print">2011-01-20 02:00:02</td>'
|
||||
. '</tr><tr class="print-category">'
|
||||
. '<td class="print">2</td><td class="print">foo</td><td class="print">2010-01-20 02:00:02</td>'
|
||||
. '</tr><tr class="print-category">'
|
||||
. '<td class="print">3</td><td class="print">Abcd</td><td class="print">2012-01-20 02:00:02</td>'
|
||||
. '</tr></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(
|
||||
'<h2>Table structure for table tbl</h2>dumpText1',
|
||||
'<h2>Table structure for table test_table</h2>'
|
||||
. '<table class="pma-table w-100" cellspacing="1"><tr class="print-category">'
|
||||
. '<th class="print">Column</th><td class="print"><strong>Type</strong></td>'
|
||||
. '<td class="print"><strong>Null</strong></td><td class="print"><strong>Default</strong></td></tr>'
|
||||
. '<tr class="print-category"><td class="print"><em><strong>id</strong></em></td>'
|
||||
. '<td class="print">int(11)</td><td class="print">No</td><td class="print">NULL</td></tr>'
|
||||
. '<tr class="print-category"><td class="print">name</td><td class="print">varchar(20)</td>'
|
||||
. '<td class="print">No</td><td class="print">NULL</td></tr><tr class="print-category">'
|
||||
. '<td class="print">datetimefield</td><td class="print">datetime</td>'
|
||||
. '<td class="print">No</td><td class="print">NULL</td></tr></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(
|
||||
'<h2>Triggers tbl</h2>dumpText2',
|
||||
'<h2>Triggers test_table</h2><table class="pma-table w-100" cellspacing="1">'
|
||||
. '<tr class="print-category"><th class="print">Name</th>'
|
||||
. '<td class="print"><strong>Time</strong></td><td class="print"><strong>Event</strong></td>'
|
||||
. '<td class="print"><strong>Definition</strong></td></tr><tr class="print-category">'
|
||||
. '<td class="print">test_trigger</td><td class="print">AFTER</td>'
|
||||
. '<td class="print">INSERT</td><td class="print">BEGIN END</td></tr></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(
|
||||
'<h2>Structure for view tbl</h2>dumpText3',
|
||||
'<h2>Structure for view test_table</h2>'
|
||||
. '<table class="pma-table w-100" cellspacing="1"><tr class="print-category">'
|
||||
. '<th class="print">Column</th><td class="print"><strong>Type</strong></td>'
|
||||
. '<td class="print"><strong>Null</strong></td><td class="print"><strong>Default</strong>'
|
||||
. '</td></tr><tr class="print-category"><td class="print"><em><strong>id</strong></em></td>'
|
||||
. '<td class="print">int(11)</td><td class="print">No</td><td class="print">NULL</td></tr>'
|
||||
. '<tr class="print-category"><td class="print">name</td><td class="print">varchar(20)</td>'
|
||||
. '<td class="print">No</td><td class="print">NULL</td></tr><tr class="print-category">'
|
||||
. '<td class="print">datetimefield</td><td class="print">datetime</td>'
|
||||
. '<td class="print">No</td><td class="print">NULL</td></tr></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(
|
||||
'<h2>Stand-in structure for view tbl</h2>dumpText4',
|
||||
'<h2>Stand-in structure for view test_table</h2>'
|
||||
. '<table class="pma-table w-100" cellspacing="1"><tr class="print-category">'
|
||||
. '<th class="print">Column</th><td class="print"><strong>Type</strong></td>'
|
||||
. '<td class="print"><strong>Null</strong></td><td class="print"><strong>Default</strong></td>'
|
||||
. '</tr><tr class="print-category">'
|
||||
. '<td class="print"><em><strong>id</strong></em></td><td class="print">int(11)</td>'
|
||||
. '<td class="print">No</td><td class="print">NULL</td></tr><tr class="print-category">'
|
||||
. '<td class="print">name</td><td class="print">varchar(20)</td><td class="print">No</td>'
|
||||
. '<td class="print">NULL</td></tr><tr class="print-category">'
|
||||
. '<td class="print">datetimefield</td><td class="print">datetime</td>'
|
||||
. '<td class="print">No</td><td class="print">NULL</td></tr></table>',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
@ -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`;'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@ -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
|
||||
);
|
||||
|
||||
@ -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(
|
||||
'<table:table table:name="v&w_data">',
|
||||
$GLOBALS['odt_buffer']
|
||||
);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'</table:table-row>c1</table:table-row>c2</table:table-row>' .
|
||||
'</table:table>',
|
||||
$this->assertEquals(
|
||||
'<table:table table:name="test_table_data">'
|
||||
. '<table:table-column table:number-columns-repeated="4"/><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Column</text:p>'
|
||||
. '</table:table-cell><table:table-cell office:value-type="string"><text:p>Type</text:p>'
|
||||
. '</table:table-cell><table:table-cell office:value-type="string"><text:p>Null</text:p>'
|
||||
. '</table:table-cell><table:table-cell office:value-type="string"><text:p>Default</text:p>'
|
||||
. '</table:table-cell></table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>id</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>int(11)</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>name</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>varchar(20)</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>datetimefield</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>datetime</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row></table:table>',
|
||||
$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(
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2" ' .
|
||||
'text:is-list-header="true">Table structure for table t&bl</text:h>',
|
||||
$this->assertEquals(
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
|
||||
. 'Table structure for table test_table</text:h><table:table table:name="test_table_structure">'
|
||||
. '<table:table-column table:number-columns-repeated="4"/><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Column</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Type</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Null</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Default</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>id</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>int(11)</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>name</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>varchar(20)</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>datetimefield</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>datetime</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row></table:table>',
|
||||
$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(
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2" ' .
|
||||
'text:is-list-header="true">Triggers t&bl</text:h>',
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
|
||||
. 'Triggers test_table</text:h><table:table table:name="test_table_triggers">'
|
||||
. '<table:table-column table:number-columns-repeated="4"/><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Name</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Time</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Event</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Definition</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>test_trigger</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>AFTER</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>INSERT</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>BEGIN END</text:p></table:table-cell>'
|
||||
. '</table:table-row></table:table>',
|
||||
$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(
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2" ' .
|
||||
'text:is-list-header="true">Structure for view t&bl</text:h>',
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
|
||||
. 'Structure for view test_table</text:h><table:table table:name="test_table_structure">'
|
||||
. '<table:table-column table:number-columns-repeated="4"/><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Column</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Type</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Null</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Default</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>id</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>int(11)</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>name</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>varchar(20)</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>datetimefield</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>datetime</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row></table:table>',
|
||||
$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(
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2" text:is' .
|
||||
'-list-header="true">Stand-in structure for view t&bl</text:h>',
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
|
||||
. 'Stand-in structure for view test_table</text:h><table:table table:name="test_table_data">'
|
||||
. '<table:table-column table:number-columns-repeated="4"/><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Column</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Type</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Null</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>Default</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>id</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>int(11)</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>name</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>varchar(20)</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row><table:table-row>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>datetimefield</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>datetime</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>No</text:p></table:table-cell>'
|
||||
. '<table:table-cell office:value-type="string"><text:p>NULL</text:p></table:table-cell>'
|
||||
. '</table:table-row></table:table>',
|
||||
$GLOBALS['odt_buffer']
|
||||
);
|
||||
}
|
||||
|
||||
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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',
|
||||
'ta<ble',
|
||||
'test_db',
|
||||
'test_table',
|
||||
"\n",
|
||||
'example.com',
|
||||
'SELECT'
|
||||
'localhost',
|
||||
'SELECT * FROM `test_db`.`test_table`;'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertIsString($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
|
||||
);
|
||||
}
|
||||
|
||||
@ -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, '<a>']));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
ob_start();
|
||||
$this->assertTrue(
|
||||
$this->object->exportData(
|
||||
'db',
|
||||
'ta<ble',
|
||||
'test_db',
|
||||
'test_table',
|
||||
"\n",
|
||||
'example.com',
|
||||
'SELECT'
|
||||
'localhost',
|
||||
'SELECT * FROM `test_db`.`test_table`;'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertIsString($result);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'<!-- Table ta<ble -->',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'<table name="ta<ble">',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'<column name="fName1">NULL</column>',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'<column name="fNa"me2"><a>' .
|
||||
'</column>',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'<column name="fName3">NULL</column>',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'</table>',
|
||||
$this->assertEquals(
|
||||
' <!-- Table test_table -->' . "\n"
|
||||
. ' <table name="test_table">' . "\n"
|
||||
. ' <column name="id">1</column>' . "\n"
|
||||
. ' <column name="name">abcd</column>' . "\n"
|
||||
. ' <column name="datetimefield">2011-01-20 02:00:02</column>' . "\n"
|
||||
. ' </table>' . "\n"
|
||||
. ' <table name="test_table">' . "\n"
|
||||
. ' <column name="id">2</column>' . "\n"
|
||||
. ' <column name="name">foo</column>' . "\n"
|
||||
. ' <column name="datetimefield">2010-01-20 02:00:02</column>' . "\n"
|
||||
. ' </table>' . "\n"
|
||||
. ' <table name="test_table">' . "\n"
|
||||
. ' <column name="id">3</column>' . "\n"
|
||||
. ' <column name="name">Abcd</column>' . "\n"
|
||||
. ' <column name="datetimefield">2012-01-20 02:00:02</column>' . "\n"
|
||||
. ' </table>' . "\n",
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
@ -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',
|
||||
'ta<ble',
|
||||
'test_db',
|
||||
'test_table',
|
||||
"\n",
|
||||
'example.com',
|
||||
'SELECT'
|
||||
'localhost',
|
||||
'SELECT * FROM `test_db`.`test_table`;'
|
||||
)
|
||||
);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
'# 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
|
||||
);
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user