Merge branch 'master' of github.com:phpmyadmin/phpmyadmin

This commit is contained in:
Madhura Jayaratne 2015-08-25 20:07:12 +10:00
commit 47e82d6436
38 changed files with 2219 additions and 2173 deletions

View File

@ -68,7 +68,7 @@ foreach ($tables as $table) {
* Gets table information
*/
$show_comment = $GLOBALS['dbi']->getTable($db, $table)
->sGetStatusInfo('TABLE_COMMENT');
->getStatusInfo('TABLE_COMMENT');
/**
* Gets table keys and retains them

View File

@ -8,17 +8,22 @@
namespace PMA;
use PMA_Response;
require_once 'libraries/common.inc.php';
require_once 'libraries/db_common.inc.php';
require_once 'libraries/db_info.inc.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/controllers/DatabaseStructureController.class.php';
require_once 'libraries/Response.class.php';
$container = DI\Container::getDefaultContainer();
$container->factory('PMA\Controllers\DatabaseStructureController');
$container->alias(
'DatabaseStructureController', 'PMA\Controllers\DatabaseStructureController'
);
$container->set('PMA_Response', PMA_Response::getInstance());
$container->alias('response', 'PMA_Response');
global $db, $pos, $db_is_system_schema, $total_num_tables, $tables, $num_tables;
/* Define dependencies for the concerned controller */

View File

@ -1678,7 +1678,7 @@ class PMA_DisplayResults
$data_html .= '<input class="table_create_time" type="hidden" value="'
. $GLOBALS['dbi']->getTable(
$this->__get('db'), $this->__get('table')
)->sGetStatusInfo('Create_time')
)->getStatusInfo('Create_time')
. '" />';
}

View File

@ -172,7 +172,7 @@ class PMA_Table
if ($this->_dbi->getCachedTableContent("${db}.${table}") != null
|| $GLOBALS['cfg']['Server']['DisableIS']
) {
$type = $this->sGetStatusInfo('TABLE_TYPE');
$type = $this->getStatusInfo('TABLE_TYPE');
return $type == 'VIEW' || $type == 'SYSTEM VIEW';
}
@ -272,7 +272,7 @@ class PMA_Table
$engine = null;
// if called static, with parameters
if (! empty($this->_db_name) && ! empty($this->_name)) {
$engine = $this->sGetStatusInfo('ENGINE', null, true);
$engine = $this->getStatusInfo('ENGINE', null, true);
}
// did we get engine?
@ -300,7 +300,7 @@ class PMA_Table
*
* @return mixed
*/
public function sGetStatusInfo(
public function getStatusInfo(
$info = null,
$force_read = false,
$disable_error = false
@ -1644,7 +1644,7 @@ class PMA_Table
&& isset($this->uiprefs[$property])
) {
// check if the table has not been modified
if ($this->sGetStatusInfo('Create_time') == $this->uiprefs['CREATE_TIME']) {
if ($this->getStatusInfo('Create_time') == $this->uiprefs['CREATE_TIME']) {
return $this->uiprefs[$property];
} else {
// remove the property, since the table has been modified
@ -1685,7 +1685,7 @@ class PMA_Table
&& ($property == self::PROP_COLUMN_ORDER
|| $property == self::PROP_COLUMN_VISIB)
) {
$curr_create_time = $this->sGetStatusInfo('CREATE_TIME');
$curr_create_time = $this->getStatusInfo('CREATE_TIME');
if (isset($table_create_time)
&& $table_create_time == $curr_create_time
) {

View File

@ -16,7 +16,6 @@ if (!defined('PHPMYADMIN')) {
exit;
}
require_once 'libraries/Response.class.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/database_interface.inc.php';
@ -51,6 +50,6 @@ abstract class Controller
$container = Container::getDefaultContainer();
$this->container = $container;
$this->dbi = $this->container->get('dbi');
$this->response = PMA_Response::getInstance();
$this->response = $this->container->get('response');
}
}

View File

@ -16,7 +16,6 @@ use PMA_Message;
use PMA_PageSettings;
use PMA_Util;
require_once 'libraries/common.inc.php';
require_once 'libraries/mysql_charsets.inc.php';
require_once 'libraries/config/page_settings.class.php';
require_once 'libraries/display_create_table.lib.php';
@ -94,7 +93,7 @@ class DatabaseStructureController extends DatabaseController
{
// Add/Remove favorite tables using Ajax request.
if ($GLOBALS['is_ajax_request'] && !empty($_REQUEST['favorite_table'])) {
$this->addRemoveFavoriteTables();
$this->addRemoveFavoriteTablesAction();
return;
}
@ -281,7 +280,7 @@ class DatabaseStructureController extends DatabaseController
$showtable = $this->dbi->getTable(
$this->db, $current_table['TABLE_NAME']
)->sGetStatusInfo(null, true);
)->getStatusInfo(null, true);
if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
$create_time = isset($showtable['Create_time'])
@ -684,7 +683,7 @@ class DatabaseStructureController extends DatabaseController
*
* @return void
*/
protected function addRemoveFavoriteTables()
public function addRemoveFavoriteTablesAction()
{
$fav_instance = PMA_RecentFavoriteTable::getInstance('favorite');
if (isset($_REQUEST['favorite_tables'])) {
@ -820,7 +819,7 @@ class DatabaseStructureController extends DatabaseController
}
$favorite_tables[$user] = $fav_instance->getTables();
$$this->response->addJSON(
$this->response->addJSON(
array(
'favorite_tables' => json_encode($favorite_tables),
'list' => $fav_instance->getHtmlList()
@ -853,8 +852,8 @@ class DatabaseStructureController extends DatabaseController
/**
* Find table with truename
*
* @param array $db DB to look into
* @param bool $truename Table name
* @param array $db DB to look into
* @param string $truename Table name
*
* @return bool
*/

View File

@ -15,7 +15,6 @@ use PMA_Message;
use PMA\Template;
use PMA\Controllers\TableController;
require_once 'libraries/common.inc.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/Template.class.php';

View File

@ -16,7 +16,6 @@ use PMA_Response;
use PMA\Template;
use PMA_Util;
require_once 'libraries/common.inc.php';
require_once 'libraries/Index.class.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/Util.class.php';
@ -144,7 +143,7 @@ class TableIndexesController extends TableController
// If there is a request for SQL previewing.
if (isset($_REQUEST['preview_sql'])) {
PMA_Response::getInstance()->addJSON(
$this->response->addJSON(
'sql_data',
Template::get('preview_sql')
->render(
@ -161,11 +160,10 @@ class TableIndexesController extends TableController
__('Table %1$s has been altered successfully.')
);
$message->addParam($this->table);
$response = PMA_Response::getInstance();
$response->addJSON(
$this->response->addJSON(
'message', PMA_Util::getMessage($message, $sql_query, 'success')
);
$response->addJSON(
$this->response->addJSON(
'index_table',
PMA_Index::getHtmlForIndexes(
$this->table, $this->db
@ -175,9 +173,8 @@ class TableIndexesController extends TableController
include 'tbl_structure.php';
}
} else {
$response = PMA_Response::getInstance();
$response->isSuccess(false);
$response->addJSON('message', $error);
$this->response->isSuccess(false);
$this->response->addJSON('message', $error);
}
}
}

View File

@ -8,7 +8,6 @@
namespace PMA\Controllers\Table;
require_once 'libraries/common.inc.php';
require_once 'libraries/DatabaseInterface.class.php';
require_once 'libraries/controllers/TableController.class.php';
require_once 'libraries/index.lib.php';
@ -157,7 +156,8 @@ class TableRelationController extends TableController
// display secondary level tabs if necessary
$engine = $this->dbi->getTable($this->db, $this->table)
->sGetStatusInfo('ENGINE');
->getStatusInfo('ENGINE');
$this->response->addHTML(
Template::get('table/secondary_tabs')->render(
array(
@ -301,7 +301,7 @@ class TableRelationController extends TableController
public function getDropdownValueForTableAction()
{
$foreignTable = $_REQUEST['foreignTable'];
$table_obj = new PMA_Table($foreignTable, $_REQUEST['foreignDb']);
$table_obj = $this->dbi->getTable($_REQUEST['foreignDb'], $foreignTable);
// Since views do not have keys defined on them provide the full list of
// columns
if ($table_obj->isView()) {
@ -369,7 +369,7 @@ class TableRelationController extends TableController
$GLOBALS['dbi']->getTable(
$_REQUEST['foreignDb'],
$row[0]
)->sGetStatusInfo('Engine')
)->getStatusInfo('Engine')
);
if (isset($engine) && $engine == $this->tbl_storage_engine) {
$tables[] = htmlspecialchars($row[0]);

View File

@ -13,8 +13,6 @@ use PMA\Controllers\TableController;
use PMA_DatabaseInterface;
use PMA_Util;
require_once 'libraries/common.inc.php';
require_once 'libraries/tbl_info.inc.php';
require_once 'libraries/Template.class.php';
require_once 'libraries/mysql_charsets.inc.php';
require_once 'libraries/sql.lib.php';
@ -173,6 +171,10 @@ class TableSearchController extends TableController
*/
public function indexAction()
{
$_REQUEST['db'] = 'TEST';
$_REQUEST['table'] = 'fuck2';
$_REQUEST['where_clause'] = '`c` = 2';
$this->getDataRowAction();
switch ($this->_searchType) {
case 'replace':
if (isset($_POST['find'])) {

View File

@ -19,8 +19,6 @@ use PMA_Util;
use PMA\Util;
use SqlParser;
require_once 'libraries/common.inc.php';
require_once 'libraries/tbl_info.inc.php';
require_once 'libraries/Index.class.php';
require_once 'libraries/Partition.class.php';
require_once 'libraries/mysql_charsets.inc.php';
@ -103,7 +101,7 @@ class TableStructureController extends TableController
$this->_table_info_num_rows = $table_info_num_rows;
$this->_tbl_collation = $tbl_collation;
$this->_showtable = $showtable;
$this->table_obj = new PMA_Table($this->table, $this->db);
$this->table_obj = $this->dbi->getTable($this->db, $this->table);
}
/**
@ -245,7 +243,7 @@ class TableStructureController extends TableController
}
// display secondary level tabs if necessary
$engine = $this->table_obj->sGetStatusInfo('ENGINE');
$engine = $this->table_obj->getStatusInfo('ENGINE');
$this->response->addHTML(
Template::get('table/secondary_tabs')->render(
array(
@ -725,7 +723,7 @@ class TableStructureController extends TableController
if ($result !== false) {
$changed_privileges = $this->adjustColumnPrivileges(
$this->db, $this->table, $adjust_privileges
$adjust_privileges
);
if ($changed_privileges) {
@ -1063,7 +1061,7 @@ class TableStructureController extends TableController
if (empty($this->_showtable)) {
$this->_showtable = $this->dbi->getTable(
$this->db, $this->table
)->sGetStatusInfo(null, true);
)->getStatusInfo(null, true);
}
if (empty($this->_showtable['Data_length'])) {

View File

@ -11,6 +11,8 @@ if (! defined('PHPMYADMIN')) {
exit;
}
require_once 'libraries/Partition.class.php';
/**
* Get HTML output for database comment
*

View File

@ -926,7 +926,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema
/**
* Gets table information
*/
$showtable = $GLOBALS['dbi']->getTable($this->db, $table)->sGetStatusInfo();
$showtable = $GLOBALS['dbi']->getTable($this->db, $table)->getStatusInfo();
$show_comment = isset($showtable['Comment'])
? $showtable['Comment']
: '';

View File

@ -38,14 +38,14 @@ $GLOBALS['dbi']->selectDb($GLOBALS['db']);
*/
$GLOBALS['showtable'] = array();
// PMA_Table::sGetStatusInfo() does caching by default, but here
// PMA_Table::getStatusInfo() does caching by default, but here
// we force reading of the current table status
// if $reread_info is true (for example, coming from tbl_operations.php
// and we just changed the table's storage engine)
$GLOBALS['showtable'] = $GLOBALS['dbi']->getTable(
$GLOBALS['db'],
$GLOBALS['table']
)->sGetStatusInfo(
)->getStatusInfo(
null,
(isset($reread_info) && $reread_info ? true : false)
);

View File

@ -8,7 +8,11 @@
namespace PMA;
use PMA_Response;
require_once 'libraries/common.inc.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/Response.class.php';
require_once 'libraries/controllers/TableChartController.class.php';
$container = DI\Container::getDefaultContainer();
@ -16,6 +20,8 @@ $container->factory('PMA\Controllers\Table\TableChartController');
$container->alias(
'TableChartController', 'PMA\Controllers\Table\TableChartController'
);
$container->set('PMA_Response', PMA_Response::getInstance());
$container->alias('response', 'PMA_Response');
/* Define dependencies for the concerned controller */
$dependency_definitions = array(

View File

@ -13,7 +13,9 @@
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/tbl_common.inc.php';
require_once 'libraries/tbl_info.inc.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/Response.class.php';
require_once 'libraries/controllers/TableSearchController.class.php';
use PMA\DI;
@ -23,6 +25,8 @@ $container->factory('PMA\Controllers\Table\TableSearchController');
$container->alias(
'TableSearchController', 'PMA\Controllers\Table\TableSearchController'
);
$container->set('PMA_Response', PMA_Response::getInstance());
$container->alias('response', 'PMA_Response');
$dependency_definitions = array(
'searchType' => 'replace',

View File

@ -8,9 +8,11 @@
namespace PMA;
use PMA_Response;
use PMA_Util;
require_once 'libraries/di/Container.class.php';
require_once 'libraries/Response.class.php';
require_once 'libraries/controllers/TableGisVisualizationController.class.php';
require_once 'libraries/Util.class.php';
@ -20,6 +22,8 @@ $container->alias(
'TableGisVisualizationController',
'PMA\Controllers\Table\TableGisVisualizationController'
);
$container->set('PMA_Response', PMA_Response::getInstance());
$container->alias('response', 'PMA_Response');
/* Define dependencies for the concerned controller */
$dependency_definitions = array(

View File

@ -9,9 +9,12 @@
namespace PMA;
use PMA_Index;
use PMA_Response;
require_once 'libraries/common.inc.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/controllers/TableIndexesController.class.php';
require_once 'libraries/Response.class.php';
require_once 'libraries/Index.class.php';
$container = DI\Container::getDefaultContainer();
@ -19,6 +22,8 @@ $container->factory('PMA\Controllers\Table\TableIndexesController');
$container->alias(
'TableIndexesController', 'PMA\Controllers\Table\TableIndexesController'
);
$container->set('PMA_Response', PMA_Response::getInstance());
$container->alias('response', 'PMA_Response');
/* Define dependencies for the concerned controller */
$db = $container->get('db');

View File

@ -19,11 +19,14 @@
*/
namespace PMA;
use PMA_Response;
use PMA_Table;
use PMA_Util;
require_once 'libraries/common.inc.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/controllers/TableRelationController.class.php';
require_once 'libraries/Response.class.php';
require_once 'libraries/Table.class.php';
require_once 'libraries/Util.class.php';
@ -32,6 +35,8 @@ $container->factory('PMA\Controllers\Table\TableRelationController');
$container->alias(
'TableRelationController', 'PMA\Controllers\Table\TableRelationController'
);
$container->set('PMA_Response', PMA_Response::getInstance());
$container->alias('response', 'PMA_Response');
/* Define dependencies for the concerned controller */
$db = $container->get('db');
@ -46,7 +51,7 @@ $options_array = array(
$cfgRelation = PMA_getRelationsParam();
$tbl_storage_engine = /*overload*/
mb_strtoupper(
$GLOBALS['dbi']->getTable($db, $table)->sGetStatusInfo('Engine')
$GLOBALS['dbi']->getTable($db, $table)->getStatusInfo('Engine')
);
$upd_query = new PMA_Table($table, $db, $dbi);

View File

@ -14,7 +14,9 @@
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/tbl_common.inc.php';
require_once 'libraries/tbl_info.inc.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/Response.class.php';
require_once 'libraries/controllers/TableSearchController.class.php';
use PMA\DI;
@ -24,6 +26,8 @@ $container->factory('PMA\Controllers\Table\TableSearchController');
$container->alias(
'TableSearchController', 'PMA\Controllers\Table\TableSearchController'
);
$container->set('PMA_Response', PMA_Response::getInstance());
$container->alias('response', 'PMA_Response');
/* Define dependencies for the concerned controller */
$dependency_definitions = array(

View File

@ -9,18 +9,24 @@
namespace PMA;
use PMA_Response;
require_once 'libraries/common.inc.php';
require_once 'libraries/tbl_info.inc.php';
require_once 'libraries/mysql_charsets.inc.php';
require_once 'libraries/config/page_settings.class.php';
require_once 'libraries/bookmark.lib.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/controllers/TableStructureController.class.php';
require_once 'libraries/Response.class.php';
$container = DI\Container::getDefaultContainer();
$container->factory('PMA\Controllers\TableStructureController');
$container->alias(
'TableStructureController', 'PMA\Controllers\TableStructureController'
);
$container->set('PMA_Response', PMA_Response::getInstance());
$container->alias('response', 'PMA_Response');
global $db, $table, $db_is_system_schema, $tbl_is_view, $tbl_storage_engine,
$table_info_num_rows, $tbl_collation, $showtable;

View File

@ -13,7 +13,9 @@
*/
require_once './libraries/common.inc.php';
require_once 'libraries/tbl_common.inc.php';
require_once 'libraries/tbl_info.inc.php';
require_once './libraries/di/Container.class.php';
require_once './libraries/Response.class.php';
require_once './libraries/controllers/TableSearchController.class.php';
use PMA\DI;
@ -23,6 +25,8 @@ $container->factory('PMA\Controllers\Table\TableSearchController');
$container->alias(
'TableSearchController', 'PMA\Controllers\Table\TableSearchController'
);
$container->set('PMA_Response', PMA_Response::getInstance());
$container->alias('response', 'PMA_Response');
/* Define dependencies for the concerned controller */
$dependency_definitions = array(

View File

@ -58,7 +58,7 @@ if ($foreign_db) {
$engine = $GLOBALS['dbi']->getTable(
$foreign_db,
$row[0]
)->sGetStatusInfo('Engine');
)->getStatusInfo('Engine');
if (isset($engine)
&& /*overload*/mb_strtoupper($engine) == $tbl_storage_engine
) {

View File

@ -1,164 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for libraries/TableSearch.class.php with search type replace
*
* @package PhpMyAdmin-test
*/
require_once 'libraries/Util.class.php';
/*
* Include to test.
*/
//require_once 'libraries/TableSearch.class.php';
require_once 'libraries/DatabaseInterface.class.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/url_generating.lib.php';
/**
* Tests for libraries/TableSearch.class.php with search type replace
*
* @package PhpMyAdmin-test
*/
class PMA_TableReplaceSearchTest extends PHPUnit_Framework_TestCase
{
/**
* @var PMA_TableSearch
*/
private $_object;
/**
* Sets up the environment for tests
*
* @return void
*/
protected function setup()
{
// @todo: Replace this test with TableSearchController test
/*$this->_object = $this->getMock(
'PMA_TableSearch',
array('_loadTableInfo'),
array(),
'',
false
);
$reflection = new \ReflectionClass('PMA_TableSearch');
// set database, table names
$attrDb = $reflection->getProperty('_db');
$attrDb->setAccessible(true);
$attrDb->setValue($this->_object, 'dbName');
$attrTable = $reflection->getProperty('_table');
$attrTable->setAccessible(true);
$attrTable->setValue($this->_object, 'tableName');
// set column names list
$attrColNames = $reflection->getProperty('_columnNames');
$attrColNames->setAccessible(true);
$columnNames = array('column1');
$attrColNames->setValue($this->_object, $columnNames);*/
}
/**
* Tests getReplacePreview() method
*
* @return void
* @group medium
*/
public function testGetReplacePreview()
{
// @todo: Replace this test with TableSearchController test
/*//mock DBI
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$find = 'findValue';
$replaceWith = 'replaceWithValue';
$useRegex = false;
$charSet = 'charSetValue';
// set expectations
$dbi->expects($this->once())
->method('fetchResult')
->will(
$this->returnValue(
array(
array('val1', 'replace1', 5),
array('va<2', 'replac<2', 1)
)
)
);
$GLOBALS['dbi'] = $dbi;
$ret = $this->_object->getReplacePreview(
0, $find, $replaceWith, $useRegex, $charSet
);
// assert whether hidden values are properly set
$this->assertContains(
'<input type="hidden" name="replace" value="true" />',
$ret
);
$this->assertContains(
'<input type="hidden" name="columnIndex" value="0" />',
$ret
);
$this->assertContains(
'<input type="hidden" name="findString"' . ' value="' . $find . '" />',
$ret
);
$this->assertContains(
'<input type="hidden" name="replaceWith"' . ' value="'
. $replaceWith . '" />',
$ret
);*/
// assert values displayed in the preview and escaping
/**
* @todo Find out a better method to test for HTML
*
* $this->assertContains(
* '<td class="right">5</td><td>val1</td><td>replace1</td>',
* $ret
* );
*
* $this->assertContains(
* '<td class="right">1</td><td>va&lt;2</td><td>replac&lt;2</td>',
* $ret
* );
*/
}
/**
* Tests replace() method
*
* @return void
*/
public function testReplace()
{
// @todo: Replace this test with TableSearchController test
/*//mock DBI
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$find = 'findValue';
$replaceWith = 'replaceWithValue';
$useRegex = false;
$charSet = 'charSetValue';
$expectedQuery = "UPDATE `dbName`.`tableName`"
. " SET `column1` = REPLACE(`column1`, '" . $find . "', '" . $replaceWith
. "') WHERE `column1` LIKE '%" . $find . "%' COLLATE "
. $charSet . "_bin";
// set expectations
$dbi->expects($this->once())
->method('query')
->with($expectedQuery);
$GLOBALS['dbi'] = $dbi;
$this->_object->replace(0, $find, $replaceWith, $useRegex, $charSet);*/
}
}

View File

@ -1,449 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for PMA_TableSearch
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/DatabaseInterface.class.php';
//require_once 'libraries/TableSearch.class.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/Tracker.class.php';
require_once 'libraries/Types.class.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
/**
* Tests for PMA_TableSearch
*
* @package PhpMyAdmin-test
*/
class PMA_TableSearch_Test extends PHPUnit_Framework_TestCase
{
/**
* Setup function for test cases
*
* @access protected
* @return void
*/
protected function setUp()
{
/**
* SET these to avoid undefined index error
*/
/*$_SESSION['PMA_Theme'] = new PMA_Theme();
$_POST['zoom_submit'] = 'zoom';
$GLOBALS['server'] = 1;
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
$GLOBALS['pmaThemeImage'] = 'themes/dot.gif';
$GLOBALS['is_ajax_request'] = false;
$GLOBALS['cfgRelation'] = PMA_getRelationsParam();
$GLOBALS['PMA_Types'] = new PMA_Types_MySQL();
$GLOBALS['cfg']['ServerDefault'] = 1;
$GLOBALS['cfg']['maxRowPlotLimit'] = 500;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['cfg']['ServerDefault'] = 1;
$GLOBALS['cfg']['ActionLinksMode'] = 'both';
$GLOBALS['cfg']['ForeignKeyMaxLimit'] = 100;
$GLOBALS['cfg']['InitialSlidersState'] = 'closed';
$GLOBALS['cfg']['MaxRows'] = 25;
$GLOBALS['cfg']['TabsMode'] = 'text';
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$columns =array(
array(
'Field' => 'Field1',
'Type' => 'Type1',
'Null' => 'Null1',
'Collation' => 'Collation1',
),
array(
'Field' => 'Field2',
'Type' => 'Type2',
'Null' => 'Null2',
'Collation' => 'Collation2',
)
);
$dbi->expects($this->any())->method('getColumns')
->will($this->returnValue($columns));
$show_create_table = "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`),
KEY `foreign_field` (`foreign_db`,`foreign_table`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin "
. "COMMENT='Bookmarks'";
$dbi->expects($this->any())->method('fetchValue')
->will($this->returnValue($show_create_table));
$GLOBALS['dbi'] = $dbi;*/
// @todo: Replace this test with TableSearchController test
}
/**
* tearDown function for test cases
*
* @access protected
* @return void
*/
protected function tearDown()
{
}
/**
* Test for __construct
*
* @return void
* @group medium
*/
public function testConstruct()
{
/*$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "normal");
$columNames = $tableSearch->getColumnNames();
$this->assertEquals(
'Field1',
$columNames[0]
);
$this->assertEquals(
'Field2',
$columNames[1]
);*/
// @todo: Replace this test with TableSearchController test
}
/**
* Test for getSelectionForm
*
* @return void
* @group medium
*/
public function testGetSelectionForm()
{
/*//$this->_searchType == 'zoom'
$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom");
$url_goto = "http://phpmyadmin.net";
$form = $tableSearch->getSelectionForm($url_goto);
$this->assertContains(
'<fieldset id="fieldset_zoom_search">',
$form
);
$this->assertContains(
'Do a "query by example"',
$form
);
//$this->_searchType == 'normal'
$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "normal");
$url_goto = "http://phpmyadmin.net";
$form = $tableSearch->getSelectionForm($url_goto);
$this->assertContains(
'<fieldset id="fieldset_table_search">',
$form
);
$this->assertContains(
'Do a "query by example"',
$form
);
//$this->_searchType == 'replace'
$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "replace");
$url_goto = "http://phpmyadmin.net";
$form = $tableSearch->getSelectionForm($url_goto);
$this->assertContains(
'<fieldset id="fieldset_find_replace">',
$form
);
$this->assertContains(
__('Find and replace'),
$form
);*/
// @todo: Replace this test with TableSearchController test
}
/**
* Test for getSecondaryTabs
*
* @return void
*/
public function testGetSecondaryTabs()
{
// @todo: Replace this test with TableSearchController test
/*$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom");
$html = $tableSearch->getSecondaryTabs();
$this->assertContains(
'<ul id="topmenu2">',
$html
);
//sub tabs
$this->assertContains(
__('Table search'),
$html
);
$this->assertContains(
__('Zoom search'),
$html
);
$this->assertContains(
__('Find and replace'),
$html
);*/
}
/**
* Test for getZoomResultsForm
*
* @return void
*/
public function testGetZoomResultsForm()
{
/*$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom");
$goto = "http://phpmyadmin.net";
$data = array("PMAA" => "abc");
$html = $tableSearch->getZoomResultsForm($goto, $data);
$this->assertContains(
'<legend>' . __('Browse/Edit the points') . '</legend>',
$html
);
$this->assertContains(
json_encode($data),
$html
);*/
// @todo: Replace this test with TableSearchController test
}
/**
* Test for replace
*
* @return void
*/
public function testReplace()
{
/*$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom");
$columnIndex = 0;
$find = "Field";
$replaceWith = "Column";
$useRegex = false;
$charSet = "UTF-8";
$tableSearch->replace(
$columnIndex, $find, $replaceWith, $useRegex, $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
);*/
// @todo: Replace this test with TableSearchController test
}
/**
* Test for _getSearchAndReplaceHTML
*
* @return void
*/
public function testGetSearchAndReplaceHTML()
{
/*$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom");
$html = $tableSearch->_getSearchAndReplaceHTML();
$this->assertContains(
__('Find:'),
$html
);
$this->assertContains(
__('Replace with:'),
$html
);*/
// @todo: Replace this test with TableSearchController test
}
/**
* Test for getReplacePreview
*
* @return void
*/
public function testGetReplacePreview()
{
/*$value = array(
'value',
'replace_value',
'count'
);
$dbi = $GLOBALS['dbi'];
$dbi->expects($this->once())
->method('fetchResult')
->will($this->returnValue(array($value)));
$GLOBALS['dbi'] = $dbi;
$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom");
$columnIndex = 0;
$find = "Field";
$replaceWith = "Column";
$useRegex = false;
$charSet = "UTF-8";
$html = $tableSearch->getReplacePreview(
$columnIndex,
$find,
$replaceWith,
$useRegex,
$charSet
);*/
/**
* @todo Find out a better method to test for HTML
*
* $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
);*/
}
/**
* Test for buildSqlQuery
*
* @return void
*/
public function testBuildSqlQueryw()
{
/*$_POST['distinct'] = true;
$_POST['zoom_submit'] = true;
$_POST['table'] = "PMA";
$_POST['orderByColumn'] = "name";
$_POST['order'] = "asc";
$_POST['customWhereClause'] = "name='pma'";
$tableSearch = new PMA_TableSearch("PMA", "PMA_BookMark", "zoom");
$sql = $tableSearch->buildSqlQuery();
$result = "SELECT DISTINCT * FROM `PMA` WHERE name='pma' "
. "ORDER BY `name` asc";
$this->assertEquals(
$result,
$sql
);
unset($_POST['customWhereClause']);
$sql = $tableSearch->buildSqlQuery();
$result = "SELECT DISTINCT * FROM `PMA` ORDER BY `name` asc";
$this->assertEquals(
$result,
$sql
);
$_POST['criteriaValues'] = array(
'value1',
'value2',
'value3',
'value4',
'value5',
'value6',
'value7,value8'
);
$_POST['criteriaColumnNames'] = array(
'name',
'id',
'index',
'index2',
'index3',
'index4',
'index5',
);
$_POST['criteriaColumnTypes'] = array(
'varchar',
'int',
'enum',
'type1',
'type2',
'type3',
'type4'
);
$_POST['criteriaColumnCollations'] = array(
"char1",
"char2",
"char3",
"char4",
"char5",
"char6",
"char7",
);
$_POST['criteriaColumnOperators'] = array(
"!=",
">",
"IS NULL",
"LIKE %...%",
"REGEXP ^...$",
"IN (...)",
"BETWEEN"
);
$sql = $tableSearch->buildSqlQuery();
$result = "SELECT DISTINCT * FROM `PMA` WHERE `name` != 'value1'"
. " AND `id` > value2 AND `index` IS NULL AND `index2` LIKE '%value4%'"
. " AND `index3` REGEXP ^value5$ AND `index4` IN (value6) AND `index5`"
. " BETWEEN value7 AND value8 ORDER BY `name` asc";
$this->assertEquals(
$result,
$sql
);*/
// @todo: Replace this test with TableSearchController test
}
}

View File

@ -592,13 +592,92 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase
}
/**
* Test for isMerge
* Test for isMerge -- when there's no ENGINE info cached
*
* @return void
*/
public function testIsMerge()
public function testIsMergeCase1()
{
$this->markTestIncomplete('Not yet implemented!');
$tableObj = new PMA_Table('PMA_BookMark', 'PMA');
$this->assertEquals(
'',
$tableObj->isMerge()
);
$GLOBALS['dbi']->expects($this->any())
->method('getCachedTableContent')
->will($this->returnValue(array('table_name' => "PMA_BookMark")));
$tableObj = new PMA_Table('PMA_BookMark', 'PMA');
$this->assertEquals(
false,
$tableObj->isMerge()
);
}
/**
* Test for isMerge -- when ENGINE info is MERGE
*
* @return void
*/
public function testIsMergeCase2()
{
$map = array(
array('PMA.PMA_BookMark', null, array('ENGINE' => "MERGE")),
array('PMA.PMA_BookMark.ENGINE', null, "MERGE")
);
$GLOBALS['dbi']->expects($this->any())
->method('getCachedTableContent')
->will($this->returnValueMap($map));
$tableObj = new PMA_Table('PMA_BookMark', 'PMA');
$this->assertEquals(
true,
$tableObj->isMerge()
);
}
/**
* Test for isMerge -- when ENGINE info is MRG_MYISAM
*
* @return void
*/
public function testIsMergeCase3()
{
$map = array(
array('PMA.PMA_BookMark', null, array('ENGINE' => "MRG_MYISAM")),
array('PMA.PMA_BookMark.ENGINE', null, "MRG_MYISAM")
);
$GLOBALS['dbi']->expects($this->any())
->method('getCachedTableContent')
->will($this->returnValueMap($map));
$tableObj = new PMA_Table('PMA_BookMark', 'PMA');
$this->assertEquals(
true,
$tableObj->isMerge()
);
}
/**
* Test for isMerge -- when ENGINE info is ISDB
*
* @return void
*/
public function testIsMergeCase4()
{
$map = array(
array('PMA.PMA_BookMark', null, array('ENGINE' => "ISDB")),
array('PMA.PMA_BookMark.ENGINE', null, "ISDB")
);
$GLOBALS['dbi']->expects($this->any())
->method('getCachedTableContent')
->will($this->returnValueMap($map));
$tableObj = new PMA_Table('PMA_BookMark', 'PMA');
$this->assertEquals(
false,
$tableObj->isMerge()
);
}
/**
@ -754,6 +833,96 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase
);
}
/**
* Test for getColumnsMeta
*
* @return void
*/
public function testGetColumnsMeta()
{
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('tryQuery')
->with("SELECT * FROM `db`.`table` LIMIT 1")
->will($this->returnValue('v1'));
$dbi->expects($this->once())
->method('getFieldsMeta')
->with("v1")
->will($this->returnValue('movecols'));
$GLOBALS['dbi'] = $dbi;
$tableObj = new PMA_Table('table', 'db');
$this->assertEquals(
$tableObj->getColumnsMeta(),
'movecols'
);
}
/**
* Tests for _getSQLToCreateForeignKey() method.
*
* @return void
* @test
*/
public function testGetSQLToCreateForeignKey()
{
$table = "PMA_table";
$field = array("PMA_field1", "PMA_field2");
$foreignDb = "foreignDb";
$foreignTable = "foreignTable";
$foreignField = array("foreignField1", "foreignField2");
$class = new ReflectionClass('PMA_Table');
$method = $class->getMethod('_getSQLToCreateForeignKey');
$method->setAccessible(true);
$tableObj = new PMA_Table('PMA_table', 'db');
$sql = $method->invokeArgs($tableObj, array(
$table,
$field,
$foreignDb,
$foreignTable,
$foreignField
)
);
$sql_excepted = 'ALTER TABLE `PMA_table` ADD '
. 'FOREIGN KEY (`PMA_field1`, `PMA_field2`) REFERENCES '
. '`foreignDb`.`foreignTable`(`foreignField1`, `foreignField2`);';
$this->assertEquals(
$sql_excepted,
$sql
);
}
/**
* Tests for getSqlQueryForIndexCreateOrEdit() method.
*
* @return void
* @test
*/
public function testGetSqlQueryForIndexCreateOrEdit()
{
$db = "pma_db";
$table = "pma_table";
$index = new PMA_Index();
$error = false;
$_REQUEST['old_index'] = "PRIMARY";
$table = new PMA_Table($table, $db);
$sql = $table->getSqlQueryForIndexCreateOrEdit($index, $error);
$this->assertEquals(
"ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY, ADD UNIQUE ;",
$sql
);
}
/**
* Test for getColumns
@ -799,7 +968,24 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase
*/
public function testCountRecords()
{
$this->markTestIncomplete('Not yet implemented!');
$map = array(
array('PMA.PMA_BookMark', null, array('Comment' => "Comment222", 'TABLE_TYPE' => "VIEW")),
array('PMA.PMA_BookMark.TABLE_TYPE', null, 'VIEW')
);
$GLOBALS['dbi']->expects($this->any())
->method('getCachedTableContent')
->will($this->returnValueMap($map));
$table = 'PMA_BookMark';
$db = 'PMA';
$tableObj = new PMA_Table($table, $db);
$return = $tableObj->countRecords(true);
$expect = 20;
$this->assertEquals(
$expect,
$return
);
}
/**

View File

@ -0,0 +1,420 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* DatabaseStructureController_Test class
*
* this class is for testing DatabaseStructureController class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
use PMA\Controllers\DatabaseStructureController;
use PMA\DI\Container;
require_once 'libraries/DatabaseInterface.class.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/Table.class.php';
require_once 'libraries/di/Container.class.php';
require_once 'test/libraries/stubs/ResponseStub.php';
require_once 'libraries/controllers/DatabaseStructureController.class.php';
/**
* DatabaseStructureController_Test class
*
* this class is for testing DatabaseStructureController class
*
* @package PhpMyAdmin-test
*/
class DatabaseStructureController_Test extends PHPUnit_Framework_TestCase
{
/**
* @var \PMA\Test\Stubs\PMA_Response
*/
private $response;
/**
* Prepares environment for the test.
*
* @return void
*/
public function setUp()
{
//$_REQUEST
$_REQUEST['log'] = "index1";
$_REQUEST['pos'] = 3;
//$GLOBALS
$GLOBALS['cfg']['MaxRows'] = 10;
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['ServerDefault'] = "server";
$GLOBALS['cfg']['RememberSorting'] = true;
$GLOBALS['cfg']['SQP'] = array();
$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000;
$GLOBALS['cfg']['ShowSQL'] = true;
$GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons';
$GLOBALS['cfg']['LimitChars'] = 100;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['table'] = "table";
$GLOBALS['pmaThemeImage'] = 'image';
//$_SESSION
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new PMA_Theme();
$table = $this->getMockBuilder('PMA_Table')
->disableOriginalConstructor()
->getMock();
// Expect the table will have 6 rows
$table->expects($this->any())->method('getRealRowCountTable')
->will($this->returnValue(6));
$table->expects($this->any())->method('countRecords')
->will($this->returnValue(6));
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->any())->method('getTable')
->will($this->returnValue($table));
$GLOBALS['dbi'] = $dbi;
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$container->set('dbi', $GLOBALS['dbi']);
$this->response = new \PMA\Test\Stubs\PMA_Response();
$container->set('PMA_Response', $this->response);
$container->alias('response', 'PMA_Response');
}
/**
* Tests for getValuesForInnodbTable()
*
* @return void
* @test
*/
public function testGetValuesForInnodbTable()
{
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$container->set('dbi', $GLOBALS['dbi']);
$response = new \PMA\Test\Stubs\PMA_Response();
$container->set('PMA_Response', $response);
$container->alias('response', 'PMA_Response');
$class = new ReflectionClass('PMA\Controllers\DatabaseStructureController');
$method = $class->getMethod('getValuesForInnodbTable');
$method->setAccessible(true);
// Showing statistics
$is_show_stats = true;
$ctrl = new DatabaseStructureController(null, null, null, null,
null, null, $is_show_stats);
$GLOBALS['cfg']['MaxExactCount'] = 10;
$current_table = array(
'ENGINE' => 'InnoDB',
'TABLE_ROWS' => 5,
'Data_length' => 16384,
'Index_length' => 0,
'TABLE_NAME' => 'table'
);
list($current_table, $formatted_size, $unit, $sum_size)
= $method->invokeArgs($ctrl, array($current_table, 10));
$this->assertEquals(
true,
$current_table['COUNTED']
);
$this->assertEquals(
6,
$current_table['TABLE_ROWS']
);
$this->assertEquals(
16394,
$sum_size
);
$current_table['ENGINE'] = 'MYISAM';
list($current_table, $formatted_size, $unit, $sum_size)
= $method->invokeArgs($ctrl, array($current_table, 10));
$this->assertEquals(
false,
$current_table['COUNTED']
);
$this->assertEquals(
16394,
$sum_size
);
// Not showing statistics
$is_show_stats = false;
$ctrl = new DatabaseStructureController(null, null, null, null,
null, null, $is_show_stats);
$current_table['ENGINE'] = 'InnoDB';
list($current_table, $formatted_size, $unit, $sum_size)
= $method->invokeArgs($ctrl, array($current_table, 10));
$this->assertEquals(
true,
$current_table['COUNTED']
);
$this->assertEquals(
10,
$sum_size
);
$current_table['ENGINE'] = 'MYISAM';
list($current_table, $formatted_size, $unit, $sum_size)
= $method->invokeArgs($ctrl, array($current_table, 10));
$this->assertEquals(
false,
$current_table['COUNTED']
);
$this->assertEquals(
10,
$sum_size
);
}
/**
* Tests for the getValuesForAriaTable()
*
* @return void
* @test
*/
public function testGetValuesForAriaTable()
{
$class = new ReflectionClass('PMA\Controllers\DatabaseStructureController');
$method = $class->getMethod('getValuesForAriaTable');
$method->setAccessible(true);
$db_is_system_schema = true;
$is_show_stats = true;
$ctrl = new DatabaseStructureController(null, null, null, $db_is_system_schema,
null, null, $is_show_stats);
$current_table = array(
'Data_length' => 16384,
'Index_length' => 0,
'Name' => 'table',
'Data_free' => 300
);
list($current_table, $formatted_size, $unit, $formatted_overhead,
$overhead_unit, $overhead_size, $sum_size
) = $method->invokeArgs($ctrl, array(
$current_table, 0, 0, 0, 0,
0, 0
));
$this->assertEquals(
6,
$current_table['Rows']
);
$this->assertEquals(
doubleval(16384),
$sum_size
);
$this->assertEquals(
300,
$overhead_size
);
unset($current_table['Data_free']);
list($current_table, $formatted_size, $unit, $formatted_overhead,
$overhead_unit, $overhead_size, $sum_size
) = $method->invokeArgs($ctrl, array(
$current_table, 0, 0, 0, 0,
0, 0
));
$this->assertEquals(
0,
$overhead_size
);
$is_show_stats = false;
$ctrl = new DatabaseStructureController(null, null, null, $db_is_system_schema,
null, null, $is_show_stats);
list($current_table, $formatted_size, $unit, $formatted_overhead,
$overhead_unit, $overhead_size, $sum_size
) = $method->invokeArgs($ctrl, array(
$current_table, 0, 0, 0, 0,
0, 0
));
$this->assertEquals(
0,
$sum_size
);
$db_is_system_schema = false;
$ctrl = new DatabaseStructureController(null, null, null, $db_is_system_schema,
null, null, $is_show_stats);
list($current_table, $formatted_size, $unit, $formatted_overhead,
$overhead_unit, $overhead_size, $sum_size
) = $method->invokeArgs($ctrl, array(
$current_table, 0, 0, 0, 0,
0, 0
));
$this->assertArrayNotHasKey(
'Row',
$current_table
);
}
/**
* Tests for hasTable()
*
* @return void
* @test
*/
public function testHasTable()
{
$class = new ReflectionClass('PMA\Controllers\DatabaseStructureController');
$method = $class->getMethod('hasTable');
$method->setAccessible(true);
$ctrl = new DatabaseStructureController(null, null, null, null,
null, null, null);
// When parameter $db is empty
$this->assertEquals(
false,
$method->invokeArgs($ctrl, array(array(), 'table'))
);
// Correct parameter
$tables = array(
'db.table'
);
$this->assertEquals(
true,
$method->invokeArgs($ctrl, array($tables, 'table'))
);
// Table not in database
$tables = array(
'db.tab1e'
);
$this->assertEquals(
false,
$method->invokeArgs($ctrl, array($tables, 'table'))
);
}
/**
* Tests for checkFavoriteTable()
*
* @return void
* @test
*/
public function testCheckFavoriteTable()
{
$class = new ReflectionClass('PMA\Controllers\DatabaseStructureController');
$method = $class->getMethod('checkFavoriteTable');
$method->setAccessible(true);
$ctrl = new DatabaseStructureController(null, null, null, null,
null, null, null);
$_SESSION['tmpval']['favorite_tables'][$GLOBALS['server']] = array(
array('db' => 'db', 'table' => 'table')
);
$this->assertEquals(
false,
$method->invokeArgs($ctrl, array(''))
);
$this->assertEquals(
true,
$method->invokeArgs($ctrl, array('table'))
);
}
/**
* Tests for synchronizeFavoriteTables()
*
* @return void
* @test
*/
public function testSynchronizeFavoriteTables()
{
$fav_instance = $this->getMockBuilder('PMA_RecentFavoriteTable')
->disableOriginalConstructor()
->getMock();
$fav_instance->expects($this->at(1))->method('getTables')
->will($this->returnValue(array()));
$fav_instance->expects($this->at(2))->method('getTables')
->will($this->returnValue(
array(
array('db' => 'db', 'table' => 'table')
)
));
$class = new ReflectionClass('PMA\Controllers\DatabaseStructureController');
$method = $class->getMethod('synchronizeFavoriteTables');
$method->setAccessible(true);
$ctrl = new DatabaseStructureController(null, null, null, null,
null, null, null);
// The user hash for test
$user = 'abcdefg';
$favorite_table[$user] = array(
array('db' => 'db', 'table' => 'table')
);
$method->invokeArgs($ctrl, array($fav_instance, $user, $favorite_table));
$json = $this->response->getJSONResult();
$this->assertEquals(json_encode($favorite_table), $json['favorite_tables']);
$this->assertArrayHasKey('list', $json);
}
/**
* Tests for handleRealRowCountRequestAction()
*
* @return void
* @test
*/
public function testHandleRealRowCountRequestAction()
{
$_REQUEST['table'] = 'table';
$ctrl = new DatabaseStructureController(null, null, null, null,
null, null, null);
$ctrl->handleRealRowCountRequestAction();
$json = $this->response->getJSONResult();
$this->assertEquals(
6,
$json['real_row_count']
);
// Fall into another branch
$_REQUEST['real_row_count_all'] = 'abc';
$GLOBALS['tables'] = array(
array(
'TABLE_NAME' => 'table'
)
);
$ctrl->handleRealRowCountRequestAction();
$json = $this->response->getJSONResult();
$expected_result = array(
array(
'table' => 'table',
'row_count' => 6
)
);
$this->assertEquals(
json_encode($expected_result),
$json['real_row_count_all']
);
}
}

View File

@ -0,0 +1,227 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for libraries/controllers/TableIndexesController.class.php
*
* @package PhpMyAdmin-test
*/
use PMA\Controllers\Table\TableIndexesController;
use PMA\DI\Container;
/*
* Include to test.
*/
require_once 'libraries/Template.class.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/Table.class.php';
require_once 'libraries/Index.class.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/sanitizing.lib.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/controllers/TableIndexesController.class.php';
require_once 'test/libraries/stubs/ResponseStub.php';
/**
* Tests for libraries/controllers/TableIndexesController.class.php
*
* @package PhpMyAdmin-test
*/
class PMA_TableIndexesControllerTest extends PHPUnit_Framework_TestCase
{
/**
* Setup function for test cases
*
* @access protected
* @return void
*/
protected function setUp()
{
/**
* SET these to avoid undefined index error
*/
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['Server']['pmadb'] = '';
$GLOBALS['pmaThemeImage'] = 'theme/';
$GLOBALS['cfg']['ServerDefault'] = "server";
$GLOBALS['cfg']['ShowHint'] = true;
$GLOBALS['url_params'] = array(
'db' => 'db',
'server' => 1
);
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$indexs = array(
array(
"Schema" => "Schema1",
"Key_name"=>"Key_name1",
"Column_name"=>"Column_name1"
),
array(
"Schema" => "Schema2",
"Key_name"=>"Key_name2",
"Column_name"=>"Column_name2"
),
array(
"Schema" => "Schema3",
"Key_name"=>"Key_name3",
"Column_name"=>"Column_name3"
),
);
$dbi->expects($this->any())->method('getTableIndexes')
->will($this->returnValue($indexs));
$GLOBALS['dbi'] = $dbi;
//$_SESSION
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new PMA_Theme();
}
/**
* Tests for doSaveDataAction() method
*
* @return void
* @test
*/
public function testDoSaveDataAction()
{
$sql_query = 'ALTER TABLE `db`.`table` DROP PRIMARY KEY, ADD UNIQUE ;';
$table = $this->getMockBuilder('PMA_Table')
->disableOriginalConstructor()
->getMock();
$table->expects($this->any())->method('getSqlQueryForIndexCreateOrEdit')
->will($this->returnValue($sql_query));
$GLOBALS['dbi']->expects($this->any())->method('getTable')
->will($this->returnValue($table));
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$container->set('dbi', $GLOBALS['dbi']);
$response = new \PMA\Test\Stubs\PMA_Response();
$container->set('PMA_Response', $response);
$container->alias('response', 'PMA_Response');
$ctrl = new TableIndexesController(null);
// Preview SQL
$_REQUEST['preview_sql'] = true;
$ctrl->doSaveDataAction();
$jsonArray = $response->getJSONResult();
$this->assertArrayHasKey('sql_data', $jsonArray);
$this->assertContains(
$sql_query,
$jsonArray['sql_data']
);
// Alter success
$response->clear();
unset($_REQUEST['preview_sql']);
$GLOBALS['is_ajax_request'] = true;
$ctrl->doSaveDataAction();
$jsonArray = $response->getJSONResult();
$this->assertArrayHasKey('index_table', $jsonArray);
$this->assertArrayHasKey('message', $jsonArray);
}
/**
* Tests for displayFormAction()
*
* @return void
* @test
*/
public function testDisplayFormAction()
{
$table = $this->getMockBuilder('PMA_Table')
->disableOriginalConstructor()
->getMock();
$table->expects($this->any())->method('getStatusInfo')
->will($this->returnValue(""));
$table->expects($this->any())->method('isView')
->will($this->returnValue(false));
$table->expects($this->any())->method('getNameAndTypeOfTheColumns')
->will($this->returnValue(array("field_name" => "field_type")));
$GLOBALS['dbi']->expects($this->any())->method('getTable')
->will($this->returnValue($table));
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$container->set('dbi', $GLOBALS['dbi']);
$response = new \PMA\Test\Stubs\PMA_Response();
$container->set('PMA_Response', $response);
$container->alias('response', 'PMA_Response');
$index = new PMA_Index();
$ctrl = new TableIndexesController($index);
$_REQUEST['create_index'] = true;
$_REQUEST['added_fields'] = 3;
$ctrl->displayFormAction();
$html = $response->getHTMLResult();
//PMA_URL_getHiddenInputs
$this->assertContains(
PMA_URL_getHiddenInputs(
array(
'db' => 'db',
'table' => 'table',
'create_index' => 1,
)
),
$html
);
$doc_html = PMA_Util::showHint(
PMA_Message::notice(
__(
'"PRIMARY" <b>must</b> be the name of'
. ' and <b>only of</b> a primary key!'
)
)
);
$this->assertContains(
$doc_html,
$html
);
$this->assertContains(
PMA_Util::showMySQLDocu('ALTER_TABLE'),
$html
);
// generateIndexSelector
$this->assertContains(
PMA\Template::trim($index->generateIndexChoiceSelector(false)),
$html
);
$this->assertContains(
sprintf(__('Add %s column(s) to index'), 1),
$html
);
//$field_name & $field_type
$this->assertContains(
"field_name",
$html
);
$this->assertContains(
"field_type",
$html
);
}
}

View File

@ -0,0 +1,336 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for libraries/controllers/TableRelationController.class.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
use PMA\DI\Container;
require_once 'libraries/Util.class.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/relation.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/di/Container.class.php';
require_once 'test/libraries/stubs/ResponseStub.php';
require_once 'libraries/controllers/TableRelationController.class.php';
/**
* Tests for libraries/controllers/TableRelationController.class.php
*
* @package PhpMyAdmin-test
*/
class TableRelationController_Test extends PHPUnit_Framework_TestCase
{
/**
* @var \PMA\Test\Stubs\PMA_Response
*/
private $response;
/**
* Configures environment
*
* @return void
*/
protected function setUp()
{
$GLOBALS['server'] = 0;
$GLOBALS['pmaThemeImage'] = 'theme/';
$GLOBALS['cfg']['ShowHint'] = true;
//$_SESSION
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new PMA_Theme();
$_REQUEST['foreignDb'] = 'db';
$_REQUEST['foreignTable'] = 'table';
$GLOBALS['pma'] = new DataBasePMAMockForTblRelation();
$GLOBALS['pma']->databases = new DataBaseMockForTblRelation();
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$container->set('dbi', $GLOBALS['dbi']);
$this->response = new \PMA\Test\Stubs\PMA_Response();
$container->set('PMA_Response', $this->response);
$container->alias('response', 'PMA_Response');
}
/**
* Tests for getDropdownValueForTableAction()
*
* Case one: this case is for the situation when the target
* table is a view.
*
* @return void
* @test
*/
public function testGetDropdownValueForTableActionIsView()
{
$viewColumns = array(
'viewCol', 'viewCol2', 'viewCol3'
);
$tableMock = $this->getMockBuilder('PMA_Table')
->disableOriginalConstructor()
->getMock();
// Test the situation when the table is a view
$tableMock->expects($this->any())->method('isView')
->will($this->returnValue(true));
$tableMock->expects($this->any())->method('getColumns')
->will($this->returnValue($viewColumns));
$GLOBALS['dbi']->expects($this->any())->method('getTable')
->will($this->returnValue($tableMock));
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PMA\Controllers\Table\TableRelationController');
$container->alias(
'TableRelationController', 'PMA\Controllers\Table\TableRelationController'
);
/**
* @var PMA\Controllers\Table\TableRelationController
*/
$ctrl = $container->get('TableRelationController');
$ctrl->getDropdownValueForTableAction();
$json = $this->response->getJSONResult();
$this->assertEquals(
$viewColumns,
$json['columns']
);
}
/**
* Tests for getDropdownValueForTableAction()
*
* Case one: this case is for the situation when the target
* table is not a view (real tabletable).
*
* @return void
* @test
*/
public function testGetDropdownValueForTableActionNotView()
{
$indexedColumns = array(
'primaryTableCol'
);
$tableMock = $this->getMockBuilder('PMA_Table')
->disableOriginalConstructor()
->getMock();
// Test the situation when the table is a view
$tableMock->expects($this->any())->method('isView')
->will($this->returnValue(false));
$tableMock->expects($this->any())->method('getIndexedColumns')
->will($this->returnValue($indexedColumns));
$GLOBALS['dbi']->expects($this->any())->method('getTable')
->will($this->returnValue($tableMock));
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PMA\Controllers\Table\TableRelationController');
$container->alias(
'TableRelationController', 'PMA\Controllers\Table\TableRelationController'
);
$ctrl = $container->get('TableRelationController');
$ctrl->getDropdownValueForTableAction();
$json = $this->response->getJSONResult();
$this->assertEquals(
$indexedColumns,
$json['columns']
);
}
/**
* Tests for getDropdownValueForDbAction()
*
* Case one: foreign and not Drizzle
*
* @return void
* @test
*/
public function testGetDropdownValueForDbActionOne()
{
$GLOBALS['dbi']->expects($this->any())->method('fetchArray')
->will($this->returnCallback(
function () {
static $count = 0;
if ($count == 0) {
$count++;
return array(
'Engine' => 'InnoDB',
'Name' => 'table'
);
} else {
return null;
}
}
));
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PMA\Controllers\Table\TableRelationController');
$container->alias(
'TableRelationController', 'PMA\Controllers\Table\TableRelationController'
);
$ctrl = $container->get('TableRelationController', array(
'tbl_storage_engine' => 'INNODB'
)
);
$_REQUEST['foreign'] = 'true';
$ctrl->getDropdownValueForDbAction();
$json = $this->response->getJSONResult();
$this->assertEquals(
array('table'),
$json['tables']
);
}
/**
* Tests for getDropdownValueForDbAction()
*
* Case two: not foreign and not Drizzle
*
* @return void
* @test
*/
public function testGetDropdownValueForDbActionTwo()
{
$GLOBALS['dbi']->expects($this->any())->method('fetchArray')
->will($this->returnCallback(
function () {
static $count = 0;
if ($count == 0) {
$count++;
return array('table');
} else {
return null;
}
}
));
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PMA\Controllers\Table\TableRelationController');
$container->alias(
'TableRelationController', 'PMA\Controllers\Table\TableRelationController'
);
$ctrl = $container->get('TableRelationController', array(
'tbl_storage_engine' => 'INNODB'
)
);
$_REQUEST['foreign'] = 'false';
$ctrl->getDropdownValueForDbAction();
$json = $this->response->getJSONResult();
$this->assertEquals(
array('table'),
$json['tables']
);
}
/**
* Tests for getDropdownValueForDbAction()
*
* Case three: foreign and Drizzle
*
* @return void
* @test
*/
public function testGetDropdownValueForDbActionThree()
{
if (! PMA_HAS_RUNKIT) {
$this->markTestSkipped("Cannot redefine PMA_DRIZZLE constant");
}
runkit_constant_redefine('PMA_DRIZZLE', true);
$tableMock = $this->getMockBuilder('PMA_Table')
->disableOriginalConstructor()
->getMock();
$statusInfo = 'InnoDB';
$tableMock->expects($this->any())->method('getStatusInfo')
->will($this->returnValue($statusInfo));
$GLOBALS['dbi']->expects($this->any())->method('getTable')
->will($this->returnValue($tableMock));
$GLOBALS['dbi']->expects($this->any())->method('fetchArray')
->will($this->returnCallback(
function () {
static $count = 0;
if ($count == 0) {
$count++;
return array('table');
} else {
return null;
}
}
));
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PMA\Controllers\Table\TableRelationController');
$container->alias(
'TableRelationController', 'PMA\Controllers\Table\TableRelationController'
);
$ctrl = $container->get('TableRelationController', array(
'tbl_storage_engine' => 'INNODB'
)
);
$_REQUEST['foreign'] = 'true';
$ctrl->getDropdownValueForDbAction();
$json = $this->response->getJSONResult();
$this->assertEquals(
array('table'),
$json['tables']
);
}
}
/**
* Mock class for DataBasePMAMock
*
* @package PhpMyAdmin-test
*/
Class DataBasePMAMockForTblRelation
{
var $databases;
}
/**
* Mock class for DataBaseMock
*
* @package PhpMyAdmin-test
*/
Class DataBaseMockForTblRelation
{
/**
* mock function to return table is existed
*
* @param string $name table name
*
* @return bool
*/
function exists($name)
{
return true;
}
}

View File

@ -0,0 +1,391 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for PMA_TableSearch
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
use PMA\Controllers\Table\TableSearchController;
use PMA\DI\Container;
require_once 'libraries/DatabaseInterface.class.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/Tracker.class.php';
require_once 'libraries/Types.class.php';
require_once 'test/libraries/stubs/ResponseStub.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/controllers/TableSearchController.class.php';
/**
* Tests for PMA_TableSearch
*
* @package PhpMyAdmin-test
*/
class PMA_TableSearchController_Test extends PHPUnit_Framework_TestCase
{
/**
* @var PMA\Test\Stubs\PMA_Response
*/
private $response;
/**
* Setup function for test cases
*
* @access protected
* @return void
*/
protected function setUp()
{
/**
* SET these to avoid undefined index error
*/
$_SESSION['PMA_Theme'] = new PMA_Theme();
$_POST['zoom_submit'] = 'zoom';
$GLOBALS['server'] = 1;
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
$GLOBALS['pmaThemeImage'] = 'themes/dot.gif';
$GLOBALS['is_ajax_request'] = false;
$GLOBALS['cfgRelation'] = PMA_getRelationsParam();
$GLOBALS['PMA_Types'] = new PMA_Types_MySQL();
$GLOBALS['cfg']['ServerDefault'] = 1;
$GLOBALS['cfg']['maxRowPlotLimit'] = 500;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['cfg']['ServerDefault'] = 1;
$GLOBALS['cfg']['ActionLinksMode'] = 'both';
$GLOBALS['cfg']['ForeignKeyMaxLimit'] = 100;
$GLOBALS['cfg']['InitialSlidersState'] = 'closed';
$GLOBALS['cfg']['MaxRows'] = 25;
$GLOBALS['cfg']['TabsMode'] = 'text';
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$columns =array(
array(
'Field' => 'Field1',
'Type' => 'Type1',
'Null' => 'Null1',
'Collation' => 'Collation1',
),
array(
'Field' => 'Field2',
'Type' => 'Type2',
'Null' => 'Null2',
'Collation' => 'Collation2',
)
);
$dbi->expects($this->any())->method('getColumns')
->will($this->returnValue($columns));
$show_create_table = "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`),
KEY `foreign_field` (`foreign_db`,`foreign_table`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin "
. "COMMENT='Bookmarks'";
$dbi->expects($this->any())->method('fetchValue')
->will($this->returnValue($show_create_table));
$GLOBALS['dbi'] = $dbi;
$this->response = new PMA\Test\Stubs\PMA_Response();
$container = Container::getDefaultContainer();
$container->set('db', 'PMA');
$container->set('table', 'PMA_BookMark');
$container->set('dbi', $GLOBALS['dbi']);
$container->set('response', $this->response);
$container->set('searchType', 'replace');
}
/**
* tearDown function for test cases
*
* @access protected
* @return void
*/
protected function tearDown()
{
}
/**
* Test for replace
*
* @return void
*/
public function testReplace()
{
$tableSearch = new TableSearchController("zoom", null);
$columnIndex = 0;
$find = "Field";
$replaceWith = "Column";
$useRegex = false;
$charSet = "UTF-8";
$tableSearch->replace(
$columnIndex, $find, $replaceWith, $useRegex, $charSet
);
$sql_query = $GLOBALS['sql_query'];
$result = "UPDATE `PMA_BookMark` SET `Field1` = "
. "REPLACE(`Field1`, 'Field', 'Column') "
. "WHERE `Field1` LIKE '%Field%' COLLATE UTF-8_bin";
$this->assertEquals(
$result,
$sql_query
);
}
/**
* Test for buildSqlQuery
*
* @return void
*/
public function testBuildSqlQuery()
{
$_POST['distinct'] = true;
$_POST['zoom_submit'] = true;
$_POST['table'] = "PMA";
$_POST['orderByColumn'] = "name";
$_POST['order'] = "asc";
$_POST['customWhereClause'] = "name='pma'";
$class = new ReflectionClass('PMA\Controllers\Table\TableSearchController');
$method = $class->getMethod('_buildSqlQuery');
$method->setAccessible(true);
$tableSearch = new TableSearchController("zoom", null);
$sql = $method->invoke($tableSearch);
$result = "SELECT DISTINCT * FROM `PMA` WHERE name='pma' "
. "ORDER BY `name` asc";
$this->assertEquals(
$result,
$sql
);
unset($_POST['customWhereClause']);
$sql = $method->invoke($tableSearch);
$result = "SELECT DISTINCT * FROM `PMA` ORDER BY `name` asc";
$this->assertEquals(
$result,
$sql
);
$_POST['criteriaValues'] = array(
'value1',
'value2',
'value3',
'value4',
'value5',
'value6',
'value7,value8'
);
$_POST['criteriaColumnNames'] = array(
'name',
'id',
'index',
'index2',
'index3',
'index4',
'index5',
);
$_POST['criteriaColumnTypes'] = array(
'varchar',
'int',
'enum',
'type1',
'type2',
'type3',
'type4'
);
$_POST['criteriaColumnCollations'] = array(
"char1",
"char2",
"char3",
"char4",
"char5",
"char6",
"char7",
);
$_POST['criteriaColumnOperators'] = array(
"!=",
">",
"IS NULL",
"LIKE %...%",
"REGEXP ^...$",
"IN (...)",
"BETWEEN"
);
$sql = $method->invoke($tableSearch);
$result = "SELECT DISTINCT * FROM `PMA` WHERE `name` != 'value1'"
. " AND `id` > value2 AND `index` IS NULL AND `index2` LIKE '%value4%'"
. " AND `index3` REGEXP ^value5$ AND `index4` IN (value6) AND `index5`"
. " BETWEEN value7 AND value8 ORDER BY `name` asc";
$this->assertEquals(
$result,
$sql
);
}
/**
* Tests for getColumnMinMax()
*
* @return void
* @test
*/
public function testGetColumnMinMax()
{
$GLOBALS['dbi']->expects($this->any())->method('fetchSingleRow')
->will($this->returnArgument(0));
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PMA\Controllers\Table\TableSearchController');
$container->alias(
'TableSearchController', 'PMA\Controllers\Table\TableSearchController'
);
$ctrl = $container->get('TableSearchController');
$result = $ctrl->getColumnMinMax('column');
$expected = 'SELECT MIN(`column`) AS `min`, '
. 'MAX(`column`) AS `max` '
. 'FROM `PMA`.`PMA_BookMark`';
$this->assertEquals(
$expected,
$result
);
}
/**
* Tests for _generateWhereClause()
*
* @return void
* @test
*/
public function testGenerateWhereClause()
{
$types = $this->getMockBuilder('PMA_Types')
->disableOriginalConstructor()
->getMock();
$types->expects($this->any())->method('isUnaryOperator')
->will($this->returnValue(false));
$GLOBALS['PMA_Types'] = $types;
$class = new ReflectionClass('\PMA\Controllers\Table\TableSearchController');
$method = $class->getMethod('_generateWhereClause');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->factory('\PMA\Controllers\Table\TableSearchController');
$container->alias(
'TableSearchController', 'PMA\Controllers\Table\TableSearchController'
);
$ctrl = $container->get('TableSearchController');
$_POST['customWhereClause'] = '`table` = \'PMA_BookMark\'';
$result = $method->invoke($ctrl);
$this->assertEquals(
' WHERE `table` = \'PMA_BookMark\'',
$result
);
unset($_POST['customWhereClause']);
$this->assertEquals(
'',
$method->invoke($ctrl)
);
$_POST['criteriaColumnNames'] = array(
'b', 'a'
);
$_POST['criteriaColumnOperators'] = array(
'<=', '='
);
$_POST['criteriaValues'] = array(
'10', '2'
);
$_POST['criteriaColumnTypes'] = array(
'int(11)', 'int(11)'
);
$result = $method->invoke($ctrl);
$this->assertEquals(
' WHERE `b` <= 10 AND `a` = 2',
$result
);
}
/**
* Tests for getDataRowAction()
*
* @return void
* @test
*/
public function testGetDataRowAction()
{
$meta_one = new stdClass();
$meta_one->type = 'int';
$meta_one->length = 11;
$meta_two = new stdClass();
$meta_two->length = 11;
$meta_two->type = 'int';
$fields_meta = array(
$meta_one, $meta_two
);
$GLOBALS['dbi']->expects($this->any())->method('getFieldsMeta')
->will($this->returnValue($fields_meta));
$GLOBALS['dbi']->expects($this->any())->method('fetchAssoc')
->will($this->returnCallback(
function () {
static $count = 0;
if ($count == 0) {
$count++;
return array(
'col1' => 1,
'col2' => 2
);
} else {
return null;
}
}
));
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('\PMA\Controllers\Table\TableSearchController');
$container->alias(
'TableSearchController', 'PMA\Controllers\Table\TableSearchController'
);
$ctrl = $container->get('TableSearchController');
$_REQUEST['db'] = 'PMA';
$_REQUEST['table'] = 'PMA_BookMark';
$_REQUEST['where_clause'] = '`col1` = 1';
$expected = array(
'col1' => 1,
'col2' => 2
);
$ctrl->getDataRowAction();
$json = $this->response->getJSONResult();
$this->assertEquals(
$expected,
$json['row_info']
);
}
}

View File

@ -0,0 +1,393 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* TableStructureController_Test class
*
* this class is for testing TableStructureController class
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
use PMA\DI\Container;
require_once 'libraries/DatabaseInterface.class.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/Table.class.php';
require_once 'libraries/di/Container.class.php';
require_once 'test/libraries/stubs/ResponseStub.php';
require_once 'libraries/controllers/TableStructureController.class.php';
/**
* TableStructureController_Test class
*
* this class is for testing TableStructureController class
*
* @package PhpMyAdmin-test
*/
class TableStructureController_Test extends PHPUnit_Framework_TestCase
{
/**
* @var \PMA\Test\Stubs\PMA_Response
*/
private $response;
/**
* Prepares environment for the test.
*
* @return void
*/
public function setUp()
{
//$_REQUEST
$_REQUEST['log'] = "index1";
$_REQUEST['pos'] = 3;
//$GLOBALS
$GLOBALS['cfg']['MaxRows'] = 10;
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['ServerDefault'] = "server";
$GLOBALS['cfg']['RememberSorting'] = true;
$GLOBALS['cfg']['SQP'] = array();
$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000;
$GLOBALS['cfg']['ShowSQL'] = true;
$GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons';
$GLOBALS['cfg']['LimitChars'] = 100;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['table'] = "table";
$GLOBALS['pmaThemeImage'] = 'image';
//$_SESSION
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new PMA_Theme();
$table = $this->getMockBuilder('PMA_Table')
->disableOriginalConstructor()
->getMock();
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->any())->method('getTable')
->will($this->returnValue($table));
$GLOBALS['dbi'] = $dbi;
$container = Container::getDefaultContainer();
$container->set('db', 'db');
$container->set('table', 'table');
$container->set('dbi', $GLOBALS['dbi']);
$this->response = new \PMA\Test\Stubs\PMA_Response();
$container->set('PMA_Response', $this->response);
$container->alias('response', 'PMA_Response');
}
/**
* Tests for getKeyForTablePrimary()
*
* Case one: there are no primary key in the table
*
* @return void
* @test
*/
public function testGetKeyForTablePrimaryOne()
{
$GLOBALS['dbi']->expects($this->any())->method('fetchAssoc')
->will($this->returnValue(null));
$class = new ReflectionClass('\PMA\Controllers\TableStructureController');
$method = $class->getMethod('getKeyForTablePrimary');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PMA\Controllers\TableStructureController');
$container->alias(
'TableStructureController', 'PMA\Controllers\TableStructureController'
);
$ctrl = $container->get('TableStructureController');
// No primary key in db.table2
$this->assertEquals(
'',
$method->invoke($ctrl)
);
}
/**
* Tests for getKeyForTablePrimary()
*
* Case two: there are a primary key in the table
*
* @return void
* @test
*/
public function testGetKeyForTablePrimaryTwo()
{
$GLOBALS['dbi']->expects($this->any())->method('fetchAssoc')
->will($this->returnCallback(
function () {
static $callCount = 0;
if ($callCount == 0) {
$callCount++;
return array(
'Key_name' => 'PRIMARY',
'Column_name' => 'column'
);
} else {
return null;
}
}
));
$class = new ReflectionClass('\PMA\Controllers\TableStructureController');
$method = $class->getMethod('getKeyForTablePrimary');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PMA\Controllers\TableStructureController');
$container->alias(
'TableStructureController', 'PMA\Controllers\TableStructureController'
);
$ctrl = $container->get('TableStructureController');
// With db.table, it has a primary key `column`
$this->assertEquals(
'column, ',
$method->invoke($ctrl)
);
}
/**
* Tests for adjustColumnPrivileges()
*
* @return void
* @test
*/
public function testAdjustColumnPrivileges()
{
$class = new ReflectionClass('\PMA\Controllers\TableStructureController');
$method = $class->getMethod('adjustColumnPrivileges');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PMA\Controllers\TableStructureController');
$container->alias(
'TableStructureController', 'PMA\Controllers\TableStructureController'
);
$ctrl = $container->get('TableStructureController');
$this->assertEquals(
false,
$method->invokeArgs($ctrl, array(null))
);
}
/**
* Tests for adjustColumnPrivileges()
* For the Drizzle environment
*
* @return void
* @test
*/
public function testAdjustColumnPrivilegesDrizzle()
{
if (! PMA_HAS_RUNKIT) {
$this->markTestSkipped("Cannot redefine PMA_DRIZZLE constant");
}
$class = new ReflectionClass('\PMA\Controllers\TableStructureController');
$method = $class->getMethod('adjustColumnPrivileges');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PMA\Controllers\TableStructureController');
$container->alias(
'TableStructureController', 'PMA\Controllers\TableStructureController'
);
$ctrl = $container->get('TableStructureController');
$this->assertEquals(
false,
$method->invokeArgs($ctrl, array(null))
);
runkit_constant_redefine('PMA_DRIZZLE', false);
$adjust_privileges = array(
'col1' => 'col2'
);
$GLOBALS['col_priv'] = true;
$GLOBALS['flush_priv'] = true;
$this->assertEquals(
true,
$method->invokeArgs($ctrl, array($adjust_privileges))
);
}
/**
* Tests for getMultipleFieldCommandType()
*
* @return void
* @test
*/
public function testGetMultipleFieldCommandType()
{
$class = new ReflectionClass('\PMA\Controllers\TableStructureController');
$method = $class->getMethod('getMultipleFieldCommandType');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->set('dbi', $GLOBALS['dbi']);
$container->factory('PMA\Controllers\TableStructureController');
$container->alias(
'TableStructureController', 'PMA\Controllers\TableStructureController'
);
$ctrl = $container->get('TableStructureController');
$this->assertEquals(
null,
$method->invoke($ctrl)
);
$_REQUEST['submit_mult_drop_x'] = true;
$this->assertEquals(
'drop',
$method->invoke($ctrl)
);
unset($_REQUEST['submit_mult_drop_x']);
$_REQUEST['submit_mult'] = 'create';
$this->assertEquals(
'create',
$method->invoke($ctrl)
);
unset($_REQUEST['submit_mult']);
$_REQUEST['mult_btn'] = __('Yes');
$this->assertEquals(
'row_delete',
$method->invoke($ctrl)
);
$_REQUEST['selected'] = array('a', 'b');
$method->invoke($ctrl);
$this->assertEquals(
$_REQUEST['selected'],
$_REQUEST['selected_fld']
);
}
/**
* Test for getDataForSubmitMult()
*
* @return void
* @test
*/
public function testPMAGetDataForSubmitMult()
{
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->any())
->method('query')
->will($this->returnValue(true));
$class = new ReflectionClass('PMA\Controllers\TableStructureController');
$method = $class->getMethod('getDataForSubmitMult');
$method->setAccessible(true);
$container = Container::getDefaultContainer();
$container->set('dbi', $dbi);
$container->factory('PMA\Controllers\TableStructureController');
$container->alias(
'TableStructureController', 'PMA\Controllers\TableStructureController'
);
$ctrl = $container->get('TableStructureController');
$submit_mult = "index";
$db = "PMA_db";
$table = "PMA_table";
$selected = array(
"table1", "table2"
);
$action = 'db_delete_row';
list(
$what, $query_type, $is_unset_submit_mult, $mult_btn, $centralColsError
)
= $method->invokeArgs($ctrl, array($submit_mult, $db, $table, $selected, $action));
//validate 1: $what
$this->assertEquals(
null,
$what
);
//validate 2: $query_type
$this->assertEquals(
'index_fld',
$query_type
);
//validate 3: $is_unset_submit_mult
$this->assertEquals(
true,
$is_unset_submit_mult
);
//validate 4:
$this->assertEquals(
__('Yes'),
$mult_btn
);
//validate 5: $centralColsError
$this->assertEquals(
null,
$centralColsError
);
$submit_mult = "unique";
list(
$what, $query_type, $is_unset_submit_mult, $mult_btn, $centralColsError
)
= $method->invokeArgs($ctrl, array($submit_mult, $db, $table, $selected, $action));
//validate 1: $what
$this->assertEquals(
null,
$what
);
//validate 2: $query_type
$this->assertEquals(
'unique_fld',
$query_type
);
//validate 3: $is_unset_submit_mult
$this->assertEquals(
true,
$is_unset_submit_mult
);
//validate 4: $mult_btn
$this->assertEquals(
__('Yes'),
$mult_btn
);
//validate 5: $centralColsError
$this->assertEquals(
null,
$centralColsError
);
}
}

View File

@ -496,16 +496,6 @@ class PMA_Central_Columns_Test extends PHPUnit_Framework_TestCase
);
}
/**
* Test for PMA_getHTMLforCentralColumnsTableRow
*
* @return void
*/
public function testPMAGetHTMLforCentralColumnsTableRow()
{
// @todo Find a better way to test page
}
/**
* Test for PMA_getCentralColumnsListRaw
*

View File

@ -333,100 +333,6 @@ class PMA_MultSubmits_Test extends PHPUnit_Framework_TestCase
);
}
/**
* Test for PMA_getDataForSubmitMult
*
* @return void
*/
public function testPMAGetDataForSubmitMult()
{
$this->markTestIncomplete('Not Implemented Yet!');
/* todo: now this test to be moved to new StructureController
$submit_mult = "index";
$db = "PMA_db";
$table = "PMA_table";
$selected = array(
"table1", "table2"
);
$action = 'db_delete_row';
list(
$what, $query_type, $is_unset_submit_mult, $mult_btn, $centralColsError
)
= PMA_getDataForSubmitMult(
$submit_mult, $db, $table, $selected, $action
);
//validate 1: $what
$this->assertEquals(
null,
$what
);
//validate 2: $query_type
$this->assertEquals(
'index_fld',
$query_type
);
//validate 3: $is_unset_submit_mult
$this->assertEquals(
true,
$is_unset_submit_mult
);
//validate 4:
$this->assertEquals(
__('Yes'),
$mult_btn
);
//validate 5: $centralColsError
$this->assertEquals(
null,
$centralColsError
);
$submit_mult = "unique";
list(
$what, $query_type, $is_unset_submit_mult, $mult_btn, $centralColsError
)
= PMA_getDataForSubmitMult(
$submit_mult, $db, $table, $selected, $action
);
//validate 1: $what
$this->assertEquals(
null,
$what
);
//validate 2: $query_type
$this->assertEquals(
'unique_fld',
$query_type
);
//validate 3: $is_unset_submit_mult
$this->assertEquals(
true,
$is_unset_submit_mult
);
//validate 4: $mult_btn
$this->assertEquals(
__('Yes'),
$mult_btn
);
//validate 5: $centralColsError
$this->assertEquals(
null,
$centralColsError
);*/
}
/**
* Test for PMA_getQueryFromSelected
*

View File

@ -1,279 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for structure.lib.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/Util.class.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/sanitizing.lib.php';
require_once 'libraries/js_escape.lib.php';
require_once 'libraries/Tracker.class.php';
require_once 'libraries/Table.class.php';
/**
* PMA_Structure_Test class
*
* this class is for testing structure.lib.php functions
*
* @package PhpMyAdmin-test
*/
class PMA_Structure_Test extends PHPUnit_Framework_TestCase
{
/**
* Prepares environment for the test.
*
* @return void
*/
public function setUp()
{
//$_REQUEST
$_REQUEST['log'] = "index1";
$_REQUEST['pos'] = 3;
//$GLOBALS
$GLOBALS['cfg']['MaxRows'] = 10;
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['ServerDefault'] = "server";
$GLOBALS['cfg']['RememberSorting'] = true;
$GLOBALS['cfg']['SQP'] = array();
$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000;
$GLOBALS['cfg']['ShowSQL'] = true;
$GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons';
$GLOBALS['cfg']['LimitChars'] = 100;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['table'] = "table";
$GLOBALS['pmaThemeImage'] = 'image';
//$_SESSION
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new PMA_Theme();
}
/**
* Test for PMA_getHtmlForActionLinks
*
* @return void
*/
public function testPMAGetHtmlForActionLinks()
{
$this->markTestIncomplete('Not Implemented Yet!');
/**
* $current_table = array(
* 'TABLE_ROWS' => 3,
* 'TABLE_NAME' => 'name1',
* 'TABLE_COMMENT' => 'This is a test comment'
* );
* $table_is_view = false;
* $tbl_url_query = 'tbl_url_query';
* $titles = array(
* 'Browse' => 'Browse1',
* 'NoBrowse' => 'NoBrowse1',
* 'Search' => 'Search1',
* 'NoSearch' => 'NoSearch1',
* 'Empty' => 'Empty1',
* 'NoEmpty' => 'NoEmpty1',
* );;
* $truename = 'truename';
* $db_is_system_schema = null;
* $url_query = 'url_query';
*
* //$table_is_view = true;
* list(
* $browse_table, $search_table,$browse_table_label,
* $empty_table, $tracking_icon
* ) = PMA_getHtmlForActionLinks(
* $current_table, $table_is_view, $tbl_url_query,
* $titles, $truename, $db_is_system_schema, $url_query
* );
*
* //$browse_table
* $this->assertContains(
* $titles['Browse'],
* $browse_table
* );
*
* //$search_table
* $this->assertContains(
* $titles['Search'],
* $search_table
* );
* $this->assertContains(
* $tbl_url_query,
* $search_table
* );
*
* //$browse_table_label
* $this->assertContains(
* $tbl_url_query,
* $browse_table_label
* );
*
* //$empty_table
* $this->assertContains(
* $tbl_url_query,
* $empty_table
* );
* $this->assertContains(
* urlencode(
* 'TRUNCATE ' . PMA_Util::backquote($current_table['TABLE_NAME'])
* ),
* $empty_table
* );
* $this->assertContains(
* $titles['Empty'],
* $empty_table
* );
*
* //$table_is_view = false;
* $current_table = array(
* 'TABLE_ROWS' => 0,
* 'TABLE_NAME' => 'name1',
* 'TABLE_COMMENT' => 'This is a test comment'
* );
* $table_is_view = false;
* list(
* $browse_table, $search_table,$browse_table_label,
* $empty_table, $tracking_icon
* ) = PMA_getHtmlForActionLinks(
* $current_table, $table_is_view, $tbl_url_query,
* $titles, $truename, $db_is_system_schema, $url_query
* );
*
* //$browse_table
* $this->assertContains(
* $titles['NoBrowse'],
* $browse_table
* );
*
* //$search_table
* $this->assertContains(
* $titles['NoSearch'],
* $search_table
* );
*
* //$browse_table_label
* $this->assertContains(
* $tbl_url_query,
* $browse_table_label
* );
* $this->assertContains(
* $titles['NoEmpty'],
* $empty_table
* );
*/
}
/**
* Test for PMA_getTableDropQueryAndMessage
*
* @return void
*/
public function testPMAGetTableDropQueryAndMessage()
{
$this->markTestIncomplete('Not Implemented Yet!');
/*
$current_table = array(
'TABLE_ROWS' => 3,
'TABLE_NAME' => 'name1',
'ENGINE' => 'ENGINE1',
);
$table_is_view = false;
list($drop_query, $drop_message) = PMA_getTableDropQueryAndMessage(
$table_is_view, $current_table
);
//$drop_query
$ret = "DROP TABLE `name1`";
$this->assertEquals(
$ret,
$drop_query
);
//$drop_message
$ret = "Table name1 has been dropped.";
$this->assertEquals(
$ret,
$drop_message
);
*/
}
/**
* Test for PMA_getHtmlShowCreate
*
* @return void
*/
public function testPMAGetHtmlShowCreate()
{
//@todo: Find out a better way to test front-end pages
$this->markTestIncomplete('Not Implemented Yet!');
/*mock DBI
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$db = 'PMA';
$table = 'PMA_Table';
$is_view_query = "SELECT TABLE_NAME
FROM information_schema.VIEWS
WHERE TABLE_SCHEMA = '" . PMA_Util::sqlAddSlashes($db) . "'
AND TABLE_NAME = '" . PMA_Util::sqlAddSlashes($table) . "'";
$show_create_query = 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.'
. PMA_Util::backquote($table);
$expected_result = 'CREATE TABLE `PMA_Table` ( '
. '`id` numeric '
. ') ENGINE=InnoDB DEFAULT CHARSET=latin1';
$dbi->expects($this->any())
->method('fetchResult')
->with($is_view_query)
->will($this->returnValue(false));
$dbi->expects($this->any())
->method('fetchValue')
->with($show_create_query, 0, 1)
->will(
$this->returnValue(
$expected_result
)
);
$GLOBALS['dbi'] = $dbi;
$output = PMA_getHtmlShowCreate($db, array($table));
$this->assertContains(
'Showing create queries',
$output
);
$this->assertContains(
'<legend>Tables</legend><table class="show_create">',
$output
);
$this->assertContains(
'<th>Create Table</th>',
$output
);
$this->assertContains(
PMA_mimeDefaultFunction($expected_result),
$output
);
*/
}
}

View File

@ -1,744 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for libraries/tbl_columns_definition_form.lib.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/Util.class.php';
require_once 'libraries/DatabaseInterface.class.php';
require_once 'libraries/Partition.class.php';
require_once 'libraries/Types.class.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/transformations.lib.php';
require_once 'libraries/mysql_charsets.inc.php';
require_once 'libraries/StorageEngine.class.php';
/**
* Tests for libraries/tbl_columns_definition_form.lib.php
*
* @package PhpMyAdmin-test
*/
class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
{
/**
* SetUp function for test cases
*
* @return void
*/
public function setUp()
{
/**
* $GLOBALS['cfg']['ServerDefault'] = 1;
* $GLOBALS['cfg']['DBG'] = null;
* $GLOBALS['pmaThemeImage'] = 'image';
*
* $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
* $_SESSION['PMA_Theme'] = new PMA_Theme();
*/
}
/**
* Test for PMA_getHeaderCells
*
* @return void
*/
public function testGetHeaderCells()
{
/**
* @todo Test against table_fields_definition.phtml
* $GLOBALS['cfg']['BrowseMIME'] = true;
* $GLOBALS['cfg']['ShowHint'] = false;
* $result = PMA_getHeaderCells(false, array(), true);
*
* $this->assertContains(
* 'Index',
* $result
* );
*
* $this->assertContains(
* 'Move column',
* $result
* );
*
* $this->assertContains(
* 'MIME type',
* $result
* );
*/
}
/**
* Test for PMA_getMoveColumns
*
* @return void
*/
public function testGetMoveColumns()
{
/**
* @todo Test against PMA_Table::getColumnsMeta
* $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
* ->disableOriginalConstructor()
* ->getMock();
*
* $dbi->expects($this->once())
* ->method('tryQuery')
* ->with("SELECT * FROM `db`.`table` LIMIT 1")
* ->will($this->returnValue('v1'));
*
* $dbi->expects($this->once())
* ->method('getFieldsMeta')
* ->with("v1")
* ->will($this->returnValue('movecols'));
*
* $GLOBALS['dbi'] = $dbi;
*
* $this->assertEquals(
* PMA_getMoveColumns('db', 'table'),
* 'movecols'
* );
*/
}
/**
* Test for PMA_getRowDataForRegeneration
*
* @return void
*/
public function testGetRowDataForRegeneration()
{
/** @todo Move test
$_REQUEST = array(
'field_name' => array(1 => 'name'),
'field_type' => array(1 => 'type'),
'field_collation' => array(1 => 'colltn'),
'field_null' => array(1 => true),
'field_key' => array(1 => "fulltext_1"),
'field_default_type' => array(1 => 'USER_DEFINED'),
'field_default_value' => array(1 => 'DEF'),
'field_extra' => array(1 => 'extra')
);
$submit_fulltext = array(1 => 1);
$result = PMA_getRowDataForRegeneration(1, $submit_fulltext);
$this->assertEquals(
array(
'Field' => 'name',
'Type' => 'type',
'Collation' => 'colltn',
'Null' => true,
'Key' => 'FULLTEXT',
'DefaultType' => 'USER_DEFINED',
'DefaultValue' => 'DEF',
'Default' => 'DEF',
'Extra' => 'extra',
'Comment' => 'FULLTEXT'
),
$result
);
*/
}
/**
* Test for PMA_getSubmitPropertiesForRegeneration
*
* @return void
*/
public function testGetSubmitPropertiesForRegeneration()
{
/** @todo Move test
$_REQUEST = array(
'field_length' => array(1 => 22),
'field_attribute' => array(1 => 'attr'),
'field_default_current_timestamp' => array()
);
$result = PMA_getSubmitPropertiesForRegeneration(1);
$this->assertEquals(
array(22, 'attr', false),
$result
);
*/
}
/**
* Test for PMA_getColumnMetaForDefault
*
* @return void
*/
public function testHandleRegeneration()
{
/** @todo Move test
$_REQUEST = array(
'field_comments' => array(1 => 'comm'),
'field_mimetype' => array(1 => 'mime'),
'field_transformation' => array(1 => 'trans'),
'field_transformation_options' => array(1 => 'transops')
);
$result = PMA_handleRegeneration(1, 'FULLTEXT', array(), array());
$this->assertEquals(
array('comm'),
$result[4]
);
$this->assertEquals(
array(
array(
'mimetype' => 'mime',
'transformation' => 'trans',
'transformation_options' => 'transops'
)
),
$result[5]
);
*/
}
/**
* Test for PMA_getColumnMetaForDefault
*
* @return void
*/
public function testGetColumnMetaForDefault()
{
// @todo Move test
// $cmeta = array(
// 'Default' => null,
// 'Null' => 'YES',
// 'DefaultType' => 'a',
// 'DefaultValue' => 'b',
// );
// $result = PMA_getColumnMetaForDefault($cmeta, null);
// $this->assertEquals(
// 'NULL',
// $result['DefaultType']
// );
// $this->assertEquals(
// '',
// $result['DefaultValue']
// );
// // case 2
// $cmeta = array(
// 'Default' => null,
// 'Null' => 'NO',
// 'DefaultType' => 'a',
// 'DefaultValue' => 'b',
// );
// $result = PMA_getColumnMetaForDefault($cmeta, true);
// $this->assertEquals(
// 'USER_DEFINED',
// $result['DefaultType']
// );
// $this->assertEquals(
// null,
// $result['DefaultValue']
// );
// // case 3
// $cmeta = array(
// 'Default' => null,
// 'Null' => 'NO',
// 'DefaultType' => 'a',
// 'DefaultValue' => 'b',
// );
// $result = PMA_getColumnMetaForDefault($cmeta, false);
// $this->assertEquals(
// 'NONE',
// $result['DefaultType']
// );
// $this->assertEquals(
// null,
// $result['DefaultValue']
// );
// // case 4
// $cmeta = array(
// 'Default' => 'CURRENT_TIMESTAMP',
// 'Null' => 'NO',
// 'DefaultType' => 'a',
// 'DefaultValue' => 'b',
// );
// $result = PMA_getColumnMetaForDefault($cmeta, false);
// $this->assertEquals(
// 'CURRENT_TIMESTAMP',
// $result['DefaultType']
// );
// $this->assertEquals(
// null,
// $result['DefaultValue']
// );
// // case 5
// $cmeta = array(
// 'Default' => 'SOMETHING_ELSE',
// 'Null' => 'NO',
// 'DefaultType' => 'a',
// 'DefaultValue' => 'b',
// );
// $result = PMA_getColumnMetaForDefault($cmeta, false);
// $this->assertEquals(
// 'USER_DEFINED',
// $result['DefaultType']
// );
// $this->assertEquals(
// 'SOMETHING_ELSE',
// $result['DefaultValue']
// );
}
/**
* Test for PMA_getHtmlForColumnName
*
* @return void
*/
public function testGetHtmlForColumnName()
{
/**
* @todo Create test for page
*/
}
/**
* Test for PMA_getHtmlForColumnType
*
* @return void
*/
public function testGetHtmlForColumnType()
{
/**
* @todo Find out a better method to test for HTML
*
* $GLOBALS['PMA_Types'] = new PMA_Types;
* $result = PMA_getHtmlForColumnType(
* 1, 4, 3, false, array('column_status' => array('isReferenced' => false,
* 'isForeignKey' => false, 'isEditable' => true))
* );
*
* $this->assertContains(
* '<select class="column_type" name="field_type[1]" id="field_1_1">',
* $result
* );
*
* $this->assertContains(
* '<option title="">INT</option>',
* $result
* );
*/
}
/**
* Test for PMA_getHtmlForTransformationOption
*
* @return void
*/
public function testGetHtmlForTransformationOption()
{
/**
* @todo Find out a better method to test for HTML
*
* $cmeta = array(
* 'Field' => 'fieldname'
* );
*
* $mime = array(
* 'fieldname' => array(
* 'transformation_options' => 'transops'
* )
* );
*
* $result = PMA_getHtmlForTransformationOption(
* 2, 4, 4, $cmeta, $mime, ''
* );
*
* $this->assertContains(
* '<input id="field_2_0" type="text" name="field_transformation_'
* . 'options[2]" size="16" class="textfield" value="transops" />',
* $result
* );
*/
$this->markTestIncomplete('Not yet implemented!');
}
/**
* Test for PMA_getHtmlForTransformation
*
* @return void
*/
public function testGetHtmlForTransformation()
{
/**
* @todo Find out a better method to test for HTML
*
* $cmeta = array(
* 'Field' => 'fieldname'
* );
*
* $mime = array(
* 'fieldname' => array(
* 'transformation' => 'Text_Plain_Preappend.class.php',
* 'transformation_options' => 'transops'
* )
* );
*
* $avail_mime = array(
* 'transformation' => array(
* 'foo' => 'text/plain: bar'
* ),
* 'transformation_file' => array(
* 'foo' => 'Text_Plain_Preappend.class.php'
* )
* );
* $result = PMA_getHtmlForTransformation(
* 2, 0, 0, $avail_mime, $cmeta, $mime, ''
* );
*
* $this->assertContains(
* '<select id="field_2_0" size="1" name="field_transformation[2]">',
* $result
* );
*
* $this->assertContains(
* 'selected ',
* $result
* );
*/
}
/**
* Test for PMA_getHtmlForMoveColumn
*
* @return void
*/
public function testGetHtmlForMoveColumn()
{
/**
* @todo Find out a better method to test for HTML
*
* $cmeta = array(
* 'Field' => 'fieldname'
* );
*
* $moveColumns = array();
*
* $temp = new stdClass;
* $temp->name = 'a';
* $moveColumns[] = $temp;
*
* $temp = new stdClass;
* $temp->name = 'fieldname';
* $moveColumns[] = $temp;
*
* $result = PMA_getHtmlForMoveColumn(
* 2, 0, 0, $moveColumns, $cmeta
* );
*
* $this->assertContains(
* '<select id="field_2_0" name="field_move_to[2]" size="1" width="5em">',
* $result
* );
*
* $this->assertContains(
* '<option value="" selected="selected">&nbsp;</option>',
* $result
* );
*/
/**
* @todo Find out a better method to test for HTML
*
* $this->assertContains(
* '<option value="a" disabled="disabled">after `a`</option>',
* $result
* );
*
* $this->assertContains(
* '<option value="fieldname" disabled="disabled">after `fieldname`</option>',
* $result
* );
*/
}
/**
* Test for PMA_getHtmlForColumnComment
*
* @return void
*/
public function testGetHtmlForColumnComment()
{
/**
* @todo Find out a better method to test for HTML
*
* $cmeta = array(
* 'Field' => 'fieldname'
* );
*
* $commentMeta = array(
* 'fieldname' => 'fieldnamecomment<'
* );
*
* $result = PMA_getHtmlForColumnComment(
* 2, 1, 0, $cmeta, $commentMeta
* );
*
* $this->assertContains(
* '<input id="field_2_1" type="text" name="field_comments[2]" '
* . 'size="12" maxlength="1024" value="fieldnamecomment&lt;" '
* . 'class="textfield" />',
* $result
* );
*/
$this->markTestIncomplete('Not yet implemented!');
}
/**
* Test for PMA_getHtmlForColumnAutoIncrement
*
* @return void
*/
public function testGetHtmlForColumnAutoIncrement()
{
/**
* @todo Find out a better method to test for HTML
*
* $cmeta = array(
* 'Extra' => 'auto_increment'
* );
*
* $result = PMA_getHtmlForColumnAutoIncrement(
* 2, 1, 0, $cmeta
* );
*
* $this->assertContains(
* '<input name="field_extra[2]" id="field_2_1" checked="checked" '
* . 'type="checkbox" value="AUTO_INCREMENT" />',
* $result
* );
*/
$this->markTestIncomplete('Not yet implemented!');
}
/**
* Test for PMA_getHtmlForColumnIndexes
*
* @return void
*/
public function testGetHtmlForColumnIndexes()
{
/**
* @todo Find out a better method to test for HTML
*
* $this->assertContains(
* '<select name="field_key[2]" id="field_2_1"',
* $result
* );
*
*
* $this->assertContains(
* '<option value="none_2">---</option>',
* $result
* );
*
* $this->assertContains(
* '<option value="primary_2" title="Primary">PRIMARY</option>',
* $result
* );
*
* $this->assertContains(
* '<option value="unique_2" title="Unique">UNIQUE</option>',
* $result
* );
*
* $this->assertContains(
* '<option value="index_2" title="Index">INDEX</option>',
* $result
* );
*/
}
/**
* Test for PMA_getHtmlForColumnNull
*
* @return void
*/
public function testGetHtmlForColumnNull()
{
/**
* @todo Find out a better method to test for HTML
*
* $cmeta = array(
* 'Null' => 'YES'
* );
*
* $result = PMA_getHtmlForColumnNull(
* 2, 3, 1, $cmeta
* );
*
* $this->assertContains(
* '<input name="field_null[2]" id="field_2_2" checked="checked" '
* . 'type="checkbox" value="NULL" class="allow_null"/>',
* $result
* );
*/
$this->markTestIncomplete('Not yet implemented!');
}
/**
* Test for PMA_getHtmlForColumnAttribute
*
* @return void
*/
public function testGetHtmlForColumnAttribute()
{
/**
* @todo Find out a better method to test for HTML
*
* $cmeta = array(
* 'Null' => 'YES',
* 'Extra' => 'on update CURRENT_TIMESTAMP',
* 'Field' => 'f'
* );
*
* $colspec = array('attribute' => 'attr');
*
* $analyzed_sql = array(
* array(
* 'create_table_fields' => array(
* 'f' => array(
* 'default_current_timestamp' => true,
* )
* )
* )
* );
*
* $types = $this->getMockBuilder('PMA_Types')
* ->disableOriginalConstructor()
* ->setMethods(array('getAttributes'))
* ->getMock();
*
* $types->expects($this->once())
* ->method('getAttributes')
* ->will(
* $this->returnValue(
* array('on update CURRENT_TIMESTAMP')
* )
* );
*
* $GLOBALS['PMA_Types'] = $types;
* $result = PMA_getHtmlForColumnAttribute(
* 2, 3, 1, $colspec, $cmeta, true, $analyzed_sql
* );
*
* $this->assertContains(
* '<select style="width: 7em;" name="field_attribute[2]" id="field_2_2">',
* $result
* );
*
* $this->assertContains(
* '<option value="on update CURRENT_TIMESTAMP">',
* $result
* );
*/
$this->markTestIncomplete('Not yet implemented!');
}
/**
* Test for PMA_getHtmlForColumnLength
*
* @return void
*/
public function testGetHtmlForColumnLength()
{
/**
* @todo Find out a better method to test for HTML
* Template: columns_definitions/column_length
*
* $this->assertContains(
* '<input id="field_2_2" type="text" name="field_length[2]" size="10" '
* . 'value="8" class="textfield" />',
* $result
* );
*
* $this->assertContains(
* '<p class="enum_notice" id="enum_notice_2_2">',
* $result
* );
*/
}
/**
* Test for PMA_getHtmlForColumnDefault
*
* @return void
*/
public function testGetHtmlForColumnDefault()
{
/**
* @todo Find out a better method to test for HTML
*
* $cmeta = array(
* 'Default' => 'YES',
* 'DefaultType' => 'NONE',
* 'DefaultValue' => '2222'
* );
*
* $result = PMA_getHtmlForColumnDefault(
* 2, 3, 1, 'TIMESTAMP', true, $cmeta
* );
*
* $this->assertContains(
* '<select name="field_default_type[2]" id="field_2_2" '
* . 'class="default_type">',
* $result
* );
*
* $this->assertContains(
* '<option value="NONE" selected="selected" >',
* $result
* );
*
* $this->assertContains(
* '<input type="text" name="field_default_value[2]" size="12" '
* . 'value="2222" class="textfield default_value" />',
* $result
* );
*/
$this->markTestIncomplete('Not yet implemented!');
}
/**
* Test for PMA_getFormParamsForOldColumn
*
* @return void
*/
public function testGetFormParamsForOldColumn()
{
// Function needs correction
$this->markTestIncomplete('Not yet implemented!');
}
}

View File

@ -1,195 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for libraries/tbl_indexes.lib.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/Template.class.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/Table.class.php';
require_once 'libraries/Index.class.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/sanitizing.lib.php';
/**
* Tests for libraries/tbl_indexes.lib.php
*
* @package PhpMyAdmin-test
*/
class PMA_TblIndexTest extends PHPUnit_Framework_TestCase
{
/**
* Setup function for test cases
*
* @access protected
* @return void
*/
protected function setUp()
{
/**
* SET these to avoid undefined index error
*/
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['Server']['pmadb'] = '';
$GLOBALS['pmaThemeImage'] = 'theme/';
$GLOBALS['cfg']['ServerDefault'] = "server";
$GLOBALS['cfg']['ShowHint'] = true;
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$indexs = array(
array(
"Schema" => "Schema1",
"Key_name"=>"Key_name1",
"Column_name"=>"Column_name1"
),
array(
"Schema" => "Schema2",
"Key_name"=>"Key_name2",
"Column_name"=>"Column_name2"
),
array(
"Schema" => "Schema3",
"Key_name"=>"Key_name3",
"Column_name"=>"Column_name3"
),
);
$dbi->expects($this->any())->method('getTableIndexes')
->will($this->returnValue($indexs));
$GLOBALS['dbi'] = $dbi;
//$_SESSION
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new PMA_Theme();
}
/**
* Tests for PMA_getSqlQueryForIndexCreateOrEdit() method.
*
* @return void
* @test
*/
public function testPMAGetSqlQueryForIndexCreateOrEdit()
{
$db = "pma_db";
$table = "pma_table";
$index = new PMA_Index();
$error = false;
$_REQUEST['old_index'] = "PRIMARY";
$table = new PMA_Table($table, $db);
$sql = $table->getSqlQueryForIndexCreateOrEdit($index, $error);
$this->assertEquals(
"ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY, ADD UNIQUE ;",
$sql
);
}
/**
* Tests for PMA_getHtmlForIndexForm() method.
*
* @return void
* @test
*/
public function testPMAGetHtmlForIndexForm()
{
/**
* @todo Find out a better method to test for HTML
*
* $fields = array("field_name" => "field_type");
* $index = new PMA_Index();
* $form_params = array(
* 'db' => 'db',
* 'table' => 'table',
* 'create_index' => 1,
* );
* $add_fields = 3;
*
* $html = PMA_getHtmlForIndexForm(
* $fields, $index, $form_params, $add_fields
* );
*
* //PMA_URL_getHiddenInputs
* $this->assertContains(
* PMA_URL_getHiddenInputs($form_params),
* $html
* );
*
* //Index name
* $this->assertContains(
* __('Index name:'),
* $html
* );
* $doc_html = PMA_Util::showHint(
* PMA_Message::notice(
* __(
* '"PRIMARY" <b>must</b> be the name of'
* . ' and <b>only of</b> a primary key!'
* )
* )
* );
* $this->assertContains(
* $doc_html,
* $html
* );
*
* //Index name
* $this->assertContains(
* __('Index name:'),
* $html
* );
* $this->assertContains(
* PMA_Util::showMySQLDocu('ALTER_TABLE'),
* $html
* );
*
* //generateIndexSelector
* $this->assertContains(
* PMA\Template::trim($index->generateIndexChoiceSelector(false)),
* $html
* );
*
* //items
* $this->assertContains(
* __('Column'),
* $html
* );
* $this->assertContains(
* __('Size'),
* $html
* );
* $this->assertContains(
* sprintf(__('Add %s column(s) to index'), 1),
* $html
* );
*
* //$field_name & $field_type
* $this->assertContains(
* "field_name",
* $html
* );
* $this->assertContains(
* "field_type",
* $html
* );
*/
$this->markTestIncomplete('Not yet implemented!');
}
}

View File

@ -1,192 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for libraries/tbl_relation.lib.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/Util.class.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/relation.lib.php';
require_once 'libraries/Theme.class.php';
/**
* Tests for libraries/tbl_relation.lib.php
*
* @package PhpMyAdmin-test
*/
class PMA_TblRelationTest extends PHPUnit_Framework_TestCase
{
/**
* Configures environment
*
* @return void
*/
protected function setUp()
{
$GLOBALS['server'] = 0;
$GLOBALS['pmaThemeImage'] = 'theme/';
$GLOBALS['cfg']['ShowHint'] = true;
//$_SESSION
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new PMA_Theme();
$GLOBALS['pma'] = new DataBasePMAMockForTblRelation();
$GLOBALS['pma']->databases = new DataBaseMockForTblRelation();
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
}
/**
* Tests for PMA_getSQLToCreateForeignKey() method.
*
* @return void
* @test
*/
public function testPMAGetSQLToCreateForeignKey()
{
// @todo Move this test to PMA_Table_test
/*
$table = "PMA_table";
$field = array("PMA_field1", "PMA_field2");
$foreignDb = "foreignDb";
$foreignTable = "foreignTable";
$foreignField = array("foreignField1", "foreignField2");
$sql = PMA_getSQLToCreateForeignKey(
$table, $field, $foreignDb, $foreignTable, $foreignField
);
$sql_excepted = 'ALTER TABLE `PMA_table` ADD '
. 'FOREIGN KEY (`PMA_field1`, `PMA_field2`) REFERENCES '
. '`foreignDb`.`foreignTable`(`foreignField1`, `foreignField2`);';
$this->assertEquals(
$sql_excepted,
$sql
);
*/
}
/**
* Tests for PMA_getHtmlForCommonForm() method.
*
* @return void
* @test
*/
public function testPMAGetHtmlForCommonForm()
{
// @todo Find out a better method to test for HTML
}
/**
* Tests for PMA_getQueryForDisplayUpdate() method.
* @todo Move this test to PMA_Table_test
*
* @return void
* @test
*/
public function testPMAGetQueryForDisplayUpdate()
{
/*
$disp = true;
$display_field = '';
$db = "pma_db";
$table = "pma_table";
$cfgRelation = array(
'displaywork' => true,
'relwork' => true,
'displaywork' => true,
'table_info' => 'table_info',
);
$GLOBALS['cfgRelation']['db'] = 'global_db';
//case 1: $disp == true && $display_field == ''
$query = PMA_getQueryForDisplayUpdate(
$disp, $display_field, $db, $table, $cfgRelation
);
$query_expect = "DELETE FROM `global_db`.`table_info` "
. "WHERE db_name = 'pma_db' AND table_name = 'pma_table'";
$this->assertEquals(
$query_expect,
$query
);
//case 2: $disp == true && $display_field == 'display_field'
$display_field == 'display_field';
$query = PMA_getQueryForDisplayUpdate(
$disp, $display_field, $db, $table, $cfgRelation
);
$query_expect = "DELETE FROM `global_db`.`table_info` "
. "WHERE db_name = 'pma_db' AND table_name = 'pma_table'";
$this->assertEquals(
$query_expect,
$query
);
//case 3: $disp == false && $display_field == 'display_field'
$disp = false;
$display_field = 'display_field';
$query = PMA_getQueryForDisplayUpdate(
$disp, $display_field, $db, $table, $cfgRelation
);
$query_expect = "INSERT INTO `global_db`.`table_info`"
. "(db_name, table_name, display_field)"
. " VALUES('pma_db','pma_table','display_field')";
$this->assertEquals(
$query_expect,
$query
);
//case 4: $disp == false && $display_field == ''
$disp = false;
$display_field = '';
$query = PMA_getQueryForDisplayUpdate(
$disp, $display_field, $db, $table, $cfgRelation
);
$query_expect = '';
$this->assertEquals(
$query_expect,
$query
);*/
}
}
/**
* Mock class for DataBasePMAMock
*
* @package PhpMyAdmin-test
*/
Class DataBasePMAMockForTblRelation
{
var $databases;
}
/**
* Mock class for DataBaseMock
*
* @package PhpMyAdmin-test
*/
Class DataBaseMockForTblRelation
{
/**
* mock function to return table is existed
*
* @param string $name table name
*
* @return bool
*/
function exists($name)
{
return true;
}
}

View File

@ -0,0 +1,181 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Fake response stub for testing purposes
*
* It will concatenate HTML and JSON for given calls to addHTML and addJSON respectively,
* what make it easy to determine whether the output is correct in test suite. Feel free to
* modify for any future test needs.
*
* @package PhpMyAdmin
* @subpackage Stubs
*/
namespace PMA\Test\Stubs;
use PMA_Header;
use PMA_Message;
require_once 'libraries/Response.class.php';
require_once 'libraries/Header.class.php';
class PMA_Response
{
/**
* PMA_Header instance
*
* @access private
* @var PMA_Header
*/
protected $header;
/**
* HTML data to be used in the response
*
* @access private
* @var string
*/
protected $htmlString;
/**
* An array of JSON key-value pairs
* to be sent back for ajax requests
*
* @access private
* @var array
*/
protected $json;
/**
* Whether there were any errors during the processing of the request
* Only used for ajax responses
*
* @access private
* @var bool
*/
protected $_isSuccess;
/**
* Creates a new class instance
*/
public function __construct()
{
$this->_isSuccess = true;
$this->htmlString = '';
$this->json = array();
$GLOBALS['lang'] = 'en';
$this->header = new PMA_Header();
}
/**
* Add HTML code to the response stub
*
* @param string $content A string to be appended to
* the current output buffer
*
* @return void
*/
public function addHTML($content)
{
if (is_array($content)) {
foreach ($content as $msg) {
$this->addHTML($msg);
}
} elseif ($content instanceof PMA_Message) {
$this->htmlString .= $content->getDisplay();
} else {
$this->htmlString .= $content;
}
}
/**
* Add JSON code to the response stub
*
* @param mixed $json Either a key (string) or an
* array or key-value pairs
* @param mixed $value Null, if passing an array in $json otherwise
* it's a string value to the key
*
* @return void
*/
public function addJSON($json, $value = null)
{
if (is_array($json)) {
foreach ($json as $key => $value) {
$this->addJSON($key, $value);
}
} else {
if ($value instanceof PMA_Message) {
$this->json[$json] = $value->getDisplay();
} else {
$this->json[$json] = $value;
}
}
}
/**
* Return the final concatenated HTML string
*
* @return string
*/
public function getHTMLResult()
{
return $this->htmlString;
}
/**
* Return the final JSON array
*
* @return array
*/
public function getJSONResult()
{
return $this->json;
}
/**
* Current I choose to return PMA_Header object directly because
* our test has nothing about the PMA_Scripts and PMA_Header class.
*
* @return PMA_Header
*/
public function getHeader()
{
return $this->header;
}
/**
* Set the status of an ajax response,
* whether it is a success or an error
*
* @param bool $state Whether the request was successfully processed
*
* @return void
*/
public function isSuccess($state)
{
$this->_isSuccess = $state;
}
/**
* Get the status of an ajax response.
*
* @return bool
*/
public function getSuccessSate()
{
return $this->_isSuccess;
}
/**
* This function is used to clear all data to this
* stub after any operations.
*
*/
public function clear()
{
$this->_isSuccess = true;
$this->json = array();
$this->htmlString = '';
}
}