diff --git a/test/classes/PMA_DisplayResults_test.php b/test/classes/PMA_DisplayResults_test.php new file mode 100644 index 0000000000..e1c1be64f0 --- /dev/null +++ b/test/classes/PMA_DisplayResults_test.php @@ -0,0 +1,369 @@ +object = $this->getMockForAbstractClass('PMA_DisplayResults', array('as', '','','')); + + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + * + * @access protected + * @return void + */ + protected function tearDown() + { + unset($this->object); + } + + /** + * Call private functions by making the visibitlity to public. + * + * @param string $name method name + * @param array $params parameters for the invocation + * + * @return the output from the private method. + */ + private function _callPrivateFunction($name, $params) + { + $class = new ReflectionClass('PMA_DisplayResults'); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method->invokeArgs($this->object, $params); + } + + /** + * @param $the_disp_mode string the synthetic value for display_mode (see a few lines above for explanations) + * @param $the_total the total number of rows returned by the SQL + * query without any programmatically appended + * LIMIT clause + * (just a copy of $unlim_num_rows if it exists, + * elsecomputed inside this function) + * + * @param $output output from the _setDisplayMode method + * + * @dataProvider providerForTestSetDisplayModeCase1 + */ + public function testSetDisplayModeCase1($the_disp_mode, $the_total, $output){ + + $GLOBALS['is_count'] = true; + $GLOBALS['is_maint'] = true; + + $this->assertEquals( + $this->_callPrivateFunction( + '_setDisplayMode', + array(&$the_disp_mode, &$the_total) + ), + $output + ); + } + + /** + * @return array data for testSetDisplayModeCase1 + */ + public function providerForTestSetDisplayModeCase1() + { + return array( + array( + 'urkp111111', + 5, + array( + 'edit_lnk' => 'nn', + 'del_lnk' => 'nn', + 'sort_lnk' => 0, + 'nav_bar' => 0, + 'ins_row' => 0, + 'bkm_form' => 1, + 'text_btn' => 1, + 'pview_lnk' => 1 + ) + ), + array( + 'nnnn000000', + 5, + array( + 'edit_lnk' => 'nn', + 'del_lnk' => 'nn', + 'sort_lnk' => 0, + 'nav_bar' => 0, + 'ins_row' => 0, + 'bkm_form' => 0, + 'text_btn' => 0, + 'pview_lnk' => 0 + ) + ) + ); + } + + /** + * @param $the_disp_mode string the synthetic value for display_mode (see a few lines above for explanations) + * @param $the_total the total number of rows returned by the SQL + * query without any programmatically appended + * LIMIT clause + * (just a copy of $unlim_num_rows if it exists, + * elsecomputed inside this function) + * + * @param $output output from the _setDisplayMode method + * + * @dataProvider providerForTestSetDisplayModeCase2 + */ + public function testSetDisplayModeCase2($the_disp_mode, $the_total, $output){ + + + $GLOBALS['is_count'] = false; + $GLOBALS['is_maint'] = false; + $GLOBALS['is_analyse'] = false; + $GLOBALS['is_explain'] = false; + $GLOBALS['is_show'] = true; + $GLOBALS['sql_query'] = 'SELECT * FROM `pma_bookmark` WHERE 1'; + $GLOBALS['unlim_num_rows'] = 1; + + $this->assertEquals( + $this->_callPrivateFunction( + '_setDisplayMode', + array(&$the_disp_mode, &$the_total) + ), + $output + ); + } + + /** + * @return array data for testSetDisplayModeCase2 + */ + public function providerForTestSetDisplayModeCase2() + { + return array( + array( + 'urkp111111', + 5, + array( + 'edit_lnk' => 'nn', + 'del_lnk' => 'nn', + 'sort_lnk' => 0, + 'nav_bar' => 0, + 'ins_row' => 0, + 'bkm_form' => 1, + 'text_btn' => 1, + 'pview_lnk' => 1 + ) + ), + array( + 'nnnn000000', + 5, + array( + 'edit_lnk' => 'nn', + 'del_lnk' => 'nn', + 'sort_lnk' => 0, + 'nav_bar' => 0, + 'ins_row' => 0, + 'bkm_form' => 0, + 'text_btn' => 0, + 'pview_lnk' => 0 + ) + ) + ); + } + + /** + * @param $the_disp_mode string the synthetic value for display_mode (see a few lines above for explanations) + * @param $the_total the total number of rows returned by the SQL + * query without any programmatically appended + * LIMIT clause + * (just a copy of $unlim_num_rows if it exists, + * elsecomputed inside this function) + * + * @param $output output from the _setDisplayMode method + * + * @dataProvider providerForTestSetDisplayModeCase3 + */ + public function testSetDisplayModeCase3($the_disp_mode, $the_total, $output){ + + $GLOBALS['is_count'] = false; + $GLOBALS['is_maint'] = false; + $GLOBALS['is_analyse'] = false; + $GLOBALS['is_explain'] = false; + $GLOBALS['printview'] = '1'; + + $this->assertEquals( + $this->_callPrivateFunction( + '_setDisplayMode', + array(&$the_disp_mode, &$the_total) + ), + $output + ); + } + + /** + * @return array data for testSetDisplayModeCase3 + */ + public function providerForTestSetDisplayModeCase3() + { + return array( + array( + 'urkp111111', + 5, + array( + 'edit_lnk' => 'nn', + 'del_lnk' => 'nn', + 'sort_lnk' => 0, + 'nav_bar' => 0, + 'ins_row' => 0, + 'bkm_form' => 0, + 'text_btn' => 0, + 'pview_lnk' => 0 + ) + ), + array( + 'nnnn000000', + 5, + array( + 'edit_lnk' => 'nn', + 'del_lnk' => 'nn', + 'sort_lnk' => 0, + 'nav_bar' => 0, + 'ins_row' => 0, + 'bkm_form' => 0, + 'text_btn' => 0, + 'pview_lnk' => 0 + ) + ) + ); + } + + /** + * Test for _isSelect function + */ + public function testisSelect(){ + + $GLOBALS['is_count'] = false; + $GLOBALS['is_export'] = false; + $GLOBALS['is_func'] = false; + $GLOBALS['is_analyse'] = false; + $GLOBALS['analyzed_sql'][0]['select_expr'] = array(); + $GLOBALS['analyzed_sql'][0]['queryflags']['select_from'] = 'pma'; + $GLOBALS['analyzed_sql'][0]['table_ref'] = array('table_ref'); + + $this->assertTrue( + $this->_callPrivateFunction( + '_isSelect', + array() + ) + ); + } + + /** + * @param string $caption iconic caption for button + * @param string $title text for button + * @param integer $pos position for next query + * @param string $html_sql_query query ready for display + * @param $output output from the _getTableNavigationButton method + * + * @dataProvider providerForTestGetTableNavigationButton + */ + public function testGetTableNavigationButton($caption, $title, $pos, $html_sql_query, $output){ + + $GLOBALS['cfg']['NavigationBarIconic'] = true; + $GLOBALS['cfg']['AjaxEnable'] = true; + $_SESSION[' PMA_token '] = 'token'; + + $this->assertEquals( + $this->_callPrivateFunction( + '_getTableNavigationButton', + array(&$caption, $title, $pos, $html_sql_query) + ), + $output + ); + } + + /** + * @return array array data for testGetTableNavigationButton + */ + public function providerForTestGetTableNavigationButton() + { + return array( + array( + 'btn', + 'Submit', + 1, + 'SELECT * FROM `pma_bookmark` WHERE 1', + '