Refactor select_server functions to static methods
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
parent
ce49e7f60f
commit
99642bf6e2
@ -15,6 +15,7 @@ use PhpMyAdmin\RecentFavoriteTable;
|
||||
use PhpMyAdmin\Relation;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\Server\Select;
|
||||
use PhpMyAdmin\ThemeManager;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
@ -183,9 +184,8 @@ if ($server > 0 || count($cfg['Servers']) > 1
|
||||
|| ($server == 0 && count($cfg['Servers']) == 1)))
|
||||
) {
|
||||
echo '<li id="li_select_server" class="no_bullets" >';
|
||||
include_once 'libraries/select_server.lib.php';
|
||||
echo Util::getImage('s_host.png') , " "
|
||||
, PMA_selectServer(true, true);
|
||||
, Select::render(true, true);
|
||||
echo '</li>';
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
namespace PhpMyAdmin\Navigation;
|
||||
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\Server\Select;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
@ -240,10 +241,9 @@ class NavigationHeader
|
||||
if ($GLOBALS['cfg']['NavigationDisplayServers']
|
||||
&& count($GLOBALS['cfg']['Servers']) > 1
|
||||
) {
|
||||
include_once './libraries/select_server.lib.php';
|
||||
$retval .= '<!-- SERVER CHOICE START -->';
|
||||
$retval .= '<div id="serverChoice">';
|
||||
$retval .= PMA_selectServer(true, true);
|
||||
$retval .= Select::render(true, true);
|
||||
$retval .= '</div>';
|
||||
$retval .= '<!-- SERVER CHOICE END -->';
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ namespace PhpMyAdmin\Plugins\Auth;
|
||||
|
||||
use PhpMyAdmin\Plugins\AuthenticationPlugin;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Server\Select;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
@ -161,10 +162,9 @@ class AuthenticationConfig extends AuthenticationPlugin
|
||||
</tr>' , "\n";
|
||||
if (count($GLOBALS['cfg']['Servers']) > 1) {
|
||||
// offer a chance to login to other servers if the current one failed
|
||||
include_once './libraries/select_server.lib.php';
|
||||
echo '<tr>' , "\n";
|
||||
echo ' <td>' , "\n";
|
||||
echo PMA_selectServer(true, true);
|
||||
echo Select::render(true, true);
|
||||
echo ' </td>' , "\n";
|
||||
echo '</tr>' , "\n";
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ use PhpMyAdmin\LanguageManager;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Plugins\AuthenticationPlugin;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Server\Select;
|
||||
use PhpMyAdmin\Session;
|
||||
use PhpMyAdmin\Util;
|
||||
use PhpMyAdmin\Url;
|
||||
@ -218,10 +219,7 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
, 'elements[\'pma_servername\'].value = \'\'" ';
|
||||
}
|
||||
echo '>';
|
||||
|
||||
include_once './libraries/select_server.lib.php';
|
||||
echo PMA_selectServer(false, false);
|
||||
|
||||
echo Select::render(false, false);
|
||||
echo '</select></div>';
|
||||
} else {
|
||||
echo ' <input type="hidden" name="server" value="'
|
||||
|
||||
125
libraries/classes/Server/Select.php
Normal file
125
libraries/classes/Server/Select.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Code for displaying server selection
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PhpMyAdmin\Server;
|
||||
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\Server\Select class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Select
|
||||
{
|
||||
/**
|
||||
* Renders the server selection in list or selectbox form, or option tags only
|
||||
*
|
||||
* @param boolean $not_only_options whether to include form tags or not
|
||||
* @param boolean $omit_fieldset whether to omit fieldset tag or not
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function render($not_only_options, $omit_fieldset)
|
||||
{
|
||||
$retval = '';
|
||||
|
||||
// Show as list?
|
||||
if ($not_only_options) {
|
||||
$list = $GLOBALS['cfg']['DisplayServersList'];
|
||||
$not_only_options =! $list;
|
||||
} else {
|
||||
$list = false;
|
||||
}
|
||||
|
||||
if ($not_only_options) {
|
||||
$retval .= '<form method="post" action="'
|
||||
. Util::getScriptNameForOption(
|
||||
$GLOBALS['cfg']['DefaultTabServer'], 'server'
|
||||
)
|
||||
. '" class="disableAjax">';
|
||||
|
||||
if (! $omit_fieldset) {
|
||||
$retval .= '<fieldset>';
|
||||
}
|
||||
|
||||
$retval .= Url::getHiddenFields(array());
|
||||
$retval .= '<label for="select_server">'
|
||||
. __('Current server:') . '</label> ';
|
||||
|
||||
$retval .= '<select name="server" id="select_server" class="autosubmit">';
|
||||
$retval .= '<option value="">(' . __('Servers') . ') ...</option>' . "\n";
|
||||
} elseif ($list) {
|
||||
$retval .= __('Current server:') . '<br />';
|
||||
$retval .= '<ul id="list_server">';
|
||||
}
|
||||
|
||||
foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
|
||||
if (empty($server['host'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
|
||||
$selected = 1;
|
||||
} else {
|
||||
$selected = 0;
|
||||
}
|
||||
if (!empty($server['verbose'])) {
|
||||
$label = $server['verbose'];
|
||||
} else {
|
||||
$label = $server['host'];
|
||||
if (!empty($server['port'])) {
|
||||
$label .= ':' . $server['port'];
|
||||
}
|
||||
}
|
||||
if (! empty($server['only_db'])) {
|
||||
if (! is_array($server['only_db'])) {
|
||||
$label .= ' - ' . $server['only_db'];
|
||||
// try to avoid displaying a too wide selector
|
||||
} elseif (count($server['only_db']) < 4) {
|
||||
$label .= ' - ' . implode(', ', $server['only_db']);
|
||||
}
|
||||
}
|
||||
if (!empty($server['user']) && $server['auth_type'] == 'config') {
|
||||
$label .= ' (' . $server['user'] . ')';
|
||||
}
|
||||
|
||||
if ($list) {
|
||||
$retval .= '<li>';
|
||||
if ($selected) {
|
||||
$retval .= '<strong>' . htmlspecialchars($label) . '</strong>';
|
||||
} else {
|
||||
|
||||
$retval .= '<a class="disableAjax item" href="'
|
||||
. Util::getScriptNameForOption(
|
||||
$GLOBALS['cfg']['DefaultTabServer'], 'server'
|
||||
)
|
||||
. Url::getCommon(array('server' => $key))
|
||||
. '" >' . htmlspecialchars($label) . '</a>';
|
||||
}
|
||||
$retval .= '</li>';
|
||||
} else {
|
||||
$retval .= '<option value="' . $key . '" '
|
||||
. ($selected ? ' selected="selected"' : '') . '>'
|
||||
. htmlspecialchars($label) . '</option>' . "\n";
|
||||
}
|
||||
} // end while
|
||||
|
||||
if ($not_only_options) {
|
||||
$retval .= '</select>';
|
||||
if (! $omit_fieldset) {
|
||||
$retval .= '</fieldset>';
|
||||
}
|
||||
$retval .= '</form>';
|
||||
} elseif ($list) {
|
||||
$retval .= '</ul>';
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
}
|
||||
@ -1,115 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Code for displaying server selection
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
use PhpMyAdmin\Url;
|
||||
|
||||
/**
|
||||
* Renders the server selection in list or selectbox form, or option tags only
|
||||
*
|
||||
* @param boolean $not_only_options whether to include form tags or not
|
||||
* @param boolean $omit_fieldset whether to omit fieldset tag or not
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_selectServer($not_only_options, $omit_fieldset)
|
||||
{
|
||||
$retval = '';
|
||||
|
||||
// Show as list?
|
||||
if ($not_only_options) {
|
||||
$list = $GLOBALS['cfg']['DisplayServersList'];
|
||||
$not_only_options =! $list;
|
||||
} else {
|
||||
$list = false;
|
||||
}
|
||||
|
||||
if ($not_only_options) {
|
||||
$retval .= '<form method="post" action="'
|
||||
. PhpMyAdmin\Util::getScriptNameForOption(
|
||||
$GLOBALS['cfg']['DefaultTabServer'], 'server'
|
||||
)
|
||||
. '" class="disableAjax">';
|
||||
|
||||
if (! $omit_fieldset) {
|
||||
$retval .= '<fieldset>';
|
||||
}
|
||||
|
||||
$retval .= Url::getHiddenFields(array());
|
||||
$retval .= '<label for="select_server">'
|
||||
. __('Current server:') . '</label> ';
|
||||
|
||||
$retval .= '<select name="server" id="select_server" class="autosubmit">';
|
||||
$retval .= '<option value="">(' . __('Servers') . ') ...</option>' . "\n";
|
||||
} elseif ($list) {
|
||||
$retval .= __('Current server:') . '<br />';
|
||||
$retval .= '<ul id="list_server">';
|
||||
}
|
||||
|
||||
foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
|
||||
if (empty($server['host'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
|
||||
$selected = 1;
|
||||
} else {
|
||||
$selected = 0;
|
||||
}
|
||||
if (!empty($server['verbose'])) {
|
||||
$label = $server['verbose'];
|
||||
} else {
|
||||
$label = $server['host'];
|
||||
if (!empty($server['port'])) {
|
||||
$label .= ':' . $server['port'];
|
||||
}
|
||||
}
|
||||
if (! empty($server['only_db'])) {
|
||||
if (! is_array($server['only_db'])) {
|
||||
$label .= ' - ' . $server['only_db'];
|
||||
// try to avoid displaying a too wide selector
|
||||
} elseif (count($server['only_db']) < 4) {
|
||||
$label .= ' - ' . implode(', ', $server['only_db']);
|
||||
}
|
||||
}
|
||||
if (!empty($server['user']) && $server['auth_type'] == 'config') {
|
||||
$label .= ' (' . $server['user'] . ')';
|
||||
}
|
||||
|
||||
if ($list) {
|
||||
$retval .= '<li>';
|
||||
if ($selected) {
|
||||
$retval .= '<strong>' . htmlspecialchars($label) . '</strong>';
|
||||
} else {
|
||||
|
||||
$retval .= '<a class="disableAjax item" href="'
|
||||
. PhpMyAdmin\Util::getScriptNameForOption(
|
||||
$GLOBALS['cfg']['DefaultTabServer'], 'server'
|
||||
)
|
||||
. Url::getCommon(array('server' => $key))
|
||||
. '" >' . htmlspecialchars($label) . '</a>';
|
||||
}
|
||||
$retval .= '</li>';
|
||||
} else {
|
||||
$retval .= '<option value="' . $key . '" '
|
||||
. ($selected ? ' selected="selected"' : '') . '>'
|
||||
. htmlspecialchars($label) . '</option>' . "\n";
|
||||
}
|
||||
} // end while
|
||||
|
||||
if ($not_only_options) {
|
||||
$retval .= '</select>';
|
||||
if (! $omit_fieldset) {
|
||||
$retval .= '</fieldset>';
|
||||
}
|
||||
$retval .= '</form>';
|
||||
} elseif ($list) {
|
||||
$retval .= '</ul>';
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
@ -1,28 +1,25 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* tests for select_server.lib.php
|
||||
* tests for PhpMyAdmin\Server\Select
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
namespace PhpMyAdmin\Tests\Server;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
use PhpMyAdmin\Server\Select;
|
||||
use PhpMyAdmin\Theme;
|
||||
|
||||
|
||||
require_once 'libraries/select_server.lib.php';
|
||||
|
||||
use PhpMyAdmin\Util;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
/**
|
||||
* PMA_SelectServer_Test class
|
||||
* PhpMyAdmin\Tests\Server\SelectTest class
|
||||
*
|
||||
* this class is for testing select_server.lib.php functions
|
||||
* this class is for testing PhpMyAdmin\Server\Select methods
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase
|
||||
class SelectTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Prepares environment for the test.
|
||||
@ -52,11 +49,11 @@ class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_selectServer
|
||||
* Test for Select::render
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPMASelectServer()
|
||||
public function testRender()
|
||||
{
|
||||
$not_only_options = false;
|
||||
$omit_fieldset = false;
|
||||
@ -81,7 +78,7 @@ class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
//$not_only_options=false & $omit_fieldset=false
|
||||
$html = PMA_selectServer($not_only_options, $omit_fieldset);
|
||||
$html = Select::render($not_only_options, $omit_fieldset);
|
||||
$server = $GLOBALS['cfg']['Servers']['0'];
|
||||
|
||||
//server items
|
||||
@ -107,11 +104,11 @@ class PMA_SelectServer_Test extends PHPUnit_Framework_TestCase
|
||||
$GLOBALS['cfg']['DisplayServersList'] = null;
|
||||
|
||||
//$not_only_options=true & $omit_fieldset=true
|
||||
$html = PMA_selectServer($not_only_options, $omit_fieldset);
|
||||
$html = Select::render($not_only_options, $omit_fieldset);
|
||||
|
||||
//$GLOBALS['cfg']['DefaultTabServer']
|
||||
$this->assertContains(
|
||||
PhpMyAdmin\Util::getScriptNameForOption(
|
||||
Util::getScriptNameForOption(
|
||||
$GLOBALS['cfg']['DefaultTabServer'], 'server'
|
||||
),
|
||||
$html
|
||||
Loading…
Reference in New Issue
Block a user