diff --git a/db_central_columns.php b/db_central_columns.php index 33078bf24d..71dac4ba03 100644 --- a/db_central_columns.php +++ b/db_central_columns.php @@ -156,7 +156,7 @@ if ($total_rows <= 0) { 'The central list of columns for the current database is empty.' ) . '' ); - $columnAdd = $centralColumns->getHtmlForAddCentralColumn($GLOBALS['dbi'], $total_rows, $pos, $db); + $columnAdd = $centralColumns->getHtmlForAddColumn($GLOBALS['dbi'], $total_rows, $pos, $db); $response->addHTML($columnAdd); exit; } @@ -167,7 +167,7 @@ $table_navigation_html = $centralColumns->getHtmlForTableNavigation( $db ); $response->addHTML($table_navigation_html); -$columnAdd = $centralColumns->getHtmlForAddCentralColumn($GLOBALS['dbi'], $total_rows, $pos, $db); +$columnAdd = $centralColumns->getHtmlForAddColumn($GLOBALS['dbi'], $total_rows, $pos, $db); $response->addHTML($columnAdd); $deleteRowForm = '
' . Url::getHiddenInputs( @@ -195,7 +195,7 @@ $result = $centralColumns->getColumnsList( ); $row_num = 0; foreach ($result as $row) { - $tableHtmlRow = $centralColumns->getHtmlForCentralColumnsTableRow( + $tableHtmlRow = $centralColumns->getHtmlForTableRow( $GLOBALS['dbi'], $GLOBALS['cfg']['MaxRows'], $GLOBALS['cfg']['CharEditing'], diff --git a/libraries/classes/CentralColumns.php b/libraries/classes/CentralColumns.php index cd39897dbc..7ed5d355cb 100644 --- a/libraries/classes/CentralColumns.php +++ b/libraries/classes/CentralColumns.php @@ -138,7 +138,7 @@ class CentralColumns * * @return array list of columns in central columns among given set of columns */ - public function findExistingColNames( + private function findExistingColNames( DatabaseInterface $dbi, $user, $db, @@ -177,7 +177,7 @@ class CentralColumns * * @return Message */ - public function configErrorMessage() + private function configErrorMessage() { return Message::error( __( @@ -200,7 +200,7 @@ class CentralColumns * @return string query string to insert the given column * with definition into central list */ - public function getInsertQuery( + private function getInsertQuery( DatabaseInterface $dbi, $column, array $def, @@ -798,7 +798,7 @@ class CentralColumns * * @return string html for table header in central columns multi edit page */ - public function getEditTableHeader(array $headers) + private function getEditTableHeader(array $headers) { return Template::get( 'database/central_columns/edit_table_header' @@ -815,7 +815,7 @@ class CentralColumns * * @return string html dropdown for selecting table */ - public function getHtmlForTableDropdown(DatabaseInterface $dbi, $db) + private function getHtmlForTableDropdown(DatabaseInterface $dbi, $db) { $dbi->selectDb($db); $tables = $dbi->getTables($db); @@ -873,7 +873,7 @@ class CentralColumns * * @return string html to add a column in the central list */ - public function getHtmlForAddCentralColumn( + public function getHtmlForAddColumn( DatabaseInterface $dbi, $total_rows, $pos, @@ -921,7 +921,7 @@ class CentralColumns * * @return string html of a particular row in the central columns table. */ - public function getHtmlForCentralColumnsTableRow( + public function getHtmlForTableRow( DatabaseInterface $dbi, $maxRows, $charEditing, @@ -1104,7 +1104,7 @@ class CentralColumns * * @return string html of a particular row in the central columns table. */ - public function getHtmlForCentralColumnsEditTableRow( + private function getHtmlForEditTableRow( DatabaseInterface $dbi, $maxRows, $charEditing, @@ -1324,7 +1324,7 @@ class CentralColumns * * @return string html for table footer in central columns multi edit page */ - public function getEditTableFooter() + private function getEditTableFooter() { $html_output = '
' . 'findExistingColNames($dbi, $user, $selected_db, $columns_list, true); $row_num = 0; foreach ($list_detail_cols as $row) { - $tableHtmlRow = $this->getHtmlForCentralColumnsEditTableRow( + $tableHtmlRow = $this->getHtmlForEditTableRow( $dbi, $maxRows, $charEditing, diff --git a/test/classes/CentralColumnsTest.php b/test/classes/CentralColumnsTest.php index 2d37eae346..891c61b6f6 100644 --- a/test/classes/CentralColumnsTest.php +++ b/test/classes/CentralColumnsTest.php @@ -14,6 +14,7 @@ use PhpMyAdmin\Types; use PhpMyAdmin\Url; use PhpMyAdmin\Util; use PHPUnit\Framework\TestCase; +use ReflectionClass; $GLOBALS['server'] = 1; @@ -131,6 +132,29 @@ class CentralColumnsTest extends TestCase $this->centralColumns = new CentralColumns(); } + /** + * Call protected functions by setting visibility to public. + * + * @param string $name method name + * @param array $params parameters for the invocation + * @param CentralColumns $object CentralColumns instance object + * + * @return mixed the output from the protected method. + */ + private function callProtectedMethod( + $name, + array $params = [], + CentralColumns $object = null + ) { + $class = new ReflectionClass(CentralColumns::class); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method->invokeArgs( + $object !== null ? $object : $this->centralColumns, + $params + ); + } + /** * Test for getParams * @@ -461,27 +485,39 @@ class CentralColumnsTest extends TestCase __('Collation'), __('Attributes'), __('Null'), __('A_I') ); $this->assertContains( - $this->centralColumns->getEditTableHeader($header_cells), $result + $this->callProtectedMethod( + 'getEditTableHeader', + [$header_cells] + ), + $result ); - $list_detail_cols = $this->centralColumns->findExistingColNames( - $GLOBALS['dbi'], - $GLOBALS['cfg']['Server']['user'], - 'phpmyadmin', - "'col1','col2'", - true - ); - $this->assertContains( - $this->centralColumns->getHtmlForCentralColumnsEditTableRow( + $list_detail_cols = $this->callProtectedMethod( + 'findExistingColNames', + [ $GLOBALS['dbi'], - $GLOBALS['cfg']['MaxRows'], - $GLOBALS['cfg']['CharEditing'], - $GLOBALS['cfg']['Server']['DisableIS'], - $list_detail_cols[0], - 0 - ), $result + $GLOBALS['cfg']['Server']['user'], + 'phpmyadmin', + "'col1','col2'", + true, + ] ); $this->assertContains( - $this->centralColumns->getEditTableFooter(), $result + $this->callProtectedMethod( + 'getHtmlForEditTableRow', + [ + $GLOBALS['dbi'], + $GLOBALS['cfg']['MaxRows'], + $GLOBALS['cfg']['CharEditing'], + $GLOBALS['cfg']['Server']['DisableIS'], + $list_detail_cols[0], + 0, + ] + ), + $result + ); + $this->assertContains( + $this->callProtectedMethod('getEditTableFooter'), + $result ); } @@ -655,7 +691,7 @@ class CentralColumnsTest extends TestCase { $this->assertInstanceOf( 'PhpMyAdmin\Message', - $this->centralColumns->configErrorMessage() + $this->callProtectedMethod('configErrorMessage') ); } @@ -678,12 +714,15 @@ class CentralColumnsTest extends TestCase ); $this->assertEquals( array_slice($this->_modifiedColumnData, 1, 1), - $this->centralColumns->findExistingColNames( - $GLOBALS['dbi'], - $GLOBALS['cfg']['Server']['user'], - 'phpmyadmin', - "'col1'", - true + $this->callProtectedMethod( + 'findExistingColNames', + [ + $GLOBALS['dbi'], + $GLOBALS['cfg']['Server']['user'], + 'phpmyadmin', + "'col1'", + true, + ] ) ); } @@ -696,7 +735,13 @@ class CentralColumnsTest extends TestCase public function testPMAGetHTMLforTableDropdown() { $db = 'PMA_db'; - $result = $this->centralColumns->getHtmlForTableDropdown($GLOBALS['dbi'], $db); + $result = $this->callProtectedMethod( + 'getHtmlForTableDropdown', + [ + $GLOBALS['dbi'], + $db, + ] + ); $this->assertContains( '