diff --git a/ChangeLog b/ChangeLog index d9cbfb6373..da3eec6d14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,7 @@ phpMyAdmin - ChangeLog + rfe #755 Export with table/column name changes + rfe #869 Run SQL query: Allow rollback for InnoDB tables + rfe #654 Range Search Capability ++ rfe #1490 Dynamic process list 4.2.5.0 (not yet released) - bug #4467 shell_exec() has been disabled for security reasons diff --git a/js/messages.php b/js/messages.php index fe8e23f07b..0f7a7097b7 100644 --- a/js/messages.php +++ b/js/messages.php @@ -132,6 +132,8 @@ $js_messages['strAddOneSeriesWarning'] = __('Please add at least one variable to $js_messages['strNone'] = __('None'); $js_messages['strResumeMonitor'] = __('Resume monitor'); $js_messages['strPauseMonitor'] = __('Pause monitor'); +$js_messages['strStartRefresh'] = __('Start auto refresh'); +$js_messages['strStopRefresh'] = __('Stop auto refresh'); /* Monitor: Instructions Dialog */ $js_messages['strBothLogOn'] = __('general_log and slow_query_log are enabled.'); $js_messages['strGenLogOn'] = __('general_log is enabled.'); diff --git a/js/server_status_monitor.js b/js/server_status_monitor.js index 3325ab5875..60ab1ff5a0 100644 --- a/js/server_status_monitor.js +++ b/js/server_status_monitor.js @@ -670,9 +670,9 @@ AJAX.registerOnload('server_status_monitor.js', function () { event.preventDefault(); runtime.redrawCharts = ! runtime.redrawCharts; if (! runtime.redrawCharts) { - $(this).html(PMA_getImage('play.png') + ' ' + PMA_messages.strResumeMonitor); + $(this).html(PMA_getImage('play.png') + PMA_messages.strResumeMonitor); } else { - $(this).html(PMA_getImage('pause.png') + ' ' + PMA_messages.strPauseMonitor); + $(this).html(PMA_getImage('pause.png') + PMA_messages.strPauseMonitor); if (! runtime.charts) { initGrid(); $('a[href="#settingsPopup"]').show(); diff --git a/js/server_status_processes.js b/js/server_status_processes.js new file mode 100644 index 0000000000..72b9bfbbf5 --- /dev/null +++ b/js/server_status_processes.js @@ -0,0 +1,171 @@ +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * Server Status Processes + * + * @package PhpMyAdmin + */ + +// object to store process list state information +var processList = { + + // denotes whether auto refresh is on or off + autoRefresh: false, + // stores the GET request which refresh process list + refreshRequest: null, + // stores the timeout id returned by setTimeout + refreshTimeout: null, + // the refresh interval in seconds + refreshInterval: null, + // the refresh URL (required to save last used option) + // i.e. full or sorting url + refreshUrl: null, + + /** + * Handles killing of a process + * + * @return void + */ + init: function() { + processList.setRefreshLabel(); + if (processList.refreshUrl === null) { + processList.refreshUrl = 'server_status_processes.php?' + + PMA_commonParams.get('common_query'); + } + if (processList.refreshInterval === null) { + processList.refreshInterval = $('#id_refreshRate').val(); + } else { + $('#id_refreshRate').val(processList.refreshInterval); + } + }, + + /** + * Handles killing of a process + * + * @param object the event object + * + * @return void + */ + killProcessHandler: function(event) { + event.preventDefault(); + var url = $(this).attr('href'); + // Get row element of the process to be killed. + var $tr = $(this).closest('tr'); + $.getJSON(url, function(data) { + // Check if process was killed or not. + if (data.hasOwnProperty('success') && data.success) { + // remove the row of killed process. + $tr.remove(); + // As we just removed a row, reapply odd-even classes + // to keep table stripes consistent + $('#tableprocesslist > tbody > tr').filter(':even') + .removeClass('odd').addClass('even'); + $('#tableprocesslist > tbody > tr').filter(':odd') + .removeClass('even').addClass('odd'); + // Show process killed message + PMA_ajaxShowMessage(data.message, false); + } else { + // Show process error message + PMA_ajaxShowMessage(data.error, false); + } + }); + }, + + /** + * Handles Auto Refreshing + * + * @param object the event object + * + * @return void + */ + refresh: function(event) { + // abort any previous pending requests + // this is necessary, it may go into + // multiple loops causing unnecessary + // requests even after leaving the page. + processList.abortRefresh(); + // if auto refresh is enabled + if (processList.autoRefresh) { + var interval = parseInt(processList.refreshInterval, 10) * 1000; + processList.refreshRequest = $.get(processList.refreshUrl, { + 'ajax_request': true, + 'refresh': true + }, function(data) { + if (data.hasOwnProperty('success') && data.success) { + $newTable = $(data.message); + $('#tableprocesslist').html($newTable.html()); + } + processList.refreshTimeout = setTimeout( + processList.refresh, + interval + ); + }); + } + }, + + /** + * Stop current request and clears timeout + * + * @return void + */ + abortRefresh: function() { + if (processList.refreshRequest !== null) { + processList.refreshRequest.abort(); + processList.refreshRequest = null; + } + clearTimeout(processList.refreshTimeout); + }, + + /** + * Set label of refresh button + * change between play & pause + * + * @return void + */ + setRefreshLabel: function() { + var img = 'play.png'; + var label = PMA_messages.strStartRefresh; + if (processList.autoRefresh) { + img = 'pause.png'; + label = PMA_messages.strStopRefresh; + processList.refresh(); + } + $('a#toggleRefresh').html(PMA_getImage(img) + escapeHtml(label)); + } +}; + +AJAX.registerOnload('server_status_processes.js', function() { + + processList.init(); + // Bind event handler for kill_process + $('#tableprocesslist').on( + 'click', + 'a.kill_process', + processList.killProcessHandler + ); + // Bind event handler for toggling refresh of process list + $('a#toggleRefresh').on('click', function(event) { + event.preventDefault(); + processList.autoRefresh = !processList.autoRefresh; + processList.setRefreshLabel(); + }); + // Bind event handler for change in refresh rate + $('#id_refreshRate').on('change', function(event) { + processList.refreshInterval = $(this).val(); + }); + // Bind event handler for table header links + $('#tableprocesslist').on('click', 'thead a', function() { + processList.refreshUrl = $(this).attr('href'); + }); +}); + +/** + * Unbind all event handlers before tearing down a page + */ +AJAX.registerTeardown('server_status_processes.js', function() { + $('#tableprocesslist').off('click', 'a.kill_process'); + $('a#toggleRefresh').off('click'); + $('#id_refreshRate').off('change'); + $('#tableprocesslist').off('click', 'thead a'); + // stop refreshing further + processList.abortRefresh(); +}); diff --git a/libraries/ServerStatusData.class.php b/libraries/ServerStatusData.class.php index 128aad45f4..a07e671f15 100644 --- a/libraries/ServerStatusData.class.php +++ b/libraries/ServerStatusData.class.php @@ -365,6 +365,10 @@ class PMA_ServerStatusData 'name' => __('Server'), 'url' => 'server_status.php' ), + array( + 'name' => __('Processes'), + 'url' => 'server_status_processes.php' + ), array( 'name' => __('Query statistics'), 'url' => 'server_status_queries.php' @@ -401,6 +405,40 @@ class PMA_ServerStatusData return $retval; } + + /** + * Builds a '; + foreach ($refreshRates as $rate) { + $selected = ($rate == $defaultRate)?' selected="selected"':''; + $return .= ''; + } + $return .= ''; + return $return; + } } ?> diff --git a/libraries/server_status.lib.php b/libraries/server_status.lib.php index ec85052746..9f5d77f571 100644 --- a/libraries/server_status.lib.php +++ b/libraries/server_status.lib.php @@ -30,9 +30,6 @@ function PMA_getHtmlForServerStatus($ServerStatusData) //display the server state connection information $retval .= PMA_getHtmlForServerStateConnections($ServerStatusData); - //display the server Process List information - $retval .= PMA_getHtmlForServerProcesslist($ServerStatusData); - return $retval; } @@ -309,236 +306,4 @@ function PMA_getHtmlForServerStateConnections($ServerStatusData) return $retval; } -/** - * Prints Server Process list - * - * @return string - */ -function PMA_getHtmlForServerProcesslist() -{ - $url_params = array(); - - $show_full_sql = ! empty($_REQUEST['full']); - if ($show_full_sql) { - $url_params['full'] = 1; - $full_text_link = 'server_status.php' . PMA_URL_getCommon( - array(), 'html', '?' - ); - } else { - $full_text_link = 'server_status.php' . PMA_URL_getCommon( - array('full' => 1) - ); - } - - // This array contains display name and real column name of each - // sortable column in the table - $sortable_columns = array( - array( - 'column_name' => __('ID'), - 'order_by_field' => 'Id' - ), - array( - 'column_name' => __('User'), - 'order_by_field' => 'User' - ), - array( - 'column_name' => __('Host'), - 'order_by_field' => 'Host' - ), - array( - 'column_name' => __('Database'), - 'order_by_field' => 'db' - ), - array( - 'column_name' => __('Command'), - 'order_by_field' => 'Command' - ), - array( - 'column_name' => __('Time'), - 'order_by_field' => 'Time' - ), - array( - 'column_name' => __('Status'), - 'order_by_field' => 'State' - ), - array( - 'column_name' => __('SQL query'), - 'order_by_field' => 'Info' - ) - ); - $sortableColCount = count($sortable_columns); - - if (PMA_DRIZZLE) { - $left_str = 'left(p.info, ' - . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')'; - $sql_query = "SELECT - p.id AS Id, - p.username AS User, - p.host AS Host, - p.db AS db, - p.command AS Command, - p.time AS Time, - p.state AS State," - . ($show_full_sql ? 's.query' : $left_str ) - . " AS Info FROM data_dictionary.PROCESSLIST p " - . ($show_full_sql - ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' - : ''); - if (! empty($_REQUEST['order_by_field']) - && ! empty($_REQUEST['sort_order']) - ) { - $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' ' - . $_REQUEST['sort_order']; - } - } else { - $sql_query = $show_full_sql - ? 'SHOW FULL PROCESSLIST' - : 'SHOW PROCESSLIST'; - if (! empty($_REQUEST['order_by_field']) - && ! empty($_REQUEST['sort_order']) - ) { - $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ' - . 'ORDER BY `' - . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order']; - } - } - - $result = $GLOBALS['dbi']->query($sql_query); - - $retval = ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - foreach ($sortable_columns as $column) { - - $is_sorted = ! empty($_REQUEST['order_by_field']) - && ! empty($_REQUEST['sort_order']) - && ($_REQUEST['order_by_field'] == $column['order_by_field']); - - $column['sort_order'] = 'ASC'; - if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') { - $column['sort_order'] = 'DESC'; - } - - if ($is_sorted) { - if ($_REQUEST['sort_order'] == 'ASC') { - $asc_display_style = 'inline'; - $desc_display_style = 'none'; - } elseif ($_REQUEST['sort_order'] == 'DESC') { - $desc_display_style = 'inline'; - $asc_display_style = 'none'; - } - } - - $retval .= ''; - } - - $retval .= ''; - $retval .= ''; - $retval .= ''; - - $odd_row = true; - while ($process = $GLOBALS['dbi']->fetchAssoc($result)) { - $retval .= PMA_getHtmlForServerProcessItem( - $process, - $odd_row, - $show_full_sql - ); - $odd_row = ! $odd_row; - } - $retval .= ''; - $retval .= '
' . __('Processes') . ''; - $columnUrl = PMA_URL_getCommon($column); - $retval .= ''; - $retval .= ''
-                . __('Ascending') . ''; - } - - $retval .= ''; - - if (! PMA_DRIZZLE && (0 === --$sortableColCount)) { - $retval .= ''; - if ($show_full_sql) { - $retval .= PMA_Util::getImage( - 's_partialtext.png', - __('Truncate Shown Queries') - ); - } else { - $retval .= PMA_Util::getImage( - 's_fulltext.png', - __('Show Full Queries') - ); - } - $retval .= ''; - } - $retval .= '
'; - - return $retval; -} - -/** - * Prints Every Item of Server Process - * - * @param Array $process data of Every Item of Server Process - * @param bool $odd_row display odd row or not - * @param bool $show_full_sql show full sql or not - * - * @return string - */ -function PMA_getHtmlForServerProcessItem($process, $odd_row, $show_full_sql) -{ - // Array keys need to modify due to the way it has used - // to display column values - if (! empty($_REQUEST['order_by_field']) && ! empty($_REQUEST['sort_order']) ) { - foreach (array_keys($process) as $key) { - $new_key = ucfirst(strtolower($key)); - $process[$new_key] = $process[$key]; - unset($process[$key]); - } - } - - $url_params = array( - 'kill' => $process['Id'] - ); - $kill_process = 'server_status.php' . PMA_URL_getCommon($url_params); - - $retval = ''; - $retval .= '' . __('Kill') . ''; - $retval .= '' . $process['Id'] . ''; - $retval .= '' . htmlspecialchars($process['User']) . ''; - $retval .= '' . htmlspecialchars($process['Host']) . ''; - $retval .= '' . ((! isset($process['db']) || ! strlen($process['db'])) - ? '' . __('None') . '' - : htmlspecialchars($process['db'])) . ''; - $retval .= '' . htmlspecialchars($process['Command']) . ''; - $retval .= '' . $process['Time'] . ''; - $processStatusStr = empty($process['State']) ? '---' : $process['State']; - $retval .= '' . $processStatusStr . ''; - $retval .= ''; - - if (empty($process['Info'])) { - $retval .= '---'; - } else { - $retval .= PMA_Util::formatSql($process['Info'], ! $show_full_sql); - } - $retval .= ''; - $retval .= ''; - - return $retval; -} - ?> diff --git a/libraries/server_status_monitor.lib.php b/libraries/server_status_monitor.lib.php index 5ab1c02f1e..654565ec97 100644 --- a/libraries/server_status_monitor.lib.php +++ b/libraries/server_status_monitor.lib.php @@ -55,36 +55,6 @@ function PMA_getHtmlForMonitor($ServerStatusData) return $retval; } -/** - * Builds a '; - foreach ($refreshRates as $rate) { - $selected = ($rate == $defaultRate)?' selected="selected"':''; - $return .= ''; - } - $return .= ''; - return $return; -} - /** * Returns html for Analyse Dialog * @@ -328,7 +298,7 @@ function PMA_getHtmlForSettingsDialog() $retval .= '
'; $retval .= '
'; $retval .= __('Refresh rate') . '
'; - $retval .= PMA_getHtmlForRefreshList( + $retval .= PMA_ServerStatusData::getHtmlForRefreshList( 'gridChartRefresh', 5, Array(2, 3, 4, 5, 10, 20, 40, 60, 120, 300, 600, 1200) diff --git a/libraries/server_status_processes.lib.php b/libraries/server_status_processes.lib.php new file mode 100644 index 0000000000..e7cd41e41a --- /dev/null +++ b/libraries/server_status_processes.lib.php @@ -0,0 +1,280 @@ +getDisplay(); + $retval = $notice . ''; + $retval .= PMA_getHtmlForServerProcesslist(); + return $retval; +} + +/** + * Prints Server Process list + * + * @return string + */ +function PMA_getHtmlForServerProcesslist() +{ + $url_params = array(); + + $show_full_sql = ! empty($_REQUEST['full']); + if ($show_full_sql) { + $url_params['full'] = 1; + $full_text_link = 'server_status_processes.php' . PMA_URL_getCommon( + array(), 'html', '?' + ); + } else { + $full_text_link = 'server_status_processes.php' . PMA_URL_getCommon( + array('full' => 1) + ); + } + + // This array contains display name and real column name of each + // sortable column in the table + $sortable_columns = array( + array( + 'column_name' => __('ID'), + 'order_by_field' => 'Id' + ), + array( + 'column_name' => __('User'), + 'order_by_field' => 'User' + ), + array( + 'column_name' => __('Host'), + 'order_by_field' => 'Host' + ), + array( + 'column_name' => __('Database'), + 'order_by_field' => 'db' + ), + array( + 'column_name' => __('Command'), + 'order_by_field' => 'Command' + ), + array( + 'column_name' => __('Time'), + 'order_by_field' => 'Time' + ), + array( + 'column_name' => __('Status'), + 'order_by_field' => 'State' + ), + array( + 'column_name' => __('SQL query'), + 'order_by_field' => 'Info' + ) + ); + $sortableColCount = count($sortable_columns); + + if (PMA_DRIZZLE) { + $left_str = 'left(p.info, ' + . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')'; + $sql_query = "SELECT + p.id AS Id, + p.username AS User, + p.host AS Host, + p.db AS db, + p.command AS Command, + p.time AS Time, + p.state AS State," + . ($show_full_sql ? 's.query' : $left_str ) + . " AS Info FROM data_dictionary.PROCESSLIST p " + . ($show_full_sql + ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' + : ''); + if (! empty($_REQUEST['order_by_field']) + && ! empty($_REQUEST['sort_order']) + ) { + $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' ' + . $_REQUEST['sort_order']; + } + } else { + $sql_query = $show_full_sql + ? 'SHOW FULL PROCESSLIST' + : 'SHOW PROCESSLIST'; + if (! empty($_REQUEST['order_by_field']) + && ! empty($_REQUEST['sort_order']) + ) { + $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ' + . 'ORDER BY `' + . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order']; + } + } + + $result = $GLOBALS['dbi']->query($sql_query); + + $retval = ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + foreach ($sortable_columns as $column) { + + $is_sorted = ! empty($_REQUEST['order_by_field']) + && ! empty($_REQUEST['sort_order']) + && ($_REQUEST['order_by_field'] == $column['order_by_field']); + + $column['sort_order'] = 'ASC'; + if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') { + $column['sort_order'] = 'DESC'; + } + + if ($is_sorted) { + if ($_REQUEST['sort_order'] == 'ASC') { + $asc_display_style = 'inline'; + $desc_display_style = 'none'; + } elseif ($_REQUEST['sort_order'] == 'DESC') { + $desc_display_style = 'inline'; + $asc_display_style = 'none'; + } + } + + $retval .= ''; + } + + $retval .= ''; + $retval .= ''; + $retval .= ''; + + $odd_row = true; + while ($process = $GLOBALS['dbi']->fetchAssoc($result)) { + $retval .= PMA_getHtmlForServerProcessItem( + $process, + $odd_row, + $show_full_sql + ); + $odd_row = ! $odd_row; + } + $retval .= ''; + $retval .= '
' . __('Processes') . ''; + $columnUrl = PMA_URL_getCommon($column); + $retval .= ''; + $retval .= ''
+                . __('Ascending') . ''; + } + + $retval .= ''; + + if (! PMA_DRIZZLE && (0 === --$sortableColCount)) { + $retval .= ''; + if ($show_full_sql) { + $retval .= PMA_Util::getImage( + 's_partialtext.png', + __('Truncate Shown Queries') + ); + } else { + $retval .= PMA_Util::getImage( + 's_fulltext.png', + __('Show Full Queries') + ); + } + $retval .= ''; + } + $retval .= '
'; + + return $retval; +} + +/** + * Prints Every Item of Server Process + * + * @param Array $process data of Every Item of Server Process + * @param bool $odd_row display odd row or not + * @param bool $show_full_sql show full sql or not + * + * @return string + */ +function PMA_getHtmlForServerProcessItem($process, $odd_row, $show_full_sql) +{ + // Array keys need to modify due to the way it has used + // to display column values + if (! empty($_REQUEST['order_by_field']) && ! empty($_REQUEST['sort_order']) ) { + foreach (array_keys($process) as $key) { + $new_key = ucfirst(strtolower($key)); + if ($new_key !== $key) { + $process[$new_key] = $process[$key]; + unset($process[$key]); + } + } + } + + $url_params = array( + 'kill' => $process['Id'], + 'ajax_request' => true + ); + $kill_process = 'server_status_processes.php' . PMA_URL_getCommon($url_params); + + $retval = ''; + $retval .= '' + . __('Kill') . ''; + $retval .= '' . $process['Id'] . ''; + $retval .= '' . htmlspecialchars($process['User']) . ''; + $retval .= '' . htmlspecialchars($process['Host']) . ''; + $retval .= '' . ((! isset($process['db']) || ! strlen($process['db'])) + ? '' . __('None') . '' + : htmlspecialchars($process['db'])) . ''; + $retval .= '' . htmlspecialchars($process['Command']) . ''; + $retval .= '' . $process['Time'] . ''; + $processStatusStr = empty($process['State']) ? '---' : $process['State']; + $retval .= '' . $processStatusStr . ''; + $retval .= ''; + + if (empty($process['Info'])) { + $retval .= '---'; + } else { + $retval .= PMA_Util::formatSql($process['Info'], ! $show_full_sql); + } + $retval .= ''; + $retval .= ''; + + return $retval; +} + +?> diff --git a/server_status.php b/server_status.php index 7bee6558f6..6168318c2f 100644 --- a/server_status.php +++ b/server_status.php @@ -24,24 +24,6 @@ if (PMA_DRIZZLE) { $ServerStatusData = new PMA_ServerStatusData(); -/** - * Kills a selected process - */ -if (! empty($_REQUEST['kill'])) { - $query = $GLOBALS['dbi']->getKillQuery((int)$_REQUEST['kill']); - if ($GLOBALS['dbi']->tryQuery($query)) { - $message = PMA_Message::success(__('Thread %s was successfully killed.')); - } else { - $message = PMA_Message::error( - __( - 'phpMyAdmin was unable to kill thread %s.' - . ' It probably has already been closed.' - ) - ); - } - $message->addParam($_REQUEST['kill']); -} - /** * start output */ diff --git a/server_status_processes.php b/server_status_processes.php new file mode 100644 index 0000000000..6a437944d8 --- /dev/null +++ b/server_status_processes.php @@ -0,0 +1,62 @@ + processes list + * + * @package PhpMyAdmin + */ + +require_once 'libraries/common.inc.php'; +require_once 'libraries/server_common.inc.php'; +require_once 'libraries/ServerStatusData.class.php'; +require_once 'libraries/server_status_processes.lib.php'; + +/** + * Replication library + */ +if (PMA_DRIZZLE) { + $server_master_status = false; + $server_slave_status = false; +} else { + include_once 'libraries/replication.inc.php'; + include_once 'libraries/replication_gui.lib.php'; +} + +$ServerStatusData = new PMA_ServerStatusData(); +$response = PMA_Response::getInstance(); + +/** + * Kills a selected process + * on ajax request + */ +if ($response->isAjax() && !empty($_REQUEST['kill'])) { + $query = $GLOBALS['dbi']->getKillQuery((int)$_REQUEST['kill']); + if ($GLOBALS['dbi']->tryQuery($query)) { + $message = PMA_Message::success(__('Thread %s was successfully killed.')); + $response->isSuccess(true); + } else { + $message = PMA_Message::error( + __( + 'phpMyAdmin was unable to kill thread %s.' + . ' It probably has already been closed.' + ) + ); + $response->isSuccess(false); + } + $message->addParam($_REQUEST['kill']); + $response->addJSON('message', $message); +} elseif ($response->isAjax() && !empty($_REQUEST['refresh'])) { + // Only sends the process list table + $response->addHTML(PMA_getHtmlForServerProcessList()); +} else { + // Load the full page + $header = $response->getHeader(); + $scripts = $header->getScripts(); + $scripts->addFile('server_status_processes.js'); + $response->addHTML('
'); + $response->addHTML($ServerStatusData->getMenuHtml()); + $response->addHTML(PMA_getHtmlForServerProcesses()); + $response->addHTML('
'); +} +exit; +?> diff --git a/test/classes/PMA_ServerStatusData_test.php b/test/classes/PMA_ServerStatusData_test.php new file mode 100644 index 0000000000..1abd6e87bc --- /dev/null +++ b/test/classes/PMA_ServerStatusData_test.php @@ -0,0 +1,136 @@ +getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + //this data is needed when PMA_ServerStatusData constructs + $server_status = array( + "Aborted_clients" => "0", + "Aborted_connects" => "0", + "Com_delete_multi" => "0", + "Com_create_function" => "0", + "Com_empty_query" => 3, + "Key_blocks_used" => 2, + "Key_writes" => true, + "Key_reads" => true, + "Key_write_requests" => 5, + "Key_read_requests" => 1, + "Threads_created" => true, + "Connections" => 2, + ); + + $server_variables= array( + "auto_increment_increment" => "1", + "auto_increment_offset" => "1", + "automatic_sp_privileges" => "ON", + "back_log" => "50", + "big_tables" => "OFF", + "key_buffer_size" => 10, + ); + + $fetchResult = array( + array( + "SHOW GLOBAL STATUS", + 0, + 1, + null, + 0, + $server_status + ), + array( + "SHOW GLOBAL VARIABLES", + 0, + 1, + null, + 0, + $server_variables + ), + array( + "SELECT concat('Com_', variable_name), variable_value " + . "FROM data_dictionary.GLOBAL_STATEMENTS", + 0, + 1, + null, + 0, + $server_status + ), + ); + + $dbi->expects($this->any())->method('fetchResult') + ->will($this->returnValueMap($fetchResult)); + + $GLOBALS['dbi'] = $dbi; + + $this->object = new PMA_ServerStatusData(); + } + + /** + * tests getMenuHtml() + * + * @return void + */ + function testGetMenuHtml() + { + $html = $this->object->getMenuHtml(); + + $this->assertContains('Server', $html); + $this->assertContains('server_status.php', $html); + + $this->assertContains('Processes', $html); + $this->assertContains('server_status_processes.php', $html); + + $this->assertContains('Query statistics', $html); + $this->assertContains('server_status_queries.php', $html); + + $this->assertContains('All status variables', $html); + $this->assertContains('server_status_variables.php', $html); + + $this->assertContains('Monitor', $html); + $this->assertContains('server_status_monitor.php', $html); + + $this->assertContains('Advisor', $html); + $this->assertContains('server_status_advisor.php', $html); + } +} diff --git a/test/libraries/PMA_server_status_processes_test.php b/test/libraries/PMA_server_status_processes_test.php new file mode 100644 index 0000000000..4a1143e4bf --- /dev/null +++ b/test/libraries/PMA_server_status_processes_test.php @@ -0,0 +1,279 @@ +getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $GLOBALS['dbi'] = $dbi; + } + + /** + * Test for PMA_getHtmlForServerProcesses + * + * @return void + * @group medium + */ + public function testPMAGetHtmlForServerProcesses() + { + $html = PMA_getHtmlForServerProcesses(); + + // Test Notice + $this->assertContains( + 'Note: Enabling the auto refresh here might cause ' + . 'heavy traffic between the web server and the MySQL server.', + $html + ); + // Test tab links + $this->assertContains( + '