Merge branch 'master' of https://github.com/phpmyadmin/phpmyadmin into server_refactor2

This commit is contained in:
xmujay 2013-07-21 22:12:33 +08:00
commit 751caca3bf
8 changed files with 363 additions and 40 deletions

View File

@ -2,7 +2,7 @@
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* functions for displaying server export
* functions for displaying server, database and table export
*
* @usedby server_export.php and display_export.inc.php
*
@ -29,7 +29,7 @@ function PMA_exportCheckboxCheck($str)
/**
* Prints Html For Export Selection Options
*
* @param String $tmp_select Tmp seleted method of export
* @param String $tmp_select Tmp selected method of export
*
* @return string
*/
@ -398,7 +398,7 @@ function PMA_getHtmlForExportOptionsQuickExport()
*
* @return string
*/
function PMA_getHtmlForExportOptionsOuputSaveDir()
function PMA_getHtmlForExportOptionsOutputSaveDir()
{
global $cfg;
$html = '<li>';
@ -434,7 +434,7 @@ function PMA_getHtmlForExportOptionsOuputSaveDir()
*
* @return string
*/
function PMA_getHtmlForExportOptionsOuputFormat($export_type)
function PMA_getHtmlForExportOptionsOutputFormat($export_type)
{
$html = '<li>';
$html .= '<label for="filename_template" class="desc">';
@ -518,7 +518,7 @@ function PMA_getHtmlForExportOptionsOuputFormat($export_type)
*
* @return string
*/
function PMA_getHtmlForExportOptionsOuputCharset()
function PMA_getHtmlForExportOptionsOutputCharset()
{
global $cfg;
$html = ' <li><label for="select_charset_of_file" class="desc">'
@ -548,7 +548,7 @@ function PMA_getHtmlForExportOptionsOuputCharset()
*
* @return string
*/
function PMA_getHtmlForExportOptionsOuputCompression()
function PMA_getHtmlForExportOptionsOutputCompression()
{
global $cfg;
if (isset($_GET['compression'])) {
@ -606,7 +606,7 @@ function PMA_getHtmlForExportOptionsOuputCompression()
*
* @return string
*/
function PMA_getHtmlForExportOptionsOuputRadio()
function PMA_getHtmlForExportOptionsOutputRadio()
{
$html = '<li>';
$html .= '<input type="radio" id="radio_view_as_text" '
@ -627,7 +627,7 @@ function PMA_getHtmlForExportOptionsOuputRadio()
*
* @return string
*/
function PMA_getHtmlForExportOptionsOuput($export_type)
function PMA_getHtmlForExportOptionsOutput($export_type)
{
global $cfg;
$html = '<div class="exportoptions" id="output">';
@ -644,22 +644,22 @@ function PMA_getHtmlForExportOptionsOuput($export_type)
. __('Save output to a file') . '</label>';
$html .= '<ul id="ul_save_asfile">';
if (isset($cfg['SaveDir']) && !empty($cfg['SaveDir'])) {
$html .= PMA_getHtmlForExportOptionsOuputSaveDir();
$html .= PMA_getHtmlForExportOptionsOutputSaveDir();
}
$html .= PMA_getHtmlForExportOptionsOuputFormat($export_type);
$html .= PMA_getHtmlForExportOptionsOutputFormat($export_type);
// charset of file
if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE) {
$html .= PMA_getHtmlForExportOptionsOuputCharset();
$html .= PMA_getHtmlForExportOptionsOutputCharset();
} // end if
$html .= PMA_getHtmlForExportOptionsOuputCompression();
$html .= PMA_getHtmlForExportOptionsOutputCompression();
$html .= '</ul>';
$html .= '</li>';
$html .= PMA_getHtmlForExportOptionsOuputRadio();
$html .= PMA_getHtmlForExportOptionsOutputRadio();
$html .= '</ul>';
$html .= '</div>';
@ -697,12 +697,9 @@ function PMA_getHtmlForExportOptions(
$html .= PMA_getHtmlForExportOptionsQuickExport();
}
$html .= PMA_getHtmlForExportOptionsOuput($export_type);
$html .= PMA_getHtmlForExportOptionsOutput($export_type);
$html .= PMA_getHtmlForExportOptionsFormat($export_list);
return $html;
}
?>

View File

@ -4,7 +4,7 @@
* Handles table search tab
*
* display table search form, create SQL query from form data
* and include sql.php to execute it
* and call PMA_executeQueryAndSendQueryResponse() to execute it
*
* @package PhpMyAdmin
*/
@ -15,6 +15,7 @@
require_once 'libraries/common.inc.php';
require_once 'libraries/mysql_charsets.inc.php';
require_once 'libraries/TableSearch.class.php';
require_once 'libraries/sql.lib.php';
$response = PMA_Response::getInstance();
$header = $response->getHeader();
@ -65,6 +66,16 @@ if (! isset($_POST['columnsToDisplay']) && ! isset($_POST['displayAllColumns']))
* Selection criteria have been submitted -> do the work
*/
$sql_query = $table_search->buildSqlQuery();
include 'sql.php';
/**
* Parse and analyze the query
*/
require_once 'libraries/parse_analyze.inc.php';
PMA_executeQueryAndSendQueryResponse(
$analyzed_sql_results, false, $db, $table, null, null, null, false, null,
null, null, null, $goto, $pmaThemeImage, null, null, null, $sql_query,
null, null
);
}
?>

View File

@ -136,7 +136,7 @@ class PMA_TableSearch_Test extends PHPUnit_Framework_TestCase
*/
public function testGetSelectionForm()
{
//$this->_searchType == 'zoom'
//$this->_searchType == 'zoom'
$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom");
$url_goto = "http://phpmyadmin.net";
$form = $tableSearch->getSelectionForm($url_goto);
@ -149,7 +149,7 @@ class PMA_TableSearch_Test extends PHPUnit_Framework_TestCase
$form
);
//$this->_searchType == 'normal'
//$this->_searchType == 'normal'
$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "normal");
$url_goto = "http://phpmyadmin.net";
$form = $tableSearch->getSelectionForm($url_goto);
@ -162,7 +162,7 @@ class PMA_TableSearch_Test extends PHPUnit_Framework_TestCase
$form
);
//$this->_searchType == 'replace'
//$this->_searchType == 'replace'
$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "replace");
$url_goto = "http://phpmyadmin.net";
$form = $tableSearch->getSelectionForm($url_goto);
@ -197,7 +197,7 @@ class PMA_TableSearch_Test extends PHPUnit_Framework_TestCase
$this->assertContains(
__('Zoom Search'),
$html
);
);
$this->assertContains(
__('Find and Replace'),
$html
@ -223,7 +223,31 @@ class PMA_TableSearch_Test extends PHPUnit_Framework_TestCase
json_encode($data),
$html
);
}
/**
* Test for replace
*
* @return void
*/
public function testReplace()
{
$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom");
$columnIndex = 0;
$find = "Field";
$replaceWith = "Column";
$charSet = "UTF-8";
$tableSearch->replace($columnIndex, $find, $replaceWith, $charSet);
$sql_query = $GLOBALS['sql_query'];
$result = "UPDATE `PMA`.`PMA_BookMark` SET `Field1` = "
. "REPLACE(`Field1`, 'Field', 'Column') "
. "WHERE `Field1` LIKE '%Field%' COLLATE UTF-8_bin";
$this->assertEquals(
$result,
$sql_query
);
}
/**
@ -243,7 +267,79 @@ class PMA_TableSearch_Test extends PHPUnit_Framework_TestCase
__('Replace with:'),
$html
);
}
/**
* Test for getReplacePreview
*
* @return void
*/
public function testGetReplacePreview()
{
$value = array(
'value',
'replace_value',
'count'
);
$dbi = $GLOBALS['dbi'];
$dbi->expects($this->at(3))->method('fetchRow')
->will($this->returnValue($value));
$dbi->expects($this->at(4))->method('fetchRow')
->will($this->returnValue(false));
$GLOBALS['dbi'] = $dbi;
$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom");
$columnIndex = 0;
$find = "Field";
$replaceWith = "Column";
$charSet = "UTF-8";
$html = $tableSearch->getReplacePreview(
$columnIndex,
$find,
$replaceWith,
$charSet
);
$this->assertContains(
'<form method="post" action="tbl_find_replace.php"',
$html
);
$this->assertContains(
'<input type="hidden" name="replace" value="true" />',
$html
);
$this->assertContains(
__('Find and replace - preview'),
$html
);
$this->assertContains(
__('Original string'),
$html
);
$this->assertContains(
__('Replaced string'),
$html
);
$this->assertContains(
'<td>value</td>',
$html
);
$this->assertContains(
'<td>replace_value</td>',
$html
);
$this->assertContains(
'<td class="right">count</td>',
$html
);
}
}
?>

View File

@ -46,6 +46,12 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase
$GLOBALS['pmaThemeImage'] = 'themes/dot.gif';
$GLOBALS['is_ajax_request'] = false;
$GLOBALS['cfgRelation'] = PMA_getRelationsParam();
PMA_Table::$cache["PMA"]["PMA_BookMark"] = array(
'ENGINE' => true,
'Create_time' => true,
'TABLE_TYPE' => true,
'Comment' => true,
);
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
@ -202,11 +208,14 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase
->will($this->returnValue($getUniqueColumns_sql));
$GLOBALS['dbi'] = $dbi;
//RunKit, we test:
//1. without Runkit, PMA_DRIZZLE = true;
//2. with Runkit, PMA_DRIZZLE = false;
if (!defined("PMA_DRIZZLE")) {
define("PMA_DRIZZLE", true);
}
//RunKit
if (PMA_HAS_RUNKIT) {
runkit_constant_redefine("PMA_DRIZZLE", false);
}
@ -689,6 +698,37 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase
}
}
/**
*
* Tests behaviour of PMA_Table class with Runkit and PMA_Drizzle = false
*
* @package PhpMyAdmin-test
*/
class PMA_Table_Runkit_Test extends PMA_Table_Test
{
/**
* Configures environment
*
* @return void
*/
protected function setUp()
{
//we test:
//1. without Runkit, PMA_DRIZZLE = false;
//2. with Runkit, PMA_DRIZZLE = true;
if (!defined("PMA_DRIZZLE")) {
define("PMA_DRIZZLE", false);
}
parent::setUp();
//RunKit
if (PMA_HAS_RUNKIT) {
runkit_constant_redefine("PMA_DRIZZLE", true);
}
}
}
//mock PMA
Class DataBasePMAMock
{

View File

@ -11,7 +11,9 @@
require_once 'libraries/Util.class.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/sqlparser.lib.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/Index.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/Response.class.php';
require_once 'libraries/schema/Dia_Relation_Schema.class.php';
@ -46,11 +48,13 @@ class PMA_Dia_Relation_Schema_Test extends PHPUnit_Framework_TestCase
$_POST['export_type'] = 'PMA_ExportType';
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['ServerDefault'] = 1;
$GLOBALS['cfg']['Server']['table_coords'] = "table_name";
$GLOBALS['cfgRelation']['db'] = "PMA";
$GLOBALS['cfgRelation']['table_coords'] = "table_name";
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
$dbi->expects($this->any())
->method('numRows')
@ -65,12 +69,43 @@ class PMA_Dia_Relation_Schema_Test extends PHPUnit_Framework_TestCase
->will($this->returnValue("executed_1"));
$fetchArrayReturn = array(
'table_name' => 'table_name'
'table_name' => 'pma_table_name'
);
$dbi->expects($this->at(1))
$dbi->expects($this->at(2))
->method('fetchAssoc')
->will($this->returnValue($fetchArrayReturn));
$dbi->expects($this->at(3))
->method('fetchAssoc')
->will($this->returnValue(false));
$getIndexesResult = array(
array(
'Table' => 'pma_tbl',
'Field' => 'field1',
'Key' => 'PRIMARY',
'Key_name' => "Key_name",
'Column_name' => "Column_name"
)
);
$dbi->expects($this->any())->method('getTableIndexes')
->will($this->returnValue($getIndexesResult));
$fetchValue = "CREATE TABLE `pma_bookmark` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dbase` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`user` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`label` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '',
`query` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Bookmarks'";
$dbi->expects($this->once())
->method('fetchValue')
->will($this->returnValue($fetchValue));
$GLOBALS['dbi'] = $dbi;
$this->object = new PMA_Dia_Relation_Schema();
}
@ -94,7 +129,7 @@ class PMA_Dia_Relation_Schema_Test extends PHPUnit_Framework_TestCase
* @group medium
*/
public function testSetProperty()
{
{
$this->assertEquals(
33,
$this->object->pageNumber

View File

@ -11,7 +11,9 @@
require_once 'libraries/Util.class.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/sqlparser.lib.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/Index.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/schema/Eps_Relation_Schema.class.php';
@ -47,11 +49,13 @@ class PMA_Eps_Relation_Schema_Test extends PHPUnit_Framework_TestCase
$_POST['export_type'] = 'PMA_ExportType';
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['ServerDefault'] = 1;
$GLOBALS['cfg']['Server']['table_coords'] = "table_name";
$GLOBALS['cfgRelation']['db'] = "PMA";
$GLOBALS['cfgRelation']['table_coords'] = "table_name";
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
$dbi->expects($this->any())
->method('numRows')
@ -66,11 +70,42 @@ class PMA_Eps_Relation_Schema_Test extends PHPUnit_Framework_TestCase
->will($this->returnValue("executed_1"));
$fetchArrayReturn = array(
'table_name' => 'table_name'
'table_name' => 'pma_table_name'
);
$dbi->expects($this->at(1))
$dbi->expects($this->at(2))
->method('fetchAssoc')
->will($this->returnValue($fetchArrayReturn));
$dbi->expects($this->at(3))
->method('fetchAssoc')
->will($this->returnValue(false));
$getIndexesResult = array(
array(
'Table' => 'pma_tbl',
'Field' => 'field1',
'Key' => 'PRIMARY',
'Key_name' => "Key_name",
'Column_name' => "Column_name"
)
);
$dbi->expects($this->any())->method('getTableIndexes')
->will($this->returnValue($getIndexesResult));
$fetchValue = "CREATE TABLE `pma_bookmark` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dbase` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`user` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`label` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '',
`query` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Bookmarks'";
$dbi->expects($this->once())
->method('fetchValue')
->will($this->returnValue($fetchValue));
$GLOBALS['dbi'] = $dbi;
$this->object = new PMA_Eps_Relation_Schema();
}

View File

@ -11,7 +11,10 @@
require_once 'libraries/Util.class.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/sqlparser.lib.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/Index.class.php';
require_once 'libraries/Table.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/schema/Pdf_Relation_Schema.class.php';
@ -46,13 +49,24 @@ class PMA_Pdf_Relation_Schema_Test extends PHPUnit_Framework_TestCase
$_POST['paper'] = 'paper';
$_POST['export_type'] = 'PMA_ExportType';
$_POST['with_doc'] = 'on';
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['Server']['pmadb'] = "pmadb";
$GLOBALS['cfg']['LimitChars'] = 100;
$GLOBALS['cfg']['ServerDefault'] = 1;
$GLOBALS['cfg']['Server']['user'] = "user";
$GLOBALS['cfg']['Server']['table_coords'] = "table_name";
$GLOBALS['cfg']['Server']['bookmarktable'] = "bookmarktable";
$GLOBALS['cfg']['Server']['relation'] = "relation";
$GLOBALS['cfg']['Server']['relation'] = "relation";
$GLOBALS['cfg']['Server']['table_info'] = "table_info";
$GLOBALS['cfgRelation']['db'] = "PMA";
$GLOBALS['cfgRelation']['table_coords'] = "table_name";
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
$dbi->expects($this->any())
->method('numRows')
@ -67,11 +81,71 @@ class PMA_Pdf_Relation_Schema_Test extends PHPUnit_Framework_TestCase
->will($this->returnValue("executed_1"));
$fetchArrayReturn = array(
'table_name' => 'table_name'
'table_name' => 'pma_table_name'
);
$dbi->expects($this->at(1))
$dbi->expects($this->at(2))
->method('fetchAssoc')
->will($this->returnValue($fetchArrayReturn));
$dbi->expects($this->at(3))
->method('fetchAssoc')
->will($this->returnValue(false));
$fetchRowReturn = array(
'table_name'
);
//let fetchRow have more results
for ($index=0; $index<10; ++$index) {
$dbi->expects($this->at($index))
->method('fetchRow')
->will($this->returnValue($fetchRowReturn));
}
$dbi->expects($this->at(10))
->method('fetchRow')
->will($this->returnValue($fetchRowReturn));
$fields_info = array(
"Host" => array(
"Field" => "host",
"Type" => "char(60)",
"Null" => "NO",
'Extra' => "Extra",
)
);
$dbi->expects($this->any())->method('getColumns')
->will($this->returnValue($fields_info));
$dbi->expects($this->any())->method('selectDb')
->will($this->returnValue(true));
$getIndexesResult = array(
array(
'Table' => 'pma_tbl',
'Field' => 'field1',
'Key' => 'PRIMARY',
'Key_name' => "Key_name",
'Column_name' => "Column_name"
)
);
$dbi->expects($this->any())->method('getTableIndexes')
->will($this->returnValue($getIndexesResult));
$fetchValue = "CREATE TABLE `pma_bookmark` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dbase` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`user` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`label` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '',
`query` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Bookmarks'";
$dbi->expects($this->once())
->method('fetchValue')
->will($this->returnValue($fetchValue));
$GLOBALS['dbi'] = $dbi;
$this->object = new PMA_Pdf_Relation_Schema();
}

View File

@ -11,7 +11,9 @@
require_once 'libraries/Util.class.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/sqlparser.lib.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/Index.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/schema/Svg_Relation_Schema.class.php';
@ -48,11 +50,13 @@ class PMA_Svg_Relation_Schema_Test extends PHPUnit_Framework_TestCase
$_POST['with_doc'] = 'on';
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['ServerDefault'] = 1;
$GLOBALS['cfg']['Server']['table_coords'] = "table_name";
$GLOBALS['cfgRelation']['db'] = "PMA";
$GLOBALS['cfgRelation']['table_coords'] = "table_name";
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
$dbi->expects($this->any())
->method('numRows')
@ -67,11 +71,42 @@ class PMA_Svg_Relation_Schema_Test extends PHPUnit_Framework_TestCase
->will($this->returnValue("executed_1"));
$fetchArrayReturn = array(
'table_name' => 'table_name'
'table_name' => 'pma_table_name'
);
$dbi->expects($this->at(1))
$dbi->expects($this->at(2))
->method('fetchAssoc')
->will($this->returnValue($fetchArrayReturn));
$dbi->expects($this->at(3))
->method('fetchAssoc')
->will($this->returnValue(false));
$getIndexesResult = array(
array(
'Table' => 'pma_tbl',
'Field' => 'field1',
'Key' => 'PRIMARY',
'Key_name' => "Key_name",
'Column_name' => "Column_name"
)
);
$dbi->expects($this->any())->method('getTableIndexes')
->will($this->returnValue($getIndexesResult));
$fetchValue = "CREATE TABLE `pma_bookmark` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dbase` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`user` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`label` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '',
`query` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Bookmarks'";
$dbi->expects($this->once())
->method('fetchValue')
->will($this->returnValue($fetchValue));
$GLOBALS['dbi'] = $dbi;
$this->object = new PMA_Svg_Relation_Schema();
}