Ejemplo n.º 1
0
/**
 * Prints Html for Server Variables Items
 *
 * @param Array $variable_doc_links documentation links
 *
 * @return string
 */
function PMA_getHtmlForServerVariablesItems($variable_doc_links)
{
    /**
     * Sends the queries and buffers the results
     */
    $serverVarsSession = $GLOBALS['dbi']->fetchResult('SHOW SESSION VARIABLES;', 0, 1);
    $serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1);
    $output = '';
    $odd_row = true;
    foreach ($serverVars as $name => $value) {
        $has_session_value = isset($serverVarsSession[$name]) && $serverVarsSession[$name] != $value;
        $row_class = ($odd_row ? ' odd' : ' even') . ($has_session_value ? ' diffSession' : '');
        $output .= '<div class="var-row' . $row_class . '">' . '<div class="var-name">';
        // To display variable documentation link
        if (isset($variable_doc_links[$name])) {
            $output .= '<span title="' . htmlspecialchars(str_replace('_', ' ', $name)) . '">';
            $output .= PMA_Util::showMySQLDocu($variable_doc_links[$name][1], false, $variable_doc_links[$name][2] . '_' . $variable_doc_links[$name][0], true);
            $output .= htmlspecialchars(str_replace('_', ' ', $name));
            $output .= '</a>';
            $output .= '</span>';
        } else {
            $output .= htmlspecialchars(str_replace('_', ' ', $name));
        }
        $output .= '</div>' . '<div class="var-value value' . ($GLOBALS['dbi']->isSuperuser() ? ' editable' : '') . '">&nbsp;' . PMA_formatVariable($name, $value, $variable_doc_links) . '</div>' . '<div style="clear:both"></div>' . '</div>';
        if ($has_session_value) {
            $output .= '<div class="var-row' . ($odd_row ? ' odd' : ' even') . '">' . '<div class="var-name session">(' . __('Session value') . ')</div>' . '<div class="var-value value">&nbsp;' . PMA_formatVariable($name, $serverVarsSession[$name], $variable_doc_links) . '</div>' . '<div style="clear:both"></div>' . '</div>';
        }
        $odd_row = !$odd_row;
    }
    return $output;
}
/**
 * Prints Html for Server Variables Items
 *
 * @param Array $variable_doc_links documentation links
 * @param Array $serverVars         global variables
 * @param Array $serverVarsSession  session variables
 *
 * @return string
 */
function PMA_getHtmlForServerVariablesItems($variable_doc_links, $serverVars, $serverVarsSession)
{
    // list of static system variables
    $static_variables = PMA_getStaticSystemVariables();
    $output = '<tbody>';
    $odd_row = true;
    foreach ($serverVars as $name => $value) {
        $has_session_value = isset($serverVarsSession[$name]) && $serverVarsSession[$name] != $value;
        $row_class = ($odd_row ? ' odd' : ' even') . ($has_session_value ? ' diffSession' : '');
        $output .= '<tr class="var-row' . $row_class . '">';
        $output .= '<td class="var-action">';
        // Edit Link active only for Dynamic System variables
        if (!in_array(strtolower($name), $static_variables)) {
            $output .= '<a href="#" class="editLink">' . PMA_Util::getIcon('b_edit.png', __('Edit')) . '</a>';
        } else {
            $output .= '<span title="' . __('This is a read-only variable and can not be edited') . '" class="read_only_var" >' . PMA_Util::getIcon('bd_edit.png', __('Edit')) . '</span>';
        }
        $output .= '</td>';
        $output .= '<td class="var-name">';
        // To display variable documentation link
        if (isset($variable_doc_links[$name])) {
            $output .= '<span title="' . htmlspecialchars(str_replace('_', ' ', $name)) . '">';
            $output .= PMA_Util::showMySQLDocu($variable_doc_links[$name][1], false, $variable_doc_links[$name][2] . '_' . $variable_doc_links[$name][0], true);
            $output .= htmlspecialchars(str_replace('_', ' ', $name));
            $output .= '</a>';
            $output .= '</span>';
        } else {
            $output .= htmlspecialchars(str_replace('_', ' ', $name));
        }
        $output .= '</td>';
        $output .= '<td class="var-value value' . ($GLOBALS['dbi']->isSuperuser() ? ' editable' : '') . '">&nbsp;' . PMA_formatVariable($name, $value, $variable_doc_links) . '</td>' . '</tr>';
        if ($has_session_value) {
            $output .= '<tr class="var-row' . ($odd_row ? ' odd' : ' even') . '">' . '<td class="var-action"></td>' . '<td class="var-name session">(' . __('Session value') . ')</td>' . '<td class="var-value value">&nbsp;' . PMA_formatVariable($name, $serverVarsSession[$name], $variable_doc_links) . '</td>' . '</tr>';
        }
        $odd_row = !$odd_row;
    }
    $output .= '</tbody>';
    return $output;
}
    /**
     * Test for PMA_getHtmlForServerVariablesItems
     *
     * @return void
     */
    public function testPMAGetHtmlForServerVariablesItems()
    {
        //Call the test function
        $variable_doc_links = PMA_getArrayForDocumentLinks();

        $html = PMA_getHtmlForServerVariablesItems($variable_doc_links);

        //validate 1: variable: auto_increment_increment
        $name = "auto_increment_increment";
        $value = htmlspecialchars(str_replace('_', ' ', $name));
        $this->assertContains(
            $value,
            $html
        );

        //validate 2: variable: auto_increment_offset
        $name = "auto_increment_offset";
        $value = htmlspecialchars(str_replace('_', ' ', $name));
        $this->assertContains(
            $value,
            $html
        );

        $value = PMA_formatVariable($name, "12", $variable_doc_links);
        $this->assertContains(
            $value,
            $html
        );

        //validate 3: variables
        $this->assertContains(
            __('Session value'),
            $html
        );

        $value = PMA_formatVariable($name, "13", $variable_doc_links);
        $this->assertContains(
            $value,
            $html
        );
    }
 /**
  * Test for _getHtmlForServerVariablesItems()
  *
  * @return void
  */
 public function testGetHtmlForServerVariablesItems()
 {
     $class = new ReflectionClass('\\PMA\\libraries\\controllers\\server\\ServerVariablesController');
     $method = $class->getMethod('_getHtmlForServerVariablesItems');
     $method->setAccessible(true);
     $container = Container::getDefaultContainer();
     $container->factory('PMA\\libraries\\controllers\\server\\ServerVariablesController');
     $container->alias('ServerVariablesController', 'PMA\\libraries\\controllers\\server\\ServerVariablesController');
     $ctrl = $container->get('ServerVariablesController');
     $serverVarsSession = $GLOBALS['dbi']->fetchResult('SHOW SESSION VARIABLES;', 0, 1);
     $serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1);
     $html = $method->invoke($ctrl, $serverVars, $serverVarsSession);
     //validate 1: variable: auto_increment_increment
     $name = "auto_increment_increment";
     $value = htmlspecialchars(str_replace('_', ' ', $name));
     $this->assertContains($value, $html);
     //validate 2: variable: auto_increment_offset
     $name = "auto_increment_offset";
     $value = htmlspecialchars(str_replace('_', ' ', $name));
     $this->assertContains($value, $html);
     $value = PMA_formatVariable($name, "12", $variable_doc_links);
     $this->assertContains($value, $html);
     //validate 3: variables
     $this->assertContains(__('Session value'), $html);
     $value = PMA_formatVariable($name, "13", $variable_doc_links);
     $this->assertContains($value, $html);
 }
 /**
  * Test for PMA_getHtmlForServerVariablesItems
  *
  * @return void
  */
 public function testPMAGetHtmlForServerVariablesItems()
 {
     //Call the test function
     $variable_doc_links = PMA_getArrayForDocumentLinks();
     $serverVarsSession = $GLOBALS['dbi']->fetchResult('SHOW SESSION VARIABLES;', 0, 1);
     $serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1);
     $html = PMA_getHtmlForServerVariablesItems($variable_doc_links, $serverVars, $serverVarsSession);
     //validate 1: variable: auto_increment_increment
     $name = "auto_increment_increment";
     $value = htmlspecialchars(str_replace('_', ' ', $name));
     $this->assertContains($value, $html);
     //validate 2: variable: auto_increment_offset
     $name = "auto_increment_offset";
     $value = htmlspecialchars(str_replace('_', ' ', $name));
     $this->assertContains($value, $html);
     $value = PMA_formatVariable($name, "12", $variable_doc_links);
     $this->assertContains($value, $html);
     //validate 3: variables
     $this->assertContains(__('Session value'), $html);
     $value = PMA_formatVariable($name, "13", $variable_doc_links);
     $this->assertContains($value, $html);
 }