From d25eeb45875256f19418b84a3948afe576ca6dd0 Mon Sep 17 00:00:00 2001 From: Piyush Agrawal Date: Sun, 29 Jan 2017 22:44:11 +0530 Subject: [PATCH 1/2] templating getRadioFields(), getDropDown() in Util.php Signed-off-by: Piyush Agrawal --- libraries/Util.php | 92 +++++++++---------- templates/dropdown.phtml | 8 ++ templates/radio_fields.phtml | 11 +++ test/classes/DbSearchTest.php | 8 +- test/libraries/PMA_server_privileges_test.php | 30 +++--- .../libraries/common/PMA_getDropdown_test.php | 12 ++- .../common/PMA_getRadioFields_test.php | 10 ++ 7 files changed, 104 insertions(+), 67 deletions(-) create mode 100644 templates/dropdown.phtml create mode 100644 templates/radio_fields.phtml diff --git a/libraries/Util.php b/libraries/Util.php index b24a5c083b..65ae091d87 100644 --- a/libraries/Util.php +++ b/libraries/Util.php @@ -2604,40 +2604,49 @@ class Util foreach ($choices as $choice_value => $choice_label) { - if (! empty($class)) { - $radio_html .= '
'; - } - if (! $id_prefix) { $id_prefix = $html_field_name; } $html_field_id = $id_prefix . '_' . $choice_value; - $radio_html .= '' - . ($escape_label - ? htmlspecialchars($choice_label) - : $choice_label) - . ''; + if ($choice_value == $checked_choice) + $checked = 1; + else + $checked = 0; - if ($line_break) { - $radio_html .= '
'; - } + // $radio_html .= ' />' . "\n" + // . ''; - if (! empty($class)) { - $radio_html .= '
'; - } - $radio_html .= "\n"; + // if ($line_break) { + // $radio_html .= '
'; + // } + + // if (! empty($class)) { + // $radio_html .= ''; + // } + // $radio_html .= "\n"; + $radio_html .= Template::get('radio_fields')->render([ + 'class' => $class, + 'html_field_name' => $html_field_name, + 'html_field_id' => $html_field_id, + 'choice_value' => $choice_value, + 'is_line_break' => $line_break, + 'choice_label' => $choice_label, + 'escape_label' => $escape_label, + 'checked' => $checked + ]); } return $radio_html; + } /** @@ -2660,38 +2669,27 @@ class Util public static function getDropdown( $select_name, $choices, $active_choice, $id, $class = '', $placeholder = null ) { - $result = ''; - - $resultOptions = ''; + $resultOptions = []; $selected = false; foreach ($choices as $one_choice_value => $one_choice_label) { - $resultOptions .= '' - . $resultOptions; - } - - $result .= $resultOptions - . ''; - - return $result; + return Template::get('dropdown')->render([ + 'select_name' => $select_name, + 'id' => $id, + 'class' => $class, + 'placeholder' => $placeholder, + 'selected' => $selected, + 'resultOptions' => $resultOptions, + ]); } /** diff --git a/templates/dropdown.phtml b/templates/dropdown.phtml new file mode 100644 index 0000000000..831f8745d9 --- /dev/null +++ b/templates/dropdown.phtml @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/templates/radio_fields.phtml b/templates/radio_fields.phtml new file mode 100644 index 0000000000..8faaa4d395 --- /dev/null +++ b/templates/radio_fields.phtml @@ -0,0 +1,11 @@ + +
+ + /> + + +
+ + +
+ \ No newline at end of file diff --git a/test/classes/DbSearchTest.php b/test/classes/DbSearchTest.php index 0cca012cb4..98add2b51c 100644 --- a/test/classes/DbSearchTest.php +++ b/test/classes/DbSearchTest.php @@ -204,23 +204,23 @@ class DbSearchTest extends PMATestCase . '
' . "\n" + . '' . "\n" . '
' . "\n" . '' . "\n" . '
' . "\n" + . '' . "\n" . '
' . "\n" . '' . "\n" - . '
' + . '' . "\n" . '
' . "\n" . '' . "\n" . '
' . "\n" + . ' alt="Documentation" class="icon ic_b_help" />' . "\n" . '
' . "\n" . 'Inside tables:' . '' + '', + . 'Native MySQL authentication' + . "\n" + . '' . "\n" . '', $actualHtml ); @@ -2544,10 +2547,12 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase ); $this->assertEquals( '', + . 'Native MySQL authentication' + . "\n" . '' . "\n" . '', $actualHtml ); @@ -2559,9 +2564,10 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase ); $this->assertEquals( '', + . 'Native MySQL authentication'. "\n" .'', $actualHtml ); @@ -2574,9 +2580,11 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase ); $this->assertEquals( '', + . 'id="select_authentication_plugin_cp" >' + . "\n" + . '' + . "\n" . '', $actualHtml ); diff --git a/test/libraries/common/PMA_getDropdown_test.php b/test/libraries/common/PMA_getDropdown_test.php index 40974f184b..107c1f686d 100644 --- a/test/libraries/common/PMA_getDropdown_test.php +++ b/test/libraries/common/PMA_getDropdown_test.php @@ -33,7 +33,7 @@ class PMA_GetDropdownTest extends PHPUnit_Framework_TestCase $id = "test_<dropdown>_name"; $result = ''; + . htmlspecialchars($id) . '" >' . "\n" . ''; $this->assertEquals( $result, @@ -56,15 +56,15 @@ class PMA_GetDropdownTest extends PHPUnit_Framework_TestCase $id = "test_<dropdown>_name"; $result = ''; + $result .= "\n" . ''; $this->assertEquals( $result, @@ -87,14 +87,16 @@ class PMA_GetDropdownTest extends PHPUnit_Framework_TestCase $id = "test_<dropdown>_name"; $result = ''; $this->assertEquals( diff --git a/test/libraries/common/PMA_getRadioFields_test.php b/test/libraries/common/PMA_getRadioFields_test.php index 734cce495a..6e60d9d29d 100644 --- a/test/libraries/common/PMA_getRadioFields_test.php +++ b/test/libraries/common/PMA_getRadioFields_test.php @@ -54,6 +54,7 @@ class PMA_GetRadioFieldsTest extends PHPUnit_Framework_TestCase $out .= ' />' . "\n"; $out .= ''; + $out .= "\n"; $out .= '
'; $out .= "\n"; } @@ -86,6 +87,7 @@ class PMA_GetRadioFieldsTest extends PHPUnit_Framework_TestCase $out .= ' />' . "\n"; $out .= ''; + $out .= "\n"; $out .= '
'; $out .= "\n"; } @@ -114,6 +116,7 @@ class PMA_GetRadioFieldsTest extends PHPUnit_Framework_TestCase foreach ($choices as $choice_value => $choice_label) { $html_field_id = $name . '_' . $choice_value; $out .= '
'; + $out .= "\n"; $out .= '' . $choice_label . ''; + $out .= "\n"; $out .= '
'; + $out .= "\n"; $out .= '
'; $out .= "\n"; } @@ -190,6 +195,7 @@ class PMA_GetRadioFieldsTest extends PHPUnit_Framework_TestCase $out .= ' />' . "\n"; $out .= ''; + $out .= "\n"; $out .= '
'; $out .= "\n"; } @@ -224,6 +230,7 @@ class PMA_GetRadioFieldsTest extends PHPUnit_Framework_TestCase $out .= ' />' . "\n"; $out .= ''; + $out .= "\n"; $out .= '
'; $out .= "\n"; } @@ -252,6 +259,7 @@ class PMA_GetRadioFieldsTest extends PHPUnit_Framework_TestCase foreach ($choices as $choice_value => $choice_label) { $html_field_id = $name . '_' . $choice_value; $out .= '
'; + $out .= "\n"; $out .= '' . htmlspecialchars($choice_label) . ''; + $out .= "\n"; $out .= '
'; + $out .= "\n"; $out .= '
'; $out .= "\n"; } From 60dc48155abc9c408373e02050b295ebe1211e17 Mon Sep 17 00:00:00 2001 From: Piyush Agrawal Date: Wed, 22 Feb 2017 14:53:13 +0530 Subject: [PATCH 2/2] comments removed, if-else brackets added Signed-off-by: Piyush Agrawal --- libraries/Util.php | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/libraries/Util.php b/libraries/Util.php index 65ae091d87..fae03df49b 100644 --- a/libraries/Util.php +++ b/libraries/Util.php @@ -2609,30 +2609,12 @@ class Util } $html_field_id = $id_prefix . '_' . $choice_value; - // $radio_html .= '' - // . ($escape_label - // ? htmlspecialchars($choice_label) - // : $choice_label) - // . ''; - - // if ($line_break) { - // $radio_html .= '
'; - // } - - // if (! empty($class)) { - // $radio_html .= ''; - // } - // $radio_html .= "\n"; + } $radio_html .= Template::get('radio_fields')->render([ 'class' => $class, 'html_field_name' => $html_field_name,