From 89600d7b1b1947b679c4070b202a678677bf8b4a Mon Sep 17 00:00:00 2001 From: Yasitha Pandithawatta Date: Thu, 28 Jun 2012 22:29:47 +0530 Subject: [PATCH 1/2] test cases for DisplayResults.class.php --- test/classes/PMA_DisplayResults_test.php | 371 ++++++++++++++++++ .../core/PMA_getTableCount_test_dis.php | 27 +- .../core/PMA_headerLocation_test_disabled.php | 11 +- 3 files changed, 406 insertions(+), 3 deletions(-) create mode 100644 test/classes/PMA_DisplayResults_test.php diff --git a/test/classes/PMA_DisplayResults_test.php b/test/classes/PMA_DisplayResults_test.php new file mode 100644 index 0000000000..0f5ed2c8b5 --- /dev/null +++ b/test/classes/PMA_DisplayResults_test.php @@ -0,0 +1,371 @@ +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', + '
' + ) + ); + } + + /** + * @param integer $pos_next the offset for the "next" page + * @param integer $pos_prev the offset for the "previous" page + * @param string $id_for_direction_dropdown the id for the direction dropdown + * @param $output output from the _getTableNavigation method + * + * @dataProvider providerForTestGetTableNavigation + */ + public function testGetTableNavigation($pos_next, $pos_prev, $id_for_direction_dropdown, $output){ + + $_SESSION['tmp_user_values']['max_rows'] = '20'; + $GLOBALS['cfg']['AjaxEnable'] = true; + $_SESSION['tmp_user_values']['pos'] = true; + $GLOBALS['num_rows'] = '20'; + $GLOBALS['unlim_num_rows'] = '50'; + $GLOBALS['cfg']['ShowAll'] = true; + $GLOBALS['cfg']['ShowDisplayDirection'] = true; + $_SESSION['tmp_user_values']['repeat_cells'] = '1'; + $_SESSION['tmp_user_values']['disp_direction'] = '1'; + + $this->assertEquals( + str_word_count($this->_callPrivateFunction( + '_getTableNavigation', + array($pos_next, $pos_prev, $id_for_direction_dropdown) + )), + $output + ); + } + + /** + * @return array array data for testGetTableNavigation + */ + public function providerForTestGetTableNavigation() + { + return array( + array( + 21, + 41, + '123', + '526' + ) + ); + } + +} diff --git a/test/libraries/core/PMA_getTableCount_test_dis.php b/test/libraries/core/PMA_getTableCount_test_dis.php index aa9af73708..246a17152a 100644 --- a/test/libraries/core/PMA_getTableCount_test_dis.php +++ b/test/libraries/core/PMA_getTableCount_test_dis.php @@ -10,12 +10,23 @@ /* * Include to test. */ + +require_once 'libraries/vendor_config.php'; +require_once 'libraries/Theme.class.php'; require_once 'libraries/core.lib.php'; + require_once 'libraries/common.lib.php'; +require_once 'libraries/js_escape.lib.php'; +require_once 'libraries/select_lang.lib.php'; +require_once 'libraries/sanitizing.lib.php'; require_once 'libraries/config.default.php'; require_once 'libraries/Config.class.php'; + +require_once 'libraries/url_generating.lib.php'; + +require_once 'libraries/Table.class.php'; require_once 'libraries/database_interface.lib.php'; -require_once 'libraries/vendor_config.php'; +require_once 'libraries/php-gettext/gettext.inc'; require_once 'config.sample.inc.php'; @@ -24,6 +35,20 @@ class PMA_getTableCount_test extends PHPUnit_Framework_TestCase public function setUp() { $GLOBALS['PMA_Config'] = new PMA_Config(); + $GLOBALS['PMA_Config']->enableBc(); +// $GLOBALS['cfg']['Server'] = array( +// 'host' => 'host', +// 'verbose' => 'verbose', +// 'extension' => 'mysql' +// ); + $GLOBALS['cfg']['OBGzip'] = false; + $_SESSION['PMA_Theme'] = new PMA_Theme(); + $_SESSION[' PMA_token '] = 'token'; + $GLOBALS['pmaThemeImage'] = 'theme/'; + $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath(); + $GLOBALS['server'] = 1; + $GLOBALS['db'] = ''; + $GLOBALS['table'] = ''; } function testTableCount() diff --git a/test/libraries/core/PMA_headerLocation_test_disabled.php b/test/libraries/core/PMA_headerLocation_test_disabled.php index 4869483b40..78bd7309b0 100644 --- a/test/libraries/core/PMA_headerLocation_test_disabled.php +++ b/test/libraries/core/PMA_headerLocation_test_disabled.php @@ -9,10 +9,17 @@ /* * Include to test. */ -require_once 'libraries/common.lib.php'; -require_once 'libraries/url_generating.lib.php'; +require_once 'libraries/vendor_config.php'; require_once 'libraries/core.lib.php'; +require_once 'libraries/common.lib.php'; +require_once 'libraries/js_escape.lib.php'; require_once 'libraries/select_lang.lib.php'; +require_once 'libraries/sanitizing.lib.php'; +require_once 'libraries/Config.class.php'; +require_once 'libraries/url_generating.lib.php'; +require_once 'libraries/Theme.class.php'; +require_once 'libraries/Table.class.php'; +require_once 'libraries/php-gettext/gettext.inc'; /** * Test function sending headers. From 149fa8400f6e8a0f2baff0a1f00ef3c7130d23c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jun 2012 09:19:02 +0200 Subject: [PATCH 2/2] Adjust docs headers --- test/classes/PMA_DisplayResults_test.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/classes/PMA_DisplayResults_test.php b/test/classes/PMA_DisplayResults_test.php index 0f5ed2c8b5..e1c1be64f0 100644 --- a/test/classes/PMA_DisplayResults_test.php +++ b/test/classes/PMA_DisplayResults_test.php @@ -1,10 +1,8 @@