From 26b7d100027d99e0f1841000543d7cdf68d22cbe Mon Sep 17 00:00:00 2001 From: Yasitha Pandithawatta Date: Mon, 2 Jul 2012 00:46:32 +0530 Subject: [PATCH] Test cases for PMA_Footer.class.php --- test/classes/PMA_DisplayResults_test.php | 2 +- test/classes/PMA_Footer_test.php | 167 +++++++++++++++++++++++ 2 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 test/classes/PMA_Footer_test.php diff --git a/test/classes/PMA_DisplayResults_test.php b/test/classes/PMA_DisplayResults_test.php index e1c1be64f0..819e76aa50 100644 --- a/test/classes/PMA_DisplayResults_test.php +++ b/test/classes/PMA_DisplayResults_test.php @@ -352,7 +352,7 @@ class PMA_DisplayResults_test extends PHPUnit_Framework_TestCase } /** - * @return array array data for testGetTableNavigation + * @return array data for testGetTableNavigation */ public function providerForTestGetTableNavigation() { diff --git a/test/classes/PMA_Footer_test.php b/test/classes/PMA_Footer_test.php new file mode 100644 index 0000000000..6f02445086 --- /dev/null +++ b/test/classes/PMA_Footer_test.php @@ -0,0 +1,167 @@ +object = $this->getMockForAbstractClass('PMA_Footer'); + } + + /** + * 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_Footer'); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method->invokeArgs($this->object, $params); + } + + /** + * Test for _getDebugMessage + */ + public function testGetDebugMessage(){ + + $_SESSION['debug']['queries'] = array('SELECT * FROM `pma_bookmark` WHERE 1', 'SELECT * FROM `db` WHERE 1'); + + $this->assertEquals( + $this->_callPrivateFunction( + '_getDebugMessage', + array() + ), + '
2 queries executed 0 times in 0 seconds
Array
+(
+    [queries] => Array
+        (
+            [0] => SELECT * FROM `pma_bookmark` WHERE 1
+            [1] => SELECT * FROM `db` WHERE 1
+        )
+
+)
+
' + ); + } + + /** + * Test for _getSelfLink + */ + public function testGetSelfLink(){ + + $GLOBALS['cfg']['NavigationBarIconic'] = false; + $GLOBALS['cfg']['ServerDefault'] = 1; + + $this->assertEquals( + $this->_callPrivateFunction( + '_getSelfLink', + array('db=mysql&token=1234') + ), + '' + ); + } + + /** + * Test for _getSelfLink + */ + public function testGetSelfLinkWithImage(){ + + $GLOBALS['cfg']['NavigationBarIconic'] = true; + $GLOBALS['cfg']['ServerDefault'] = 1; + $_SESSION['PMA_Theme'] = new PMA_Theme(); + $GLOBALS['pmaThemeImage'] = 'image'; + + $this->assertEquals( + $this->_callPrivateFunction( + '_getSelfLink', + array('db=mysql&token=1234') + ), + '' + ); + } + +// /** +// * Test for disable +// */ +// public function testDisable(){ +// +// $GLOBALS['lang'] = 'en'; +// $GLOBALS['collation_connection'] = 'utf8_general_ci'; +// $GLOBALS['server'] = '1'; +// $_SESSION[' PMA_token '] = 'token'; +// $GLOBALS['reload'] = '1'; +// $GLOBALS['focus_querywindow'] = 'main_pane_left'; +// +// $footer = new PMA_Footer(); +// +// $class = get_class( $footer ); +// $reflection = new ReflectionClass( $class ); +// $priv_attr = $reflection->getProperties( ReflectionProperty::IS_PRIVATE ); +// $privates = array(); +// $parseable = unserialize(str_replace("\0$class\0", "\0*\0", serialize($footer))); +// foreach($priv_attr as $attribute) +// { +// $aname = $attribute->name; +// $privates[$aname] = $parseable->$aname; +// } +// +// $this->assertFalse($priv_attr[3]->_isEnable); +// } +}