Initial commit

This commit is contained in:
2022-11-21 09:47:28 +01:00
commit 76cec83d26
11652 changed files with 1980467 additions and 0 deletions

View File

@ -0,0 +1,482 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportCodegen class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportCodegen;
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportCodegen class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportCodegenTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['server'] = 0;
$this->object = new ExportCodegen(null);
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportCodegen::initSpecificVariables
*
* @return void
*/
public function testInitSpecificVariables()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportCodegen', 'initSpecificVariables');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrCgFormats = new ReflectionProperty('PMA\libraries\plugins\export\ExportCodegen', '_cgFormats');
$attrCgFormats->setAccessible(true);
$attrCgHandlers = new ReflectionProperty('PMA\libraries\plugins\export\ExportCodegen', '_cgHandlers');
$attrCgHandlers->setAccessible(true);
$this->assertEquals(
array(
"NHibernate C# DO",
"NHibernate XML"
),
$attrCgFormats->getValue($this->object)
);
$this->assertEquals(
array(
"_handleNHibernateCSBody",
"_handleNHibernateXMLBody"
),
$attrCgHandlers->getValue($this->object)
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCodegen::setProperties
*
* @return void
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportCodegen', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportCodegen', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'CodeGen',
$properties->getText()
);
$this->assertEquals(
'cs',
$properties->getExtension()
);
$this->assertEquals(
'text/cs',
$properties->getMimeType()
);
$this->assertEquals(
'Options',
$properties->getOptionsText()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = $generalOptionsArray[0];
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$hidden = $generalProperties[0];
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\HiddenPropertyItem',
$hidden
);
$this->assertEquals(
'structure_or_data',
$hidden->getName()
);
$select = $generalProperties[1];
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\SelectPropertyItem',
$select
);
$this->assertEquals(
'format',
$select->getName()
);
$this->assertEquals(
'Format:',
$select->getText()
);
$this->assertEquals(
array(
"NHibernate C# DO",
"NHibernate XML"
),
$select->getValues()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCodegen::exportHeader
*
* @return void
*/
public function testExportHeader()
{
$this->assertTrue(
$this->object->exportHeader()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCodegen::exportFooter
*
* @return void
*/
public function testExportFooter()
{
$this->assertTrue(
$this->object->exportFooter()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCodegen::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
$this->assertTrue(
$this->object->exportDBHeader('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCodegen::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$this->assertTrue(
$this->object->exportDBFooter('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCodegen::exportData
*
* @return void
*/
public function testExportData()
{
$GLOBALS['codegen_format'] = 1;
$GLOBALS['output_kanji_conversion'] = false;
$GLOBALS['output_charset_conversion'] = false;
$GLOBALS['buffer_needed'] = false;
$GLOBALS['asfile'] = true;
$GLOBALS['save_on_server'] = false;
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
ob_start();
$this->object->exportData(
'testDB', 'testTable', "\n", 'example.com', 'test'
);
$result = ob_get_clean();
$this->assertContains(
'<?xml version="1.0" encoding="utf-8" ?>',
$result
);
$this->assertContains(
'<class name="TestTable" table="TestTable">',
$result
);
$this->assertContains(
'</class>',
$result
);
$this->assertContains(
'</hibernate-mapping>',
$result
);
$GLOBALS['codegen_format'] = 4;
$this->object->exportData(
'testDB', 'testTable', "\n", 'example.com', 'test'
);
$this->expectOutputString(
'4 is not supported.'
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCodegen::cgMakeIdentifier
*
* @return void
*/
public function testCgMakeIdentifier()
{
$this->assertEquals(
'_Ⅲfoo',
ExportCodegen::cgMakeIdentifier('Ⅲ{}96`{}foo', true)
);
$this->assertEquals(
'TestⅢ',
ExportCodegen::cgMakeIdentifier('`98testⅢ{}96`{}', true)
);
$this->assertEquals(
'testⅢ',
ExportCodegen::cgMakeIdentifier('`98testⅢ{}96`{}', false)
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCodegen::_handleNHibernateCSBody
*
* @return void
*/
public function testHandleNHibernateCSBody()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->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(array('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('PMA\libraries\plugins\export\ExportCodegen', '_handleNHibernateCSBody');
$method->setAccessible(true);
$result = $method->invoke($this->object, 'db', '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" .
"}",
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCodegen::_handleNHibernateXMLBody
*
* @return void
*/
public function testHandleNHibernateXMLBody()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->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(array('a', 'b', 'c', false, 'e', 'f')));
$dbi->expects($this->at(2))
->method('fetchRow')
->with(true)
->will($this->returnValue(array('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('PMA\libraries\plugins\export\ExportCodegen', '_handleNHibernateXMLBody');
$method->setAccessible(true);
$result = $method->invoke($this->object, 'db', '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" .
' <generator class="native" />' . "\n" .
' </id>' . "\n" .
' </class>' . "\n" .
'</hibernate-mapping>',
$result
);
}
/**
* Test for
* - PMA\libraries\plugins\export\ExportCodegen::_getCgFormats
* - PMA\libraries\plugins\export\ExportCodegen::_setCgFormats
*
* @return void
*/
public function testSetGetCgFormats()
{
$reflection = new ReflectionClass('PMA\libraries\plugins\export\ExportCodegen');
$getter = $reflection->getMethod('_getCgFormats');
$setter = $reflection->getMethod('_setCgFormats');
$getter->setAccessible(true);
$setter->setAccessible(true);
$setter->invoke($this->object, array(1, 2));
$this->assertEquals(
array(1, 2),
$getter->invoke($this->object)
);
}
/**
* Test for
* - PMA\libraries\plugins\export\ExportCodegen::_getCgHandlers
* - PMA\libraries\plugins\export\ExportCodegen::_setCgHandlers
*
* @return void
*/
public function testSetGetCgHandlers()
{
$reflection = new ReflectionClass('PMA\libraries\plugins\export\ExportCodegen');
$getter = $reflection->getMethod('_getCgHandlers');
$setter = $reflection->getMethod('_setCgHandlers');
$getter->setAccessible(true);
$setter->setAccessible(true);
$setter->invoke($this->object, array(1, 2));
$this->assertEquals(
array(1, 2),
$getter->invoke($this->object)
);
}
}

View File

@ -0,0 +1,750 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportCsv class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportCsv;
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportCsv class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportCsvTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['server'] = 0;
$this->object = new ExportCsv();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportCsv::setProperties
*
* @return void
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportCsv', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportCsv', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'CSV',
$properties->getText()
);
$this->assertEquals(
'csv',
$properties->getExtension()
);
$this->assertEquals(
'text/comma-separated-values',
$properties->getMimeType()
);
$this->assertEquals(
'Options',
$properties->getOptionsText()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = $generalOptionsArray[0];
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'separator',
$property->getName()
);
$this->assertEquals(
'Columns separated with:',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'enclosed',
$property->getName()
);
$this->assertEquals(
'Columns enclosed with:',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'escaped',
$property->getName()
);
$this->assertEquals(
'Columns escaped with:',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'terminated',
$property->getName()
);
$this->assertEquals(
'Lines terminated with:',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'null',
$property->getName()
);
$this->assertEquals(
'Replace NULL with:',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'removeCRLF',
$property->getName()
);
$this->assertEquals(
'Remove carriage return/line feed characters within columns',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'columns',
$property->getName()
);
$this->assertEquals(
'Put columns names in the first row',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\HiddenPropertyItem',
$property
);
$this->assertEquals(
'structure_or_data',
$property->getName()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCsv::exportHeader
*
* @return void
*/
public function testExportHeader()
{
// case 1
$GLOBALS['what'] = 'excel';
$GLOBALS['excel_edition'] = 'win';
$GLOBALS['excel_columns'] = true;
$this->assertTrue(
$this->object->exportHeader()
);
$this->assertEquals(
"\015\012",
$GLOBALS['csv_terminated']
);
$this->assertEquals(
";",
$GLOBALS['csv_separator']
);
$this->assertEquals(
'"',
$GLOBALS['csv_enclosed']
);
$this->assertEquals(
'"',
$GLOBALS['csv_escaped']
);
$this->assertEquals(
'yes',
$GLOBALS['csv_columns']
);
// case 2
$GLOBALS['excel_edition'] = 'mac_excel2003';
unset($GLOBALS['excel_columns']);
$GLOBALS['csv_columns'] = 'no';
$this->assertTrue(
$this->object->exportHeader()
);
$this->assertEquals(
"\015\012",
$GLOBALS['csv_terminated']
);
$this->assertEquals(
";",
$GLOBALS['csv_separator']
);
$this->assertEquals(
'"',
$GLOBALS['csv_enclosed']
);
$this->assertEquals(
'"',
$GLOBALS['csv_escaped']
);
$this->assertEquals(
'no',
$GLOBALS['csv_columns']
);
// case 3
$GLOBALS['excel_edition'] = 'mac_excel2008';
$this->assertTrue(
$this->object->exportHeader()
);
$this->assertEquals(
"\015\012",
$GLOBALS['csv_terminated']
);
$this->assertEquals(
",",
$GLOBALS['csv_separator']
);
$this->assertEquals(
'"',
$GLOBALS['csv_enclosed']
);
$this->assertEquals(
'"',
$GLOBALS['csv_escaped']
);
$this->assertEquals(
'no',
$GLOBALS['csv_columns']
);
// case 4
$GLOBALS['excel_edition'] = 'testBlank';
$GLOBALS['csv_separator'] = '#';
$this->assertTrue(
$this->object->exportHeader()
);
$this->assertEquals(
'#',
$GLOBALS['csv_separator']
);
// case 5
$GLOBALS['what'] = 'notExcel';
$GLOBALS['crlf'] = "\n";
$GLOBALS['csv_terminated'] = '';
$GLOBALS['csv_separator'] = 'a\\t';
$this->assertTrue(
$this->object->exportHeader()
);
$this->assertEquals(
$GLOBALS['csv_terminated'],
"\n"
);
$this->assertEquals(
$GLOBALS['csv_separator'],
"a\011"
);
// case 6
$GLOBALS['csv_terminated'] = 'AUTO';
$this->assertTrue(
$this->object->exportHeader()
);
$this->assertEquals(
$GLOBALS['csv_terminated'],
"\n"
);
// case 7
$GLOBALS['csv_terminated'] = 'a\\rb\\nc\\t';
$GLOBALS['csv_separator'] = 'a\\t';
$this->assertTrue(
$this->object->exportHeader()
);
$this->assertEquals(
$GLOBALS['csv_terminated'],
"a\015b\012c\011"
);
$this->assertEquals(
$GLOBALS['csv_separator'],
"a\011"
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCsv::exportFooter
*
* @return void
*/
public function testExportFooter()
{
$this->assertTrue(
$this->object->exportFooter()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCsv::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
$this->assertTrue(
$this->object->exportDBHeader('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCsv::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$this->assertTrue(
$this->object->exportDBFooter('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCsv::exportDBCreate
*
* @return void
*/
public function testExportDBCreate()
{
$this->assertTrue(
$this->object->exportDBCreate('testDB', 'database')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportCsv::exportData
*
* @return void
*/
public function testExportData()
{
// case 1
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
$GLOBALS['csv_columns'] = 'yes';
$GLOBALS['csv_terminated'] = ';';
$GLOBALS['output_kanji_conversion'] = false;
$GLOBALS['output_charset_conversion'] = false;
$GLOBALS['buffer_needed'] = false;
$GLOBALS['asfile'] = true;
$GLOBALS['save_on_server'] = true;
$GLOBALS['file_handle'] = null;
ob_start();
$this->assertFalse(
$this->object->exportData(
'testDB', 'testTable', "\n", 'example.com', 'test'
)
);
$result = ob_get_clean();
// case 2
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('query')
->with('test', null, PMA\libraries\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(array(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;
$GLOBALS['output_charset_conversion'] = false;
$GLOBALS['buffer_needed'] = false;
$GLOBALS['asfile'] = true;
$GLOBALS['save_on_server'] = false;
ob_start();
$this->assertTrue(
$this->object->exportData(
'testDB', 'testTable', "\n", 'example.com', 'test'
)
);
$result = ob_get_clean();
$this->assertEquals(
"foo'ba;customNull;",
$result
);
// case 3
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('query')
->with('test', null, PMA\libraries\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(array(1 => 'a')));
$dbi->expects($this->at(4))
->method('fetchRow')
->with(true)
->will($this->returnValue(null));
$GLOBALS['dbi'] = $dbi;
$GLOBALS['csv_enclosed'] = '"';
ob_start();
$this->assertTrue(
$this->object->exportData(
'testDB', 'testTable', "\n", 'example.com', 'test'
)
);
$result = ob_get_clean();
$this->assertEquals(
"\"foo\"bar;customNull;",
$result
);
// case 4
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('query')
->with('test', null, PMA\libraries\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(array("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'
)
);
$result = ob_get_clean();
$this->assertEquals(
"\"foo\"\"bar;\"test\";",
$result
);
// case 5
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('query')
->with('test', null, PMA\libraries\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(array("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'
)
);
$result = ob_get_clean();
$this->assertEquals(
"\"foo;\"bar;\"test\n\";",
$result
);
// case 6
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('query')
->with('test', null, PMA\libraries\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(array("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'
)
);
$result = ob_get_clean();
$this->assertEquals(
"\"foo#\"bar\"\"foo#\"bar;\"test\n" .
"\"\"test\n" .
"\";",
$result
);
}
}

View File

@ -0,0 +1,203 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportExcel class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportExcel;
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportExcel class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportExcelTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['server'] = 0;
$this->object = new ExportExcel();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportExcel::setProperties
*
* @return void
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportExcel', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportExcel', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'CSV for MS Excel',
$properties->getText()
);
$this->assertEquals(
'csv',
$properties->getExtension()
);
$this->assertEquals(
'text/comma-separated-values',
$properties->getMimeType()
);
$this->assertEquals(
'Options',
$properties->getOptionsText()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = $generalOptionsArray[0];
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'null',
$property->getName()
);
$this->assertEquals(
'Replace NULL with:',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'removeCRLF',
$property->getName()
);
$this->assertEquals(
'Remove carriage return/line feed characters within columns',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'columns',
$property->getName()
);
$this->assertEquals(
'Put columns names in the first row',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\SelectPropertyItem',
$property
);
$this->assertEquals(
'edition',
$property->getName()
);
$this->assertEquals(
array(
'win' => 'Windows',
'mac_excel2003' => 'Excel 2003 / Macintosh',
'mac_excel2008' => 'Excel 2008 / Macintosh'
),
$property->getValues()
);
$this->assertEquals(
"Excel edition:",
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\HiddenPropertyItem',
$property
);
$this->assertEquals(
'structure_or_data',
$property->getName()
);
}
}

View File

@ -0,0 +1,912 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportHtmlword class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportHtmlword;
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/transformations.lib.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportHtmlword class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportHtmlwordTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['server'] = 0;
$this->object = new ExportHtmlword();
$GLOBALS['output_kanji_conversion'] = false;
$GLOBALS['output_charset_conversion'] = false;
$GLOBALS['buffer_needed'] = false;
$GLOBALS['asfile'] = true;
$GLOBALS['save_on_server'] = false;
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::setProperties
*
* @return void
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportHtmlword', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportHtmlword', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'Microsoft Word 2000',
$properties->getText()
);
$this->assertEquals(
'doc',
$properties->getExtension()
);
$this->assertEquals(
'application/vnd.ms-word',
$properties->getMimeType()
);
$this->assertEquals(
'Options',
$properties->getOptionsText()
);
$this->assertTrue(
$properties->getForceFile()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = $generalOptionsArray[0];
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'dump_what',
$generalOptions->getName()
);
$this->assertEquals(
'Dump table',
$generalOptions->getText()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\RadioPropertyItem',
$property
);
$this->assertEquals(
'structure_or_data',
$property->getName()
);
$this->assertEquals(
array(
'structure' => __('structure'),
'data' => __('data'),
'structure_and_data' => __('structure and data')
),
$property->getValues()
);
$generalOptions = $generalOptionsArray[1];
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'dump_what',
$generalOptions->getName()
);
$this->assertEquals(
'Data dump options',
$generalOptions->getText()
);
$this->assertEquals(
'structure',
$generalOptions->getForce()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'null',
$property->getName()
);
$this->assertEquals(
'Replace NULL with:',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'columns',
$property->getName()
);
$this->assertEquals(
'Put columns names in the first row',
$property->getText()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportHeader
*
* @return void
*/
public function testExportHeader()
{
ob_start();
$this->object->exportHeader();
$result = ob_get_clean();
$expected
= '<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
. ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset='
. 'utf-8' . '" />
</head>
<body>';
$this->assertEquals(
$expected,
$result
);
// case 2
$GLOBALS['charset'] = 'ISO-8859-1';
ob_start();
$this->object->exportHeader();
$result = ob_get_clean();
$expected
= '<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
. ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset='
. 'ISO-8859-1' . '" />
</head>
<body>';
$this->assertEquals(
$expected,
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportFooter
*
* @return void
*/
public function testExportFooter()
{
ob_start();
$this->assertTrue(
$this->object->exportFooter()
);
$result = ob_get_clean();
$this->assertEquals(
'</body></html>',
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
ob_start();
$this->assertTrue(
$this->object->exportDBHeader('d"b')
);
$result = ob_get_clean();
$this->assertEquals(
'<h1>Database d&quot;b</h1>',
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$this->assertTrue(
$this->object->exportDBFooter('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportDBCreate
*
* @return void
*/
public function testExportDBCreate()
{
$this->assertTrue(
$this->object->exportDBCreate('testDB', 'database')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportData
*
* @return void
*/
public function testExportData()
{
// case 1
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('query')
->with('test', null, PMA\libraries\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(array(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';
$GLOBALS['output_kanji_conversion'] = false;
$GLOBALS['output_charset_conversion'] = false;
$GLOBALS['buffer_needed'] = false;
$GLOBALS['asfile'] = true;
$GLOBALS['save_on_server'] = false;
ob_start();
$this->assertTrue(
$this->object->exportData(
'testDB', 'testTable', "\n", 'example.com', 'test'
)
);
$result = htmlspecialchars_decode(ob_get_clean());
$this->assertEquals(
'<h2>Dumping data for table testTable</h2>' .
'<table class="width100" 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>',
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::getTableDefStandIn
*
* @return void
*/
public function testGetTableDefStandIn()
{
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportHtmlword')
->setMethods(array('formatOneColumnDefinition'))
->getMock();
// case 1
$keys = array(
array(
'Non_unique' => 0,
'Column_name' => 'name1'
),
array(
'Non_unique' => 1,
'Column_name' => 'name2'
)
);
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('getTableIndexes')
->with('database', 'view')
->will($this->returnValue($keys));
$dbi->expects($this->once())
->method('getColumns')
->with('database', 'view')
->will($this->returnValue(array(array('Field' => 'column'))));
$GLOBALS['dbi'] = $dbi;
$this->object->expects($this->once())
->method('formatOneColumnDefinition')
->with(array('Field' => 'column'), array('name1'), 'column')
->will($this->returnValue(1));
$this->assertEquals(
'<table class="width100" 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>' .
'1</tr></table>',
$this->object->getTableDefStandIn('database', 'view', "\n")
);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::getTableDef
*
* @return void
*/
public function testGetTableDef()
{
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportHtmlword')
->setMethods(array('formatOneColumnDefinition'))
->getMock();
$keys = array(
array(
'Non_unique' => 0,
'Column_name' => 'name1'
),
array(
'Non_unique' => 1,
'Column_name' => 'name2'
)
);
// case 1
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->exactly(2))
->method('fetchResult')
->willReturnOnConsecutiveCalls(
array(),
array(
'fieldname' => array(
'values' => 'test-',
'transformation' => 'testfoo',
'mimetype' => 'test<'
)
)
);
$dbi->expects($this->once())
->method('getTableIndexes')
->with('database', '')
->will($this->returnValue($keys));
$columns = array(
'Field' => 'fieldname'
);
$dbi->expects($this->once())
->method('getColumns')
->with('database', '')
->will($this->returnValue(array($columns)));
$dbi->expects($this->any())
->method('query')
->will($this->returnValue(true));
$dbi->expects($this->any())
->method('numRows')
->will($this->returnValue(1));
$dbi->expects($this->any())
->method('fetchAssoc')
->will(
$this->returnValue(
array(
'comment' => array('fieldname' => 'testComment')
)
)
);
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$this->object->expects($this->exactly(3))
->method('formatOneColumnDefinition')
->with($columns, array('name1'))
->will($this->returnValue(1));
$GLOBALS['cfgRelation']['relation'] = true;
$GLOBALS['controllink'] = null;
$_SESSION['relation'][0] = array(
'PMA_VERSION' => PMA_VERSION,
'relwork' => true,
'commwork' => true,
'mimework' => true,
'db' => 'database',
'relation' => 'rel',
'column_info' => 'col'
);
$result = $this->object->getTableDef(
'database',
'',
true,
true,
true
);
$this->assertEquals(
'<table class="width100" 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>' .
'<td class="print"><strong>Comments</strong></td>' .
'<td class="print"><strong>MIME</strong></td></tr>' .
'1<td class="print"></td><td class="print">Test&lt;</td></tr></table>',
$result
);
// case 2
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->exactly(2))
->method('fetchResult')
->willReturnOnConsecutiveCalls(
array(
'fieldname' => array(
'foreign_table' => 'ftable',
'foreign_field' => 'ffield'
)
),
array(
'field' => array(
'values' => 'test-',
'transformation' => 'testfoo',
'mimetype' => 'test<'
)
)
);
$dbi->expects($this->once())
->method('getTableIndexes')
->with('database', '')
->will($this->returnValue($keys));
$columns = array(
'Field' => 'fieldname'
);
$dbi->expects($this->once())
->method('getColumns')
->with('database', '')
->will($this->returnValue(array($columns)));
$dbi->expects($this->any())
->method('query')
->will($this->returnValue(true));
$dbi->expects($this->any())
->method('numRows')
->will($this->returnValue(1));
$dbi->expects($this->any())
->method('fetchAssoc')
->will(
$this->returnValue(
array(
'comment' => array('field' => 'testComment')
)
)
);
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$GLOBALS['cfgRelation']['relation'] = true;
$_SESSION['relation'][0] = array(
'PMA_VERSION' => PMA_VERSION,
'relwork' => true,
'commwork' => true,
'mimework' => true,
'db' => 'database',
'relation' => 'rel',
'column_info' => 'col'
);
$result = $this->object->getTableDef(
'database',
'',
true,
true,
true
);
$this->assertContains(
'<td class="print">ftable (ffield)</td>',
$result
);
$this->assertContains(
'<td class="print"></td><td class="print"></td>',
$result
);
// case 3
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('getTableIndexes')
->with('database', '')
->will($this->returnValue($keys));
$columns = array(
'Field' => 'fieldname'
);
$dbi->expects($this->once())
->method('getColumns')
->with('database', '')
->will($this->returnValue(array($columns)));
$dbi->expects($this->any())
->method('query')
->will($this->returnValue(true));
$dbi->expects($this->any())
->method('numRows')
->will($this->returnValue(1));
$dbi->expects($this->any())
->method('fetchAssoc')
->will(
$this->returnValue(
array(
'comment' => array('field' => 'testComment')
)
)
);
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$GLOBALS['cfgRelation']['relation'] = true;
$_SESSION['relation'][0] = array(
'PMA_VERSION' => PMA_VERSION,
'relwork' => false,
'commwork' => false,
'mimework' => false,
'db' => 'database',
'relation' => 'rel',
'column_info' => 'col'
);
$result = $this->object->getTableDef(
'database',
'',
false,
false,
false
);
$this->assertEquals(
'<table class="width100" 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>1</tr></table>',
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::getTriggers
*
* @return void
*/
public function testGetTriggers()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$triggers = array(
array(
'name' => 'tna"me',
'action_timing' => 'ac>t',
'event_manipulation' => 'manip&',
'definition' => 'def'
)
);
$dbi->expects($this->once())
->method('getTriggers')
->with('database', 'table')
->will($this->returnValue($triggers));
$GLOBALS['dbi'] = $dbi;
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportHtmlword', 'getTriggers');
$method->setAccessible(true);
$result = $method->invoke($this->object, 'database', 'table');
$this->assertContains(
'<td class="print">tna&quot;me</td>' .
'<td class="print">ac&gt;t</td>' .
'<td class="print">manip&amp;</td>' .
'<td class="print">def</td>',
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::exportStructure
*
* @return void
*/
public function testExportStructure()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('getTriggers')
->with('db', 'tbl')
->will($this->returnValue(1));
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportHtmlword')
->setMethods(array('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, array())
->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', "\n", "example.com", "create_table", "test"
)
);
$result = ob_get_clean();
$this->assertEquals(
'<h2>Table structure for table tbl</h2>dumpText1',
$result
);
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'db', 'tbl', "\n", "example.com", "triggers", "test"
)
);
$result = ob_get_clean();
$this->assertEquals(
'<h2>Triggers tbl</h2>dumpText2',
$result
);
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'db', 'tbl', "\n", "example.com", "create_view", "test"
)
);
$result = ob_get_clean();
$this->assertEquals(
'<h2>Structure for view tbl</h2>dumpText3',
$result
);
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'db', 'tbl', "\n", "example.com", "stand_in", "test"
)
);
$result = ob_get_clean();
$this->assertEquals(
'<h2>Stand-in structure for view tbl</h2>dumpText4',
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportHtmlword::formatOneColumnDefinition
*
* @return void
*/
public function testFormatOneColumnDefinition()
{
$method = new ReflectionMethod(
'PMA\libraries\plugins\export\ExportHtmlword', 'formatOneColumnDefinition'
);
$method->setAccessible(true);
$cols = array(
'Null' => 'Yes',
'Field' => 'field',
'Key' => 'PRI',
'Type' => 'set(abc)enum123'
);
$unique_keys = array(
'field'
);
$this->assertEquals(
'<tr class="print-category"><td class="print"><em>' .
'<strong>field</strong></em></td><td class="print">set(abc)</td>' .
'<td class="print">Yes</td><td class="print">NULL</td>',
$method->invoke($this->object, $cols, $unique_keys)
);
$cols = array(
'Null' => 'NO',
'Field' => 'fields',
'Key' => 'COMP',
'Type' => '',
'Default' => 'def'
);
$unique_keys = array(
'field'
);
$this->assertEquals(
'<tr class="print-category"><td class="print">fields</td>' .
'<td class="print">&amp;nbsp;</td><td class="print">No</td>' .
'<td class="print">def</td>',
$method->invoke($this->object, $cols, $unique_keys)
);
}
}

View File

@ -0,0 +1,254 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportJson class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportJson;
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportJson class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportJsonTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$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;
$this->object = new ExportJson();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportJson::setProperties
*
* @return void
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportJson', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportJson', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'JSON',
$properties->getText()
);
$this->assertEquals(
'json',
$properties->getExtension()
);
$this->assertEquals(
'text/plain',
$properties->getMimeType()
);
$this->assertEquals(
'Options',
$properties->getOptionsText()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = $generalOptionsArray[0];
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\HiddenPropertyItem',
$property
);
$this->assertEquals(
'structure_or_data',
$property->getName()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportJson::exportHeader
*
* @return void
*/
public function testExportHeader()
{
$GLOBALS['crlf'] = "\n";
$this->expectOutputString(
'/**' . "\n"
. ' Export to JSON plugin for PHPMyAdmin' . "\n"
. ' @version ' . PMA_VERSION . "\n"
. ' */' . "\n" . "\n"
);
$this->assertTrue(
$this->object->exportHeader()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportJson::exportFooter
*
* @return void
*/
public function testExportFooter()
{
$this->assertTrue(
$this->object->exportFooter()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportJson::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
$GLOBALS['crlf'] = "\n";
$this->expectOutputString(
"// Database 'testDB'\n"
);
$this->assertTrue(
$this->object->exportDBHeader('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportJson::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$this->assertTrue(
$this->object->exportDBFooter('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportJson::exportDBCreate
*
* @return void
*/
public function testExportDBCreate()
{
$this->assertTrue(
$this->object->exportDBCreate('testDB', 'database')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportJson::exportData
*
* @return void
*/
public function testExportData()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->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('fetchRow')
->with(null)
->will($this->returnValue(array('foo')));
$dbi->expects($this->at(4))
->method('fetchRow')
->with(null)
->will($this->returnValue(array('bar')));
$dbi->expects($this->at(5))
->method('fetchRow')
->with(null)
->will($this->returnValue(null));
$GLOBALS['dbi'] = $dbi;
$this->expectOutputString(
"\n// db.tbl\n\n" .
"[{\"f1\":\"foo\"}, {\"f1\":\"bar\"}]\n"
);
$this->assertTrue(
$this->object->exportData('db', 'tbl', "\n", "example.com", "SELECT")
);
}
}

View File

@ -0,0 +1,993 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportLatex class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportLatex;
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/transformations.lib.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportLatex class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportLatexTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$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['plugin_param'] = array();
$GLOBALS['plugin_param']['export_type'] = 'table';
$GLOBALS['plugin_param']['single_table'] = false;
$GLOBALS['cfgRelation']['relation'] = true;
$this->object = new ExportLatex();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportLatex::setProperties
*
* @return void
*/
public function testSetProperties()
{
$GLOBALS['plugin_param']['export_type'] = '';
$GLOBALS['plugin_param']['single_table'] = false;
$GLOBALS['cfgRelation']['mimework'] = true;
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportLatex', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportLatex', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'LaTeX',
$properties->getText()
);
$this->assertEquals(
'tex',
$properties->getExtension()
);
$this->assertEquals(
'application/x-tex',
$properties->getMimeType()
);
$this->assertEquals(
'Options',
$properties->getOptionsText()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'caption',
$property->getName()
);
$this->assertEquals(
'Include table caption',
$property->getText()
);
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'dump_what',
$generalOptions->getName()
);
$this->assertEquals(
'Dump table',
$generalOptions->getText()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\RadioPropertyItem',
$property
);
$this->assertEquals(
'structure_or_data',
$property->getName()
);
$this->assertEquals(
array(
'structure' => __('structure'),
'data' => __('data'),
'structure_and_data' => __('structure and data')
),
$property->getValues()
);
// hide structure
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'structure',
$generalOptions->getName()
);
$this->assertEquals(
'Object creation options',
$generalOptions->getText()
);
$this->assertEquals(
'data',
$generalOptions->getForce()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'structure_caption',
$property->getName()
);
$this->assertEquals(
'Table caption:',
$property->getText()
);
$this->assertEquals(
'faq6-27',
$property->getDoc()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'structure_continued_caption',
$property->getName()
);
$this->assertEquals(
'Table caption (continued):',
$property->getText()
);
$this->assertEquals(
'faq6-27',
$property->getDoc()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'structure_label',
$property->getName()
);
$this->assertEquals(
'Label key:',
$property->getText()
);
$this->assertEquals(
'faq6-27',
$property->getDoc()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'relation',
$property->getName()
);
$this->assertEquals(
'Display foreign key relationships',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'comments',
$property->getName()
);
$this->assertEquals(
'Display comments',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'mime',
$property->getName()
);
$this->assertEquals(
'Display MIME types',
$property->getText()
);
// data options
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'data',
$generalOptions->getName()
);
$this->assertEquals(
'Data dump options',
$generalOptions->getText()
);
$this->assertEquals(
'structure',
$generalOptions->getForce()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'columns',
$property->getName()
);
$this->assertEquals(
'Put columns names in the first row:',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'data_caption',
$property->getName()
);
$this->assertEquals(
'Table caption:',
$property->getText()
);
$this->assertEquals(
'faq6-27',
$property->getDoc()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'data_continued_caption',
$property->getName()
);
$this->assertEquals(
'Table caption (continued):',
$property->getText()
);
$this->assertEquals(
'faq6-27',
$property->getDoc()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'data_label',
$property->getName()
);
$this->assertEquals(
'Label key:',
$property->getText()
);
$this->assertEquals(
'faq6-27',
$property->getDoc()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'null',
$property->getName()
);
$this->assertEquals(
'Replace NULL with:',
$property->getText()
);
// case 2
$GLOBALS['plugin_param']['export_type'] = 'table';
$GLOBALS['plugin_param']['single_table'] = false;
$method->invoke($this->object, null);
$properties = $attrProperties->getValue($this->object);
$generalOptionsArray = $options->getProperties();
$this->assertCount(
4,
$generalOptionsArray
);
}
/**
* Test for PMA\libraries\plugins\export\ExportLatex::exportHeader
*
* @return void
*/
public function testExportHeader()
{
if (!defined("PMA_MYSQL_STR_VERSION")) {
define("PMA_MYSQL_STR_VERSION", "5.0.0");
}
$GLOBALS['crlf'] = "\n";
$GLOBALS['cfg']['Server']['port'] = 80;
$GLOBALS['cfg']['Server']['host'] = 'localhost';
ob_start();
$this->assertTrue(
$this->object->exportHeader()
);
$result = ob_get_clean();
$this->assertContains(
"\n% Host: localhost:80",
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportLatex::exportFooter
*
* @return void
*/
public function testExportFooter()
{
$this->assertTrue(
$this->object->exportFooter()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportLatex::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
$GLOBALS['crlf'] = "\n";
$this->expectOutputString(
"% \n% Database: 'testDB'\n% \n"
);
$this->assertTrue(
$this->object->exportDBHeader('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportLatex::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$this->assertTrue(
$this->object->exportDBFooter('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportLatex::exportDBCreate
*
* @return void
*/
public function testExportDBCreate()
{
$this->assertTrue(
$this->object->exportDBCreate('testDB', 'database')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportLatex::exportData
*
* @return void
*/
public function testExportData()
{
$GLOBALS['latex_caption'] = true;
$GLOBALS['latex_data_caption'] = 'latex data caption';
$GLOBALS['latex_data_continued_caption'] = 'continued caption';
$GLOBALS['latex_columns'] = true;
$GLOBALS['latex_data_label'] = 'datalabel';
$GLOBALS['latex_null'] = 'null';
$GLOBALS['cfg']['Server']['host'] = 'localhost';
$GLOBALS['cfg']['Server']['verbose'] = 'verb';
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->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(array('f1' => 'foo$%')));
$dbi->expects($this->at(4))
->method('fetchAssoc')
->with(null)
->will($this->returnValue(array('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")
);
$result = ob_get_clean();
$this->assertEquals(
"\n" . '%' . "\n" .
'% Data: tbl' . "\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" .
' \end{longtable}' . "\n",
$result
);
// case 2
unset($GLOBALS['latex_columns']);
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->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(array('f1' => 'foo$%')));
$dbi->expects($this->at(4))
->method('fetchAssoc')
->with(null)
->will($this->returnValue(array('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")
);
$result = ob_get_clean();
$this->assertContains(
'{datalabel} \\\\\\\\ \hlinefoo',
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportLatex::exportStructure
*
* @return void
*/
public function testExportStructure()
{
// $this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportHtmlword')
// ->setMethods(array('formatOneColumnDefinition'))
// ->getMock();
$keys = array(
array(
'Non_unique' => 0,
'Column_name' => 'name1'
),
array(
'Non_unique' => 1,
'Column_name' => 'name2'
)
);
// case 1
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('getTableIndexes')
->with('database', '')
->will($this->returnValue($keys));
$dbi->expects($this->exactly(2))
->method('fetchResult')
->willReturnOnConsecutiveCalls(
array(),
array(
'name1' => array(
'values' => 'test-',
'transformation' => 'testfoo',
'mimetype' => 'testmimetype_'
)
)
);
$columns = array(
array(
'Null' => 'Yes',
'Field' => 'name1',
'Key' => 'PRI',
'Type' => 'set(abc)enum123'
),
array(
'Null' => 'NO',
'Field' => 'fields',
'Key' => 'COMP',
'Type' => '',
'Default' => 'def'
)
);
$dbi->expects($this->once())
->method('getColumns')
->with('database', '')
->will($this->returnValue($columns));
$dbi->expects($this->any())
->method('query')
->will($this->returnValue(true));
$dbi->expects($this->any())
->method('numRows')
->will($this->returnValue(1));
$dbi->expects($this->any())
->method('fetchAssoc')
->will(
$this->returnValue(
array(
'comment' => array('name1' => 'testComment')
)
)
);
$GLOBALS['dbi'] = $dbi;
if (isset($GLOBALS['latex_caption'])) {
unset($GLOBALS['latex_caption']);
}
$GLOBALS['cfgRelation']['relation'] = true;
$_SESSION['relation'][0] = array(
'PMA_VERSION' => PMA_VERSION,
'relwork' => true,
'commwork' => true,
'mimework' => true,
'db' => 'database',
'relation' => 'rel',
'column_info' => 'col'
);
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'database',
'',
"\n",
"example.com",
'test',
'test',
true,
true,
true
)
);
$result = ob_get_clean();
//echo $result; die;
$this->assertEquals(
"\n" . '%' . "\n" .
'% Structure: ' . "\n" .
'%' . "\n" .
' \\begin{longtable}{|l|c|c|c|l|l|} ' . "\n" .
' \\hline \\multicolumn{1}{|c|}{\\textbf{Column}} & ' .
'\\multicolumn{1}{|c|}{\\textbf{Type}} & \\multicolumn{1}{|c|}' .
'{\\textbf{Null}} & \\multicolumn{1}{|c|}{\\textbf{Default}} &' .
' \\multicolumn{1}{|c|}{\\textbf{Comments}} & \\multicolumn{1}' .
'{|c|}{\\textbf{MIME}} \\\\ \\hline \\hline' . "\n" .
'\\endfirsthead' . "\n" . ' \\hline \\multicolumn{1}{|c|}' .
'{\\textbf{Column}} & \\multicolumn{1}' . '{|c|}{\\textbf{Type}}' .
' & \\multicolumn{1}{|c|}{\\textbf{Null}} & \\multicolumn' .
'{1}{|c|}{\\textbf{Default}} & \\multicolumn{1}{|c|}{\\textbf' .
'{Comments}} & \\multicolumn{1}{|c|}{\\textbf{MIME}} \\\\ ' .
'\\hline \\hline \\endhead \\endfoot ' . "\n" . '\\textbf{\\textit' .
'{name1}} & set(abc) & Yes & NULL & ' .
'& Testmimetype/ \\\\ \\hline ' . "\n" .
'fields & & No & def & & \\\\ \\hline ' . "\n" .
' \\end{longtable}' . "\n",
$result
);
// case 2
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->exactly(2))
->method('fetchResult')
->willReturnOnConsecutiveCalls(
array(
'name1' => array(
'foreign_table' => 'ftable',
'foreign_field' => 'ffield'
),
'foreign_keys_data' => array()
),
array(
'field' => array(
'values' => 'test-',
'transformation' => 'testfoo',
'mimetype' => 'test<'
)
)
);
$dbi->expects($this->once())
->method('getTableIndexes')
->with('database', '')
->will($this->returnValue($keys));
$dbi->expects($this->once())
->method('getColumns')
->with('database', '')
->will($this->returnValue($columns));
$dbi->expects($this->any())
->method('query')
->will($this->returnValue(true));
$dbi->expects($this->any())
->method('numRows')
->will($this->returnValue(1));
$dbi->expects($this->any())
->method('fetchAssoc')
->will(
$this->returnValue(
array(
'comment' => array('field' => 'testComment')
)
)
);
$GLOBALS['dbi'] = $dbi;
$GLOBALS['cfgRelation']['relation'] = true;
$_SESSION['relation'][0] = array(
'PMA_VERSION' => PMA_VERSION,
'relwork' => true,
'commwork' => true,
'mimework' => true,
'db' => 'database',
'relation' => 'rel',
'column_info' => 'col'
);
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'database',
'',
"\n",
"example.com",
'test',
'test',
true,
true,
true
)
);
$result = ob_get_clean();
$this->assertContains(
'\\textbf{\\textit{name1}} & set(abc) & Yes & NULL & ' .
'ftable (ffield) & & \\\\ \\hline',
$result
);
// case 3
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('getTableIndexes')
->with('database', '')
->will($this->returnValue($keys));
$dbi->expects($this->once())
->method('getColumns')
->with('database', '')
->will($this->returnValue($columns));
$dbi->expects($this->any())
->method('query')
->will($this->returnValue(true));
$dbi->expects($this->any())
->method('numRows')
->will($this->returnValue(1));
$dbi->expects($this->any())
->method('fetchAssoc')
->will(
$this->returnValue(
array(
'comment' => array('field' => 'testComment')
)
)
);
$GLOBALS['dbi'] = $dbi;
$GLOBALS['cfgRelation']['relation'] = true;
$GLOBALS['latex_caption'] = true;
$GLOBALS['latex_structure_caption'] = 'latexstructure';
$GLOBALS['latex_structure_label'] = 'latexlabel';
$GLOBALS['latex_structure_continued_caption'] = 'latexcontinued';
$GLOBALS['cfg']['Server']['host'] = 'localhost';
$GLOBALS['cfg']['Server']['verbose'] = 'verb';
$_SESSION['relation'][0] = array(
'PMA_VERSION' => PMA_VERSION,
'relwork' => false,
'commwork' => false,
'mimework' => false,
'db' => 'database',
'relation' => 'rel',
'column_info' => 'col'
);
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'database',
'',
"\n",
"example.com",
'test',
'test'
)
);
$result = ob_get_clean();
$this->assertContains(
'\\caption{latexstructure} \\label{latexlabel}',
$result
);
$this->assertContains(
'caption{latexcontinued}',
$result
);
// case 4
$this->assertTrue(
$this->object->exportStructure(
'database',
'',
"\n",
"example.com",
'triggers',
'test'
)
);
}
/**
* Test for PMA\libraries\plugins\export\ExportLatex::texEscape
*
* @return void
*/
public function testTexEscape()
{
$this->assertEquals(
'\\$\\%\\{foo\\&bar\\}\\#\\_\\^',
ExportLatex::texEscape('$%{foo&bar}#_^')
);
}
}

View File

@ -0,0 +1,420 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportMediawiki class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportMediawiki;
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportMediawiki class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportMediawikiTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$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;
$this->object = new ExportMediawiki();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportMediawiki::setProperties
*
* @return void
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportMediawiki', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportMediawiki', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'MediaWiki Table',
$properties->getText()
);
$this->assertEquals(
'mediawiki',
$properties->getExtension()
);
$this->assertEquals(
'text/plain',
$properties->getMimeType()
);
$this->assertEquals(
'Options',
$properties->getOptionsText()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = $generalOptionsArray[0];
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$this->assertEquals(
'Dump table',
$generalOptions->getText()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertySubgroup',
$property
);
$this->assertEquals(
'dump_table',
$property->getName()
);
$this->assertEquals(
'Dump table',
$property->getText()
);
$sgHeader = $property->getSubGroupHeader();
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\RadioPropertyItem',
$sgHeader
);
$this->assertEquals(
'structure_or_data',
$sgHeader->getName()
);
$this->assertEquals(
array(
'structure' => __('structure'),
'data' => __('data'),
'structure_and_data' => __('structure and data')
),
$sgHeader->getValues()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'caption',
$property->getName()
);
$this->assertEquals(
'Export table names',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'headers',
$property->getName()
);
$this->assertEquals(
'Export table headers',
$property->getText()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportHeader
*
* @return void
*/
public function testExportHeader()
{
$this->assertTrue(
$this->object->exportHeader()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportFooter
*
* @return void
*/
public function testExportFooter()
{
$this->assertTrue(
$this->object->exportFooter()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
$this->assertTrue(
$this->object->exportDBHeader('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$this->assertTrue(
$this->object->exportDBFooter('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportDBCreate
*
* @return void
*/
public function testExportDBCreate()
{
$this->assertTrue(
$this->object->exportDBCreate('testDB', 'database')
);
}
/**
* Test for ExportMediaWiki::exportStructure
*
* @return void
*/
public function testExportStructure()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$columns = array(
array(
'Null' => 'Yes',
'Field' => 'name1',
'Key' => 'PRI',
'Type' => 'set(abc)enum123',
'Default' => '',
'Extra' => ''
),
array(
'Null' => 'NO',
'Field' => 'fields',
'Key' => 'COMP',
'Type' => '',
'Default' => 'def',
'Extra' => 'ext'
)
);
$dbi->expects($this->at(0))
->method('getColumns')
->with('db', 'table')
->will($this->returnValue($columns));
$GLOBALS['dbi'] = $dbi;
$GLOBALS['mediawiki_caption'] = true;
$GLOBALS['mediawiki_headers'] = true;
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'db', 'table', "\n", "example.com", "create_table", "test"
)
);
$result = ob_get_clean();
$this->assertEquals(
"\n<!--\n" .
"Table structure for `table`\n" .
"-->\n" .
"\n" .
"{| class=\"wikitable\" style=\"text-align:center;\"\n" .
"|+'''table'''\n" .
"|- style=\"background:#ffdead;\"\n" .
"! style=\"background:#ffffff\" | \n" .
" | name1\n" .
" | fields\n" .
"|-\n" .
"! Type\n" .
" | set(abc)enum123\n" .
" | \n" .
"|-\n" .
"! Null\n" .
" | Yes\n" .
" | NO\n" .
"|-\n" .
"! Default\n" .
" | \n" .
" | def\n" .
"|-\n" .
"! Extra\n" .
" | \n" .
" | ext\n" .
"|}\n\n",
$result
);
/**
* This case produces an error, should it be tested?
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'db', 'table', "\n", "example.com", "defaultTest", "test"
)
);
$result = ob_get_clean();
*/
}
/**
* Test for PMA\libraries\plugins\export\ExportMediawiki::exportData
*
* @return void
*/
public function testExportData()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('getColumnNames')
->with('db', 'table')
->will($this->returnValue(array('name1', 'fields')));
$dbi->expects($this->once())
->method('query')
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
->will($this->returnValue(true));
$dbi->expects($this->once())
->method('numFields')
->with(true)
->will($this->returnValue(2));
$dbi->expects($this->at(3))
->method('fetchRow')
->with(true)
->will($this->returnValue(array('r1', 'r2')));
$dbi->expects($this->at(4))
->method('fetchRow')
->with(true)
->will($this->returnValue(array('r3', '')));
$dbi->expects($this->at(4))
->method('fetchRow')
->with(true)
->will($this->returnValue(null));
$GLOBALS['dbi'] = $dbi;
$GLOBALS['mediawiki_caption'] = true;
$GLOBALS['mediawiki_headers'] = true;
ob_start();
$this->assertTrue(
$this->object->exportData(
'db', 'table', "\n", "example.com", "SELECT"
)
);
$result = ob_get_clean();
$this->assertEquals(
"\n<!--\n" .
"Table data for `table`\n" .
"-->\n" .
"\n" .
"{| class=\"wikitable sortable\" style=\"text-align:" .
"center;\"\n" .
"|+'''table'''\n" .
"|-\n" .
" ! name1\n" .
" ! fields\n" .
"|-\n" .
" | r1\n" .
" | r2\n" .
"|-\n" .
" | r3\n" .
" | \n" .
"|}\n\n",
$result
);
}
}

View File

@ -0,0 +1,508 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportOds class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportOds;
//ExportOds required because of initialisation inside
require_once 'libraries/plugins/export/ExportOds.php';
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'export.php';
require_once 'libraries/opendocument.lib.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportOds class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportOdsTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$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;
$this->object = new ExportOds();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportOds::setProperties
*
* @return void
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportOds', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportOds', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'OpenDocument Spreadsheet',
$properties->getText()
);
$this->assertEquals(
'ods',
$properties->getExtension()
);
$this->assertEquals(
'application/vnd.oasis.opendocument.spreadsheet',
$properties->getMimeType()
);
$this->assertEquals(
'Options',
$properties->getOptionsText()
);
$this->assertTrue(
$properties->getForceFile()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = $generalOptionsArray[0];
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'null',
$property->getName()
);
$this->assertEquals(
'Replace NULL with:',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'columns',
$property->getName()
);
$this->assertEquals(
'Put columns names in the first row',
$property->getText()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\HiddenPropertyItem',
$property
);
$this->assertEquals(
'structure_or_data',
$property->getName()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportOds::exportHeader
*
* @return void
*/
public function testExportHeader()
{
$this->assertTrue(
isset($GLOBALS['ods_buffer'])
);
$this->assertTrue(
$this->object->exportHeader()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportOds::exportFooter
*
* @return void
*/
public function testExportFooter()
{
$GLOBALS['ods_buffer'] = 'header';
$this->expectOutputRegex('/^504b.*636f6e74656e742e786d6c/');
$this->setOutputCallback('bin2hex');
$this->assertTrue(
$this->object->exportFooter()
);
$this->assertContains(
'header',
$GLOBALS['ods_buffer']
);
$this->assertContains(
'</office:spreadsheet>',
$GLOBALS['ods_buffer']
);
$this->assertContains(
'</office:body>',
$GLOBALS['ods_buffer']
);
$this->assertContains(
'</office:document-content>',
$GLOBALS['ods_buffer']
);
}
/**
* Test for PMA\libraries\plugins\export\ExportOds::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
$this->assertTrue(
$this->object->exportDBHeader('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportOds::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$this->assertTrue(
$this->object->exportDBFooter('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportOds::exportDBCreate
*
* @return void
*/
public function testExportDBCreate()
{
$this->assertTrue(
$this->object->exportDBCreate('testDB', 'database')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportOds::exportData
*
* @return void
*/
public function testExportData()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$flags = array();
$a = new StdClass;
$flags[] = $a;
$a = new StdClass;
$a->blob = true;
$flags[] = $a;
$a = new StdClass;
$a->blob = false;
$a->type = 'date';
$flags[] = $a;
$a = new StdClass;
$a->blob = false;
$a->type = 'time';
$flags[] = $a;
$a = new StdClass;
$a->blob = false;
$a->type = 'datetime';
$flags[] = $a;
$a = new StdClass;
$a->numeric = true;
$a->type = 'none';
$a->blob = false;
$flags[] = $a;
$a = new StdClass;
$a->numeric = true;
$a->type = 'real';
$a->blob = true;
$flags[] = $a;
$a = new StdClass;
$a->type = "dummy";
$a->blob = false;
$a->numeric = false;
$flags[] = $a;
$dbi->expects($this->once())
->method('getFieldsMeta')
->with(true)
->will($this->returnValue($flags));
$dbi->expects($this->exactly(8))
->method('fieldFlags')
->willReturnOnConsecutiveCalls(
'BINARYTEST',
'binary',
'',
'',
'',
'',
'',
''
);
$dbi->expects($this->once())
->method('query')
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
->will($this->returnValue(true));
$dbi->expects($this->once())
->method('numFields')
->with(true)
->will($this->returnValue(8));
$dbi->expects($this->at(11))
->method('fetchRow')
->with(true)
->will(
$this->returnValue(
array(
null, '01-01-2000', '01-01-2000', '01-01-2000 10:00:00',
"01-01-2014 10:02:00", "t>s", "a&b", "<"
)
)
);
$GLOBALS['dbi'] = $dbi;
$GLOBALS['mediawiki_caption'] = true;
$GLOBALS['mediawiki_headers'] = true;
$GLOBALS['what'] = 'foo';
$GLOBALS['foo_null'] = "&";
$this->assertTrue(
$this->object->exportData(
'db', 'table', "\n", "example.com", "SELECT"
)
);
$this->assertEquals(
'<table:table table:name="table"><table:table-row><table:table-cell ' .
'office:value-type="string"><text:p>&amp;</text:p></table:table-cell>' .
'<table:table-cell office:value-type="string"><text:p></text:p>' .
'</table:table-cell><table:table-cell office:value-type="date" office:' .
'date-value="2000-01-01" table:style-name="DateCell"><text:p>01-01' .
'-2000</text:p></table:table-cell><table:table-cell office:value-type=' .
'"time" office:time-value="PT10H00M00S" table:style-name="TimeCell">' .
'<text:p>01-01-2000 10:00:00</text:p></table:table-cell><table:table-' .
'cell office:value-type="date" office:date-value="2014-01-01T10:02:00"' .
' table:style-name="DateTimeCell"><text:p>01-01-2014 10:02:00' .
'</text:p></table:table-cell><table:table-cell office:value-type=' .
'"float" office:value="t>s" ><text:p>t&gt;s</text:p>' .
'</table:table-cell><table:table-cell office:value-type="float" ' .
'office:value="a&b" ><text:p>a&amp;b</text:p></table:table-cell>' .
'<table:table-cell office:value-type="string"><text:p>&lt;</text:p>' .
'</table:table-cell></table:table-row></table:table>',
$GLOBALS['ods_buffer']
);
}
/**
* Test for PMA\libraries\plugins\export\ExportOds::exportData
*
* @return void
*/
public function testExportDataWithFieldNames()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$flags = array();
$dbi->expects($this->once())
->method('getFieldsMeta')
->with(true)
->will($this->returnValue($flags));
$dbi->expects($this->any())
->method('fieldFlags')
->will($this->returnValue('BINARYTEST'));
$dbi->expects($this->once())
->method('query')
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
->will($this->returnValue(true));
$dbi->expects($this->once())
->method('numFields')
->with(true)
->will($this->returnValue(2));
$dbi->expects($this->at(5))
->method('fieldName')
->will($this->returnValue('fna\"me'));
$dbi->expects($this->at(6))
->method('fieldName')
->will($this->returnValue('fnam/<e2'));
$dbi->expects($this->at(7))
->method('fetchRow')
->with(true)
->will(
$this->returnValue(
null
)
);
$GLOBALS['dbi'] = $dbi;
$GLOBALS['mediawiki_caption'] = true;
$GLOBALS['mediawiki_headers'] = true;
$GLOBALS['what'] = 'foo';
$GLOBALS['foo_null'] = "&";
$GLOBALS['foo_columns'] = true;
$this->assertTrue(
$this->object->exportData(
'db', 'table', "\n", "example.com", "SELECT"
)
);
$this->assertEquals(
'<table:table table:name="table"><table:table-row><table:table-cell ' .
'office:value-type="string"><text:p>fna&quot;me</text:p></table:table' .
'-cell><table:table-cell office:value-type="string"><text:p>' .
'fnam/&lt;e2</text:p></table:table-cell></table:table-row>' .
'</table:table>',
$GLOBALS['ods_buffer']
);
// with no row count
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$flags = array();
$dbi->expects($this->once())
->method('getFieldsMeta')
->with(true)
->will($this->returnValue($flags));
$dbi->expects($this->once())
->method('query')
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
->will($this->returnValue(true));
$dbi->expects($this->once())
->method('numFields')
->with(true)
->will($this->returnValue(0));
$dbi->expects($this->once())
->method('fetchRow')
->with(true)
->will(
$this->returnValue(
null
)
);
$GLOBALS['dbi'] = $dbi;
$GLOBALS['mediawiki_caption'] = true;
$GLOBALS['mediawiki_headers'] = true;
$GLOBALS['what'] = 'foo';
$GLOBALS['foo_null'] = "&";
$GLOBALS['ods_buffer'] = '';
$this->assertTrue(
$this->object->exportData(
'db', 'table', "\n", "example.com", "SELECT"
)
);
$this->assertEquals(
'<table:table table:name="table"><table:table-row></table:table-row>' .
'</table:table>',
$GLOBALS['ods_buffer']
);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,343 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportPdf class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportPdf;
use PMA\libraries\plugins\export\PMA_ExportPdf;
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportPdf class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportPdfTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$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;
$this->object = new ExportPdf();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportPdf::setProperties
*
* @return void
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportPdf', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportPdf', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'PDF',
$properties->getText()
);
$this->assertEquals(
'pdf',
$properties->getExtension()
);
$this->assertEquals(
'application/pdf',
$properties->getMimeType()
);
$this->assertEquals(
'Options',
$properties->getOptionsText()
);
$this->assertTrue(
$properties->getForceFile()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'report_title',
$property->getName()
);
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'dump_what',
$generalOptions->getName()
);
$this->assertEquals(
'Dump table',
$generalOptions->getText()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\RadioPropertyItem',
$property
);
$this->assertEquals(
'structure_or_data',
$property->getName()
);
$this->assertEquals(
array(
'structure' => __('structure'),
'data' => __('data'),
'structure_and_data' => __('structure and data')
),
$property->getValues()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPdf::exportHeader
*
* @return void
*/
public function testExportHeader()
{
$pdf = $this->getMockBuilder('PMA\libraries\plugins\export\PMA_ExportPdf')
->disableOriginalConstructor()
->getMock();
$pdf->expects($this->once())
->method('Open');
$pdf->expects($this->once())
->method('setAttributes');
$pdf->expects($this->once())
->method('setTopMargin');
$attrPdf = new ReflectionProperty('PMA\libraries\plugins\export\ExportPdf', '_pdf');
$attrPdf->setAccessible(true);
$attrPdf->setValue($this->object, $pdf);
$this->assertTrue(
$this->object->exportHeader()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPdf::exportFooter
*
* @return void
*/
public function testExportFooter()
{
$pdf = $this->getMockBuilder('PMA\libraries\plugins\export\PMA_ExportPdf')
->disableOriginalConstructor()
->getMock();
$pdf->expects($this->once())
->method('getPDFData');
$attrPdf = new ReflectionProperty('PMA\libraries\plugins\export\ExportPdf', '_pdf');
$attrPdf->setAccessible(true);
$attrPdf->setValue($this->object, $pdf);
$this->assertTrue(
$this->object->exportFooter()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPdf::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
$this->assertTrue(
$this->object->exportDBHeader('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPdf::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$this->assertTrue(
$this->object->exportDBFooter('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPdf::exportDBCreate
*
* @return void
*/
public function testExportDBCreate()
{
$this->assertTrue(
$this->object->exportDBCreate('testDB', 'database')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPdf::exportData
*
* @return void
*/
public function testExportData()
{
$pdf = $this->getMockBuilder('PMA\libraries\plugins\export\PMA_ExportPdf')
->disableOriginalConstructor()
->getMock();
$pdf->expects($this->once())
->method('setAttributes')
->with(
array(
'currentDb' => 'db', 'currentTable' => 'table',
'dbAlias' => 'db', 'tableAlias' => 'table',
'aliases' => array()
)
);
$pdf->expects($this->once())
->method('mysqlReport')
->with('SELECT');
$attrPdf = new ReflectionProperty('PMA\libraries\plugins\export\ExportPdf', '_pdf');
$attrPdf->setAccessible(true);
$attrPdf->setValue($this->object, $pdf);
$this->assertTrue(
$this->object->exportData(
'db', 'table', "\n", "phpmyadmin.net/err", 'SELECT'
)
);
}
/**
* Test for
* - PMA\libraries\plugins\export\ExportPdf::_setPdf
* - PMA\libraries\plugins\export\ExportPdf::_getPdf
*
* @return void
*/
public function testSetGetPdf()
{
$setter = new ReflectionMethod('PMA\libraries\plugins\export\ExportPdf', '_setPdf');
$setter->setAccessible(true);
$setter->invoke($this->object, new PMA_ExportPdf);
$getter = new ReflectionMethod('PMA\libraries\plugins\export\ExportPdf', '_getPdf');
$getter->setAccessible(true);
$this->assertInstanceOf(
'PMA\libraries\plugins\export\PMA_ExportPdf',
$getter->invoke($this->object)
);
}
/**
* Test for
* - PMA\libraries\plugins\export\ExportPdf::_setPdfReportTitle
* - PMA\libraries\plugins\export\ExportPdf::_getPdfReportTitle
*
* @return void
*/
public function testSetGetPdfTitle()
{
$setter = new ReflectionMethod('PMA\libraries\plugins\export\ExportPdf', '_setPdfReportTitle');
$setter->setAccessible(true);
$setter->invoke($this->object, "title");
$getter = new ReflectionMethod('PMA\libraries\plugins\export\ExportPdf', '_getPdfReportTitle');
$getter->setAccessible(true);
$this->assertEquals(
'title',
$getter->invoke($this->object)
);
}
}

View File

@ -0,0 +1,298 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportPhparray class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportPhparray;
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportPhparray class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportPhparrayTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$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;
$this->object = new ExportPhparray();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportPhparray::setProperties
*
* @return void
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportPhparray', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportPhparray', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'PHP array',
$properties->getText()
);
$this->assertEquals(
'php',
$properties->getExtension()
);
$this->assertEquals(
'text/plain',
$properties->getMimeType()
);
$this->assertEquals(
'Options',
$properties->getOptionsText()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = $generalOptionsArray[0];
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\HiddenPropertyItem',
$property
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPhparray::exportHeader
*
* @return void
*/
public function testExportHeader()
{
$GLOBALS['crlf'] = ' ';
ob_start();
$this->assertTrue(
$this->object->exportHeader()
);
$result = ob_get_clean();
$this->assertContains(
'<?php ',
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPhparray::exportFooter
*
* @return void
*/
public function testExportFooter()
{
$this->assertTrue(
$this->object->exportFooter()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPhparray::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
$GLOBALS['crlf'] = "\n";
ob_start();
$this->assertTrue(
$this->object->exportDBHeader("db")
);
$result = ob_get_clean();
$this->assertContains(
"/**\n * Database `db`\n */",
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPhparray::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$this->assertTrue(
$this->object->exportDBFooter('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPhparray::exportDBCreate
*
* @return void
*/
public function testExportDBCreate()
{
$this->assertTrue(
$this->object->exportDBCreate('testDB', 'database')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportPhparray::exportData
*
* @return void
*/
public function testExportData()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('query')
->with('SELECT', null, PMA\libraries\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(array(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', "\n", 'phpmyadmin.net/err', 'SELECT'
)
);
$result = ob_get_clean();
$this->assertEquals(
"\n" . '/* `db`.`table` */' . "\n" .
'$table = array(' . "\n" .
' array(\'c1\' => 1,\'\' => \'a\')' . "\n" .
');' . "\n",
$result
);
// case 2: test invalid variable name fix
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('query')
->with('SELECT', null, PMA\libraries\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', '0`932table', "\n", 'phpmyadmin.net/err', 'SELECT'
)
);
$result = ob_get_clean();
$this->assertContains(
'$_0_932table',
$result
);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,645 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportTexytext class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportTexytext;
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/transformations.lib.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportTexytext class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportTexytextTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['server'] = 0;
$GLOBALS['output_kanji_conversion'] = false;
$GLOBALS['buffer_needed'] = false;
$GLOBALS['asfile'] = false;
$GLOBALS['save_on_server'] = false;
$GLOBALS['plugin_param'] = array();
$GLOBALS['plugin_param']['export_type'] = 'table';
$GLOBALS['plugin_param']['single_table'] = false;
$GLOBALS['cfgRelation']['relation'] = true;
$this->object = new ExportTexytext();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::setProperties
*
* @return void
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportTexytext', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportTexytext', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'Texy! text',
$properties->getText()
);
$this->assertEquals(
'txt',
$properties->getExtension()
);
$this->assertEquals(
'text/plain',
$properties->getMimeType()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$this->assertEquals(
"Dump table",
$generalOptions->getText()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\RadioPropertyItem',
$property
);
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'data',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$this->assertEquals(
'columns',
$property->getName()
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\TextPropertyItem',
$property
);
$this->assertEquals(
'null',
$property->getName()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::exportHeader
*
* @return void
*/
public function testExportHeader()
{
$this->assertTrue(
$this->object->exportHeader()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::exportFooter
*
* @return void
*/
public function testExportFooter()
{
$this->assertTrue(
$this->object->exportFooter()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
$this->expectOutputString(
"===Database testDb\n\n"
);
$this->assertTrue(
$this->object->exportDBHeader('testDb')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$this->assertTrue(
$this->object->exportDBFooter('testDB')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::exportDBCreate
*
* @return void
*/
public function testExportDBCreate()
{
$this->assertTrue(
$this->object->exportDBCreate('testDB', 'database')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::exportData
*
* @return void
*/
public function testExportData()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('query')
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
->will($this->returnValue(true));
$dbi->expects($this->once())
->method('numFields')
->with(true)
->will($this->returnValue(3));
$dbi->expects($this->at(2))
->method('fieldName')
->will($this->returnValue('fName1'));
$dbi->expects($this->at(3))
->method('fieldName')
->will($this->returnValue('fNa"me2'));
$dbi->expects($this->at(4))
->method('fieldName')
->will($this->returnValue('fName3'));
$dbi->expects($this->at(5))
->method('fetchRow')
->with(true)
->will($this->returnValue(array(null, '0', 'test')));
$GLOBALS['dbi'] = $dbi;
$GLOBALS['what'] = 'foo';
$GLOBALS['foo_columns'] = "&";
$GLOBALS['foo_null'] = ">";
ob_start();
$this->assertTrue(
$this->object->exportData(
'db', 'ta<ble', "\n", "example.com", "SELECT"
)
);
$result = ob_get_clean();
$this->assertContains(
"|fName1|fNa&amp;quot;me2|fName3",
$result
);
$this->assertContains(
"|&amp;gt;|0|test",
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::getTableDefStandIn
*
* @return void
*/
public function testGetTableDefStandIn()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('getColumns')
->with('db', 'view')
->will($this->returnValue(array(1, 2)));
$keys = array(
array(
'Non_unique' => 0,
'Column_name' => 'cname'
),
array(
'Non_unique' => 1,
'Column_name' => 'cname2'
)
);
$dbi->expects($this->once())
->method('getTableIndexes')
->with('db', 'view')
->will($this->returnValue($keys));
$dbi->expects($this->once())
->method('selectDb')
->with('db');
$GLOBALS['dbi'] = $dbi;
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportTexytext')
->disableOriginalConstructor()
->setMethods(array('formatOneColumnDefinition'))
->getMock();
$this->object->expects($this->at(0))
->method('formatOneColumnDefinition')
->with(1, array('cname'))
->will($this->returnValue('c1'));
$this->object->expects($this->at(1))
->method('formatOneColumnDefinition')
->with(2, array('cname'))
->will($this->returnValue('c2'));
$result = $this->object->getTableDefStandIn('db', 'view', '#');
$this->assertContains(
"c1\nc2",
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::getTableDef
*
* @return void
*/
public function testGetTableDef()
{
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportTexytext')
->setMethods(array('formatOneColumnDefinition'))
->getMock();
$GLOBALS['controllink'] = null;
// case 1
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$keys = array(
array(
'Non_unique' => 0,
'Column_name' => 'cname'
),
array(
'Non_unique' => 1,
'Column_name' => 'cname2'
)
);
$dbi->expects($this->once())
->method('getTableIndexes')
->with('db', 'table')
->will($this->returnValue($keys));
$dbi->expects($this->exactly(2))
->method('fetchResult')
->willReturnOnConsecutiveCalls(
array(
'fname' => array(
'foreign_table' => '<ftable',
'foreign_field' => 'ffield>'
)
),
array(
'fname' => array(
'values' => 'test-',
'transformation' => 'testfoo',
'mimetype' => 'test<'
)
)
);
$dbi->expects($this->once())
->method('fetchValue')
->will(
$this->returnValue(
'SELECT a FROM b'
)
);
$columns = array(
'Field' => 'fname',
'Comment' => 'comm'
);
$dbi->expects($this->exactly(2))
->method('getColumns')
->with('db', 'table')
->will($this->returnValue(array($columns)));
$GLOBALS['dbi'] = $dbi;
$this->object->expects($this->exactly(1))
->method('formatOneColumnDefinition')
->with(array('Field' => 'fname', 'Comment' => 'comm'), array('cname'))
->will($this->returnValue(1));
$GLOBALS['cfgRelation']['relation'] = true;
$_SESSION['relation'][0] = array(
'PMA_VERSION' => PMA_VERSION,
'relwork' => true,
'commwork' => true,
'mimework' => true,
'db' => 'db',
'relation' => 'rel',
'column_info' => 'col'
);
$result = $this->object->getTableDef(
'db',
'table',
"\n",
"example.com",
true,
true,
true
);
$this->assertContains(
'1|&lt;ftable (ffield&gt;)|comm|Test&lt;',
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::getTriggers
*
* @return void
*/
public function testGetTriggers()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$triggers = array(
array(
'name' => 'tna"me',
'action_timing' => 'ac>t',
'event_manipulation' => 'manip&',
'definition' => 'def'
)
);
$dbi->expects($this->once())
->method('getTriggers')
->with('database', 'ta<ble')
->will($this->returnValue($triggers));
$GLOBALS['dbi'] = $dbi;
$result = $this->object->getTriggers('database', 'ta<ble');
$this->assertContains(
'|tna"me|ac>t|manip&|def',
$result
);
$this->assertContains(
'|Name|Time|Event|Definition',
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::exportStructure
*
* @return void
*/
public function testExportStructure()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('getTriggers')
->with('db', 't&bl')
->will($this->returnValue(1));
$this->object = $this->getMockBuilder('PMA\libraries\plugins\export\ExportTexytext')
->setMethods(array('getTableDef', 'getTriggers', 'getTableDefStandIn'))
->getMock();
$this->object->expects($this->at(0))
->method('getTableDef')
->with('db', 't&bl', "\n", "example.com", false, false, false, false)
->will($this->returnValue('dumpText1'));
$this->object->expects($this->once())
->method('getTriggers')
->with('db', 't&bl')
->will($this->returnValue('dumpText2'));
$this->object->expects($this->at(2))
->method('getTableDef')
->with(
'db', 't&bl', "\n", "example.com",
false, false, false, false, true, true
)
->will($this->returnValue('dumpText3'));
$this->object->expects($this->once())
->method('getTableDefStandIn')
->with('db', 't&bl', "\n")
->will($this->returnValue('dumpText4'));
$GLOBALS['dbi'] = $dbi;
// case 1
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'db', 't&bl', "\n", "example.com", "create_table", "test"
)
);
$result = ob_get_clean();
$this->assertContains(
'== Table structure for table t&amp;bl' . "\n\ndumpText1",
$result
);
// case 2
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'db', 't&bl', "\n", "example.com", "triggers", "test"
)
);
$result = ob_get_clean();
$this->assertEquals(
'== Triggers t&amp;bl' . "\n\ndumpText2",
$result
);
// case 3
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'db', 't&bl', "\n", "example.com", "create_view", "test"
)
);
$result = ob_get_clean();
$this->assertEquals(
'== Structure for view t&amp;bl' . "\n\ndumpText3",
$result
);
// case 4
ob_start();
$this->assertTrue(
$this->object->exportStructure(
'db', 't&bl', "\n", "example.com", "stand_in", "test"
)
);
$result = ob_get_clean();
$this->assertEquals(
'== Stand-in structure for view t&amp;bl' . "\n\ndumpText4",
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportTexytext::formatOneColumnDefinition
*
* @return void
*/
public function testFormatOneColumnDefinition()
{
$cols = array(
'Null' => 'Yes',
'Field' => 'field',
'Key' => 'PRI',
'Type' => 'set(abc)enum123'
);
$unique_keys = array(
'field'
);
$this->assertEquals(
'|//**field**//|set(abc)|Yes|NULL',
$this->object->formatOneColumnDefinition($cols, $unique_keys)
);
$cols = array(
'Null' => 'NO',
'Field' => 'fields',
'Key' => 'COMP',
'Type' => '',
'Default' => 'def'
);
$unique_keys = array(
'field'
);
$this->assertEquals(
'|fields|&amp;nbsp;|No|def',
$this->object->formatOneColumnDefinition($cols, $unique_keys)
);
}
}

View File

@ -0,0 +1,564 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportXml class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportXml;
use PMA\libraries\Table;
$GLOBALS['db'] = 'db';
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportXml class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportXmlTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['server'] = 0;
$GLOBALS['output_kanji_conversion'] = false;
$GLOBALS['buffer_needed'] = false;
$GLOBALS['asfile'] = false;
$GLOBALS['save_on_server'] = false;
$GLOBALS['plugin_param'] = array();
$GLOBALS['plugin_param']['export_type'] = 'table';
$GLOBALS['plugin_param']['single_table'] = false;
$GLOBALS['cfgRelation']['relation'] = true;
$this->object = new ExportXml();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportXml::setProperties
*
* @return void
* @group medium
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportXml', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportXml', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'XML',
$properties->getText()
);
$this->assertEquals(
'xml',
$properties->getExtension()
);
$this->assertEquals(
'text/xml',
$properties->getMimeType()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\HiddenPropertyItem',
$property
);
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'structure',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'data',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\BoolPropertyItem',
$property
);
}
/**
* Test for PMA\libraries\plugins\export\ExportXml::exportHeader
*
* @return void
* @group medium
*/
public function testExportHeader()
{
if (!defined("PMA_MYSQL_STR_VERSION")) {
define("PMA_MYSQL_STR_VERSION", "5.0.0");
}
$GLOBALS['xml_export_functions'] = 1;
$GLOBALS['xml_export_contents'] = 1;
$GLOBALS['output_charset_conversion'] = 1;
$GLOBALS['charset'] = 'iso-8859-1';
$GLOBALS['cfg']['Server']['port'] = 80;
$GLOBALS['cfg']['Server']['host'] = 'localhost';
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['xml_export_tables'] = 1;
$GLOBALS['xml_export_triggers'] = 1;
$GLOBALS['xml_export_procedures'] = 1;
$GLOBALS['xml_export_functions'] = 1;
$GLOBALS['crlf'] = "\n";
$GLOBALS['db'] = 'd<"b';
$result = array(
0 => array(
'DEFAULT_COLLATION_NAME' => 'utf8_general_ci',
'DEFAULT_CHARACTER_SET_NAME' => 'utf-8',
),
'table' => array(null, '"tbl"')
);
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->exactly(3))
->method('fetchResult')
->willReturnOnConsecutiveCalls(
$result,
$result,
false
);
$dbi->expects($this->once())
->method('getTriggers')
->with('d<"b', 'table')
->will(
$this->returnValue(
array(
array(
'create' => 'crt',
'name' => 'trname'
)
)
)
);
$dbi->expects($this->exactly(2))
->method('getProceduresOrFunctions')
->willReturnOnConsecutiveCalls(
array(
'fn'
),
array(
'pr'
)
);
$dbi->expects($this->exactly(2))
->method('getDefinition')
->willReturnOnConsecutiveCalls(
'fndef',
'prdef'
);
$dbi->expects($this->once())
->method('getTable')
->will($this->returnValue(new Table('table', 'd<"b', $dbi)));
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$GLOBALS['tables'] = array();
$GLOBALS['table'] = 'table';
ob_start();
$this->assertTrue(
$this->object->exportHeader()
);
$result = ob_get_clean();
$this->assertContains(
'&lt;pma_xml_export version=&quot;1.0&quot; xmlns:pma=&quot;' .
'https://www.phpmyadmin.net/some_doc_url/&quot;&gt;',
$result
);
$this->assertContains(
'&lt;pma:structure_schemas&gt;' . "\n" .
' &lt;pma:database name=&quot;d&amp;lt;&amp;quot;b&quot; collat' .
'ion=&quot;utf8_general_ci&quot; charset=&quot;utf-8&quot;&gt;' . "\n" .
' &lt;pma:table name=&quot;table&quot;&gt;' . "\n" .
' &amp;quot;tbl&amp;quot;;' . "\n" .
' &lt;/pma:table&gt;' . "\n" .
' &lt;pma:trigger name=&quot;trname&quot;&gt;' . "\n" .
' ' . "\n" .
' &lt;/pma:trigger&gt;' . "\n" .
' &lt;pma:function name=&quot;fn&quot;&gt;' . "\n" .
' fndef' . "\n" .
' &lt;/pma:function&gt;' . "\n" .
' &lt;pma:procedure name=&quot;pr&quot;&gt;' . "\n" .
' prdef' . "\n" .
' &lt;/pma:procedure&gt;' . "\n" .
' &lt;/pma:database&gt;' . "\n" .
' &lt;/pma:structure_schemas&gt;',
$result
);
// case 2 with isView as true and false
unset($GLOBALS['xml_export_contents']);
unset($GLOBALS['xml_export_views']);
unset($GLOBALS['xml_export_tables']);
unset($GLOBALS['xml_export_functions']);
unset($GLOBALS['xml_export_procedures']);
$GLOBALS['output_charset_conversion'] = 0;
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$result_1 = array(
array(
'DEFAULT_COLLATION_NAME' => 'utf8_general_ci',
'DEFAULT_CHARACTER_SET_NAME' => 'utf-8',
)
);
$result_2 = array(
't1' => array(null, '"tbl"')
);
$result_3 = array(
't2' => array(null, '"tbl"')
);
$dbi->expects($this->exactly(5))
->method('fetchResult')
->willReturnOnConsecutiveCalls(
$result_1,
$result_2,
true,
$result_3,
false
);
$dbi->expects($this->any())
->method('getTable')
->will($this->returnValue(new Table('table', 'd<"b', $dbi)));
$GLOBALS['dbi'] = $dbi;
$GLOBALS['tables'] = array('t1', 't2');
ob_start();
$this->assertTrue(
$this->object->exportHeader()
);
$result = ob_get_clean();
//echo $result; die;
$this->assertContains(
'&lt;pma:structure_schemas&gt;' . "\n" .
' &lt;pma:database name=&quot;d&amp;lt;&amp;quot;b&quot; collat' .
'ion=&quot;utf8_general_ci&quot; charset=&quot;utf-8&quot;&gt;' . "\n" .
' &lt;/pma:database&gt;' . "\n" .
' &lt;/pma:structure_schemas&gt;',
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportXml::exportFooter
*
* @return void
*/
public function testExportFooter()
{
$this->expectOutputString(
'&lt;/pma_xml_export&gt;'
);
$this->assertTrue(
$this->object->exportFooter()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportXml::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
$GLOBALS['xml_export_contents'] = true;
ob_start();
$this->assertTrue(
$this->object->exportDBHeader('&db')
);
$result = ob_get_clean();
$this->assertContains(
'&lt;database name=&quot;&amp;amp;db&quot;&gt;',
$result
);
$GLOBALS['xml_export_contents'] = false;
$this->assertTrue(
$this->object->exportDBHeader('&db')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportXml::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$GLOBALS['xml_export_contents'] = true;
ob_start();
$this->assertTrue(
$this->object->exportDBFooter('&db')
);
$result = ob_get_clean();
$this->assertContains(
'&lt;/database&gt;',
$result
);
$GLOBALS['xml_export_contents'] = false;
$this->assertTrue(
$this->object->exportDBFooter('&db')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportXml::exportDBCreate
*
* @return void
*/
public function testExportDBCreate()
{
$this->assertTrue(
$this->object->exportDBCreate('testDB', 'database')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportXml::exportData
*
* @return void
*/
public function testExportData()
{
$GLOBALS['xml_export_contents'] = true;
$GLOBALS['asfile'] = true;
$GLOBALS['output_charset_conversion'] = false;
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$_table = $this->getMockBuilder('PMA\libraries\Table')
->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', null, PMA\libraries\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(array(null, '<a>')));
$GLOBALS['dbi'] = $dbi;
ob_start();
$this->assertTrue(
$this->object->exportData(
'db', 'ta<ble', "\n", "example.com", "SELECT"
)
);
$result = ob_get_clean();
$this->assertContains(
"<!-- Table ta&lt;ble -->",
$result
);
$this->assertContains(
"<table name=\"ta&lt;ble\">",
$result
);
$this->assertContains(
"<column name=\"fName1\">NULL</column>",
$result
);
$this->assertContains(
"<column name=\"fNa&quot;me2\">&lt;a&gt;" .
"</column>",
$result
);
$this->assertContains(
"<column name=\"fName3\">NULL</column>",
$result
);
$this->assertContains(
"</table>",
$result
);
}
}

View File

@ -0,0 +1,268 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\ExportYaml class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\ExportYaml;
require_once 'libraries/export.lib.php';
require_once 'libraries/config.default.php';
require_once 'libraries/database_interface.inc.php';
require_once 'export.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\ExportYaml class
*
* @package PhpMyAdmin-test
* @group medium
*/
class ExportYamlTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['server'] = 0;
$GLOBALS['output_kanji_conversion'] = false;
$GLOBALS['buffer_needed'] = false;
$GLOBALS['asfile'] = false;
$GLOBALS['save_on_server'] = false;
$GLOBALS['crlf'] = "\n";
$GLOBALS['cfgRelation']['relation'] = true;
$this->object = new ExportYaml();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\ExportYaml::setProperties
*
* @return void
*/
public function testSetProperties()
{
$method = new ReflectionMethod('PMA\libraries\plugins\export\ExportYaml', 'setProperties');
$method->setAccessible(true);
$method->invoke($this->object, null);
$attrProperties = new ReflectionProperty('PMA\libraries\plugins\export\ExportYaml', 'properties');
$attrProperties->setAccessible(true);
$properties = $attrProperties->getValue($this->object);
$this->assertInstanceOf(
'PMA\libraries\properties\plugins\ExportPluginProperties',
$properties
);
$this->assertEquals(
'YAML',
$properties->getText()
);
$this->assertEquals(
'yml',
$properties->getExtension()
);
$this->assertEquals(
'text/yaml',
$properties->getMimeType()
);
$options = $properties->getOptions();
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyRootGroup',
$options
);
$this->assertEquals(
'Format Specific Options',
$options->getName()
);
$generalOptionsArray = $options->getProperties();
$generalOptions = array_shift($generalOptionsArray);
$this->assertInstanceOf(
'PMA\libraries\properties\options\groups\OptionsPropertyMainGroup',
$generalOptions
);
$this->assertEquals(
'general_opts',
$generalOptions->getName()
);
$generalProperties = $generalOptions->getProperties();
$property = array_shift($generalProperties);
$this->assertInstanceOf(
'PMA\libraries\properties\options\items\HiddenPropertyItem',
$property
);
}
/**
* Test for PMA\libraries\plugins\export\ExportYaml::exportHeader
*
* @return void
*/
public function testExportHeader()
{
ob_start();
$this->assertTrue(
$this->object->exportHeader()
);
$result = ob_get_clean();
$this->assertContains(
"%YAML 1.1\n---\n",
$result
);
}
/**
* Test for PMA\libraries\plugins\export\ExportYaml::exportFooter
*
* @return void
*/
public function testExportFooter()
{
$this->expectOutputString(
"...\n"
);
$this->assertTrue(
$this->object->exportFooter()
);
}
/**
* Test for PMA\libraries\plugins\export\ExportYaml::exportDBHeader
*
* @return void
*/
public function testExportDBHeader()
{
$this->assertTrue(
$this->object->exportDBHeader('&db')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportYaml::exportDBFooter
*
* @return void
*/
public function testExportDBFooter()
{
$this->assertTrue(
$this->object->exportDBFooter('&db')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportYaml::exportDBCreate
*
* @return void
*/
public function testExportDBCreate()
{
$this->assertTrue(
$this->object->exportDBCreate('testDB', 'database')
);
}
/**
* Test for PMA\libraries\plugins\export\ExportYaml::exportData
*
* @return void
*/
public function testExportData()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('query')
->with('SELECT', null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED)
->will($this->returnValue(true));
$dbi->expects($this->once())
->method('numFields')
->with(true)
->will($this->returnValue(4));
$dbi->expects($this->at(2))
->method('fieldName')
->will($this->returnValue('fName1'));
$dbi->expects($this->at(3))
->method('fieldName')
->will($this->returnValue('fNa"me2'));
$dbi->expects($this->at(4))
->method('fieldName')
->will($this->returnValue('fNa\\me3'));
$dbi->expects($this->at(5))
->method('fieldName')
->will($this->returnValue('fName4'));
$dbi->expects($this->at(6))
->method('fetchRow')
->with(true)
->will(
$this->returnValue(
array(null, '123', "\"c\\a\nb\r")
)
);
$dbi->expects($this->at(7))
->method('fetchRow')
->with(true)
->will(
$this->returnValue(
array(null)
)
);
$GLOBALS['dbi'] = $dbi;
ob_start();
$this->assertTrue(
$this->object->exportData(
'db', 'ta<ble', "\n", "example.com", "SELECT"
)
);
$result = ob_get_clean();
$this->assertEquals(
'# db.ta&lt;ble' . "\n" .
'-' . "\n" .
' fNa&quot;me2: 123' . "\n" .
' fName3: &quot;\&quot;c\\\\a\nb\r&quot;' . "\n" .
'-' . "\n",
$result
);
}
}

View File

@ -0,0 +1,343 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\export\TableProperty class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\export\TableProperty;
require_once 'libraries/config.default.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\export\TableProperty class
*
* @package PhpMyAdmin-test
*/
class TablePropertyTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['server'] = 0;
$row = array(' name ', 'int ', true, ' PRI', '0', 'mysql');
$this->object = new TableProperty($row);
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\export\TableProperty::__construct
*
* @return void
*/
public function testConstructor()
{
$this->assertEquals(
'name',
$this->object->name
);
$this->assertEquals(
'int',
$this->object->type
);
$this->assertEquals(
1,
$this->object->nullable
);
$this->assertEquals(
'PRI',
$this->object->key
);
$this->assertEquals(
'0',
$this->object->defaultValue
);
$this->assertEquals(
'mysql',
$this->object->ext
);
}
/**
* Test for PMA\libraries\plugins\export\TableProperty::getPureType
*
* @return void
*/
public function testGetPureType()
{
$this->object->type = "int(10)";
$this->assertEquals(
"int",
$this->object->getPureType()
);
$this->object->type = "char";
$this->assertEquals(
"char",
$this->object->getPureType()
);
}
/**
* Test for PMA\libraries\plugins\export\TableProperty::isNotNull
*
* @param string $nullable nullable value
* @param string $expected expected output
*
* @return void
* @dataProvider isNotNullProvider
*/
public function testIsNotNull($nullable, $expected)
{
$this->object->nullable = $nullable;
$this->assertEquals(
$expected,
$this->object->isNotNull()
);
}
/**
* Data provider for testIsNotNull
*
* @return array Test Data
*/
public function isNotNullProvider()
{
return array(
array("NO", "true"),
array("", "false"),
array("no", "false")
);
}
/**
* Test for PMA\libraries\plugins\export\TableProperty::isUnique
*
* @param string $key key value
* @param string $expected expected output
*
* @return void
* @dataProvider isUniqueProvider
*/
public function testIsUnique($key, $expected)
{
$this->object->key = $key;
$this->assertEquals(
$expected,
$this->object->isUnique()
);
}
/**
* Data provider for testIsUnique
*
* @return array Test Data
*/
public function isUniqueProvider()
{
return array(
array("PRI", "true"),
array("UNI", "true"),
array("", "false"),
array("pri", "false"),
array("uni", "false"),
);
}
/**
* Test for PMA\libraries\plugins\export\TableProperty::getDotNetPrimitiveType
*
* @param string $type type value
* @param string $expected expected output
*
* @return void
* @dataProvider getDotNetPrimitiveTypeProvider
*/
public function testGetDotNetPrimitiveType($type, $expected)
{
$this->object->type = $type;
$this->assertEquals(
$expected,
$this->object->getDotNetPrimitiveType()
);
}
/**
* Data provider for testGetDotNetPrimitiveType
*
* @return array Test Data
*/
public function getDotNetPrimitiveTypeProvider()
{
return array(
array("int", "int"),
array("long", "long"),
array("char", "string"),
array("varchar", "string"),
array("text", "string"),
array("longtext", "string"),
array("tinyint", "bool"),
array("datetime", "DateTime"),
array("", "unknown"),
array("dummy", "unknown"),
array("INT", "unknown")
);
}
/**
* Test for PMA\libraries\plugins\export\TableProperty::getDotNetObjectType
*
* @param string $type type value
* @param string $expected expected output
*
* @return void
* @dataProvider getDotNetObjectTypeProvider
*/
public function testGetDotNetObjectType($type, $expected)
{
$this->object->type = $type;
$this->assertEquals(
$expected,
$this->object->getDotNetObjectType()
);
}
/**
* Data provider for testGetDotNetObjectType
*
* @return array Test Data
*/
public function getDotNetObjectTypeProvider()
{
return array(
array("int", "Int32"),
array("long", "Long"),
array("char", "String"),
array("varchar", "String"),
array("text", "String"),
array("longtext", "String"),
array("tinyint", "Boolean"),
array("datetime", "DateTime"),
array("", "Unknown"),
array("dummy", "Unknown"),
array("INT", "Unknown")
);
}
/**
* Test for PMA\libraries\plugins\export\TableProperty::getIndexName
*
* @return void
*/
public function testGetIndexName()
{
$this->object->name = "ä'7<ab>";
$this->object->key = "PRI";
$this->assertEquals(
"index=\"ä'7&lt;ab&gt;\"",
$this->object->getIndexName()
);
$this->object->key = "";
$this->assertEquals(
"",
$this->object->getIndexName()
);
}
/**
* Test for PMA\libraries\plugins\export\TableProperty::isPK
*
* @return void
*/
public function testIsPK()
{
$this->object->key = "PRI";
$this->assertTrue(
$this->object->isPK()
);
$this->object->key = "";
$this->assertFalse(
$this->object->isPK()
);
}
/**
* Test for PMA\libraries\plugins\export\TableProperty::formatCs
*
* @return void
*/
public function testFormatCs()
{
$this->object->name = 'Name#name#123';
$this->assertEquals(
'text123Namename',
$this->object->formatCs("text123#name#")
);
}
/**
* Test for PMA\libraries\plugins\export\TableProperty::formatXml
*
* @return void
*/
public function testFormatXml()
{
$this->object->name = '"a\'';
$this->assertEquals(
'&quot;a\'index="&quot;a\'"',
$this->object->formatXml("#name##indexName#")
);
}
/**
* Test for PMA\libraries\plugins\export\TableProperty::format
*
* @return void
*/
public function testFormat()
{
$this->assertEquals(
'NameintInt32intfalsetrue',
$this->object->format(
"#ucfirstName##dotNetPrimitiveType##dotNetObjectType##type#" .
"#notNull##unique#"
)
);
}
}