From 053b40627b339137fdd18e7d64d9cc823cb7f22c Mon Sep 17 00:00:00 2001 From: adamgsoc2013 Date: Sat, 6 Jul 2013 21:09:26 +0800 Subject: [PATCH 1/3] add Unit Test case for PMA_relation --- test/libraries/PMA_relation_test.php | 95 ++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 test/libraries/PMA_relation_test.php diff --git a/test/libraries/PMA_relation_test.php b/test/libraries/PMA_relation_test.php new file mode 100644 index 0000000000..a6941e29c8 --- /dev/null +++ b/test/libraries/PMA_relation_test.php @@ -0,0 +1,95 @@ +getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('query') + ->will($this->returnValue('executed')); + + $dbi->expects($this->once()) + ->method('tryQuery') + ->will($this->returnValue('executed')); + + $GLOBALS['dbi'] = $dbi; + + $sql = "insert into PMA_bookmark A,B values(1, 2)"; + $this->assertEquals( + 'executed', + PMA_queryAsControlUser($sql) + ); + $this->assertEquals( + 'executed', + PMA_queryAsControlUser($sql, false) + ); + } + + /** + * Test for PMA_getRelationsParam & PMA_getRelationsParamDiagnostic + * + * @return void + */ + public function testPMA_getRelationsParam() + { + $GLOBALS['cfg']['ServerDefault'] = 0; + $_SESSION['relation'] = array(); + $_SESSION['relation'][$GLOBALS['server']]['relwork'] = "relwork"; + $GLOBALS['server'] = "table"; + + $relationsPara = PMA_getRelationsParam(); + $this->assertEquals( + false, + $relationsPara['relwork'] + ); + + $retval = PMA_getRelationsParamDiagnostic($GLOBALS['cfgRelation']); + $this->assertContains( + 'Disabled', + $retval + ); + $this->assertContains( + 'General relation features', + $retval + ); + $this->assertContains( + 'not OK', + $retval + ); + } +} From 0265241228a18d89b37fbaf43a7167eeb9412174 Mon Sep 17 00:00:00 2001 From: adamgsoc2013 Date: Sun, 7 Jul 2013 10:37:45 +0800 Subject: [PATCH 2/3] we don't use tab --- test/libraries/PMA_relation_test.php | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/test/libraries/PMA_relation_test.php b/test/libraries/PMA_relation_test.php index a6941e29c8..3764c1c347 100644 --- a/test/libraries/PMA_relation_test.php +++ b/test/libraries/PMA_relation_test.php @@ -35,20 +35,20 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase */ public function testPMA_queryAsControlUser() { - $dbi = $this->getMockBuilder('PMA_DatabaseInterface') - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->once()) - ->method('query') - ->will($this->returnValue('executed')); - - $dbi->expects($this->once()) - ->method('tryQuery') - ->will($this->returnValue('executed')); - - $GLOBALS['dbi'] = $dbi; - + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->once()) + ->method('query') + ->will($this->returnValue('executed')); + + $dbi->expects($this->once()) + ->method('tryQuery') + ->will($this->returnValue('executed')); + + $GLOBALS['dbi'] = $dbi; + $sql = "insert into PMA_bookmark A,B values(1, 2)"; $this->assertEquals( 'executed', @@ -70,14 +70,14 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['ServerDefault'] = 0; $_SESSION['relation'] = array(); $_SESSION['relation'][$GLOBALS['server']]['relwork'] = "relwork"; - $GLOBALS['server'] = "table"; - - $relationsPara = PMA_getRelationsParam(); + $GLOBALS['server'] = "table"; + + $relationsPara = PMA_getRelationsParam(); $this->assertEquals( false, - $relationsPara['relwork'] + $relationsPara['relwork'] ); - + $retval = PMA_getRelationsParamDiagnostic($GLOBALS['cfgRelation']); $this->assertContains( 'Disabled', From d100971442e3ab81b44672adcf2b559cb35c12b6 Mon Sep 17 00:00:00 2001 From: adamgsoc2013 Date: Mon, 8 Jul 2013 20:49:57 +0800 Subject: [PATCH 3/3] add more case for PMA_relation --- test/libraries/PMA_relation_test.php | 70 +++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/test/libraries/PMA_relation_test.php b/test/libraries/PMA_relation_test.php index 3764c1c347..0e6dc31cc8 100644 --- a/test/libraries/PMA_relation_test.php +++ b/test/libraries/PMA_relation_test.php @@ -10,6 +10,7 @@ * Include to test. */ require_once 'libraries/Util.class.php'; +require_once 'libraries/Theme.class.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/database_interface.inc.php'; require_once 'libraries/Tracker.class.php'; @@ -19,11 +20,14 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase { public function setUp() { - $GLOBALS['server'] = "table"; + $GLOBALS['server'] = 1; $GLOBALS['cfg']['Server']['user'] = 'root'; $GLOBALS['cfg']['Server']['pmadb'] = 'phpmyadmin'; $_SESSION['relation'][$GLOBALS['server']] = "PMA_relation"; - $GLOBALS['server'] = 1; + $_SESSION['PMA_Theme'] = new PMA_Theme(); + + $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath(); + $GLOBALS['pmaThemeImage'] = 'theme/'; include_once 'libraries/relation.lib.php'; } @@ -41,21 +45,21 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase $dbi->expects($this->once()) ->method('query') - ->will($this->returnValue('executed')); + ->will($this->returnValue('executeResult1')); $dbi->expects($this->once()) ->method('tryQuery') - ->will($this->returnValue('executed')); + ->will($this->returnValue('executeResult2')); $GLOBALS['dbi'] = $dbi; $sql = "insert into PMA_bookmark A,B values(1, 2)"; $this->assertEquals( - 'executed', + 'executeResult1', PMA_queryAsControlUser($sql) ); $this->assertEquals( - 'executed', + 'executeResult2', PMA_queryAsControlUser($sql, false) ); } @@ -69,27 +73,69 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase { $GLOBALS['cfg']['ServerDefault'] = 0; $_SESSION['relation'] = array(); - $_SESSION['relation'][$GLOBALS['server']]['relwork'] = "relwork"; - $GLOBALS['server'] = "table"; $relationsPara = PMA_getRelationsParam(); $this->assertEquals( false, $relationsPara['relwork'] ); + $this->assertEquals( + false, + $relationsPara['bookmarkwork'] + ); + $this->assertEquals( + 'root', + $relationsPara['user'] + ); + $this->assertEquals( + 'phpmyadmin', + $relationsPara['db'] + ); - $retval = PMA_getRelationsParamDiagnostic($GLOBALS['cfgRelation']); + $retval = PMA_getRelationsParamDiagnostic($relationsPara); + //check $cfg['Servers'][$i]['pmadb'] $this->assertContains( - 'Disabled', + "\$cfg['Servers'][\$i]['pmadb']", $retval ); $this->assertContains( - 'General relation features', + 'OK', $retval ); + + //$cfg['Servers'][$i]['relation'] + $result = "\$cfg['Servers'][\$i]['pmadb'] ... " + . "OK"; $this->assertContains( - 'not OK', + $result, + $retval + ); + // $cfg['Servers'][$i]['relation'] + $result = "\$cfg['Servers'][\$i]['relation'] ... " + . "not OK"; + $this->assertContains( + $result, + $retval + ); + // General relation features + $result = 'General relation features: Disabled'; + $this->assertContains( + $result, + $retval + ); + // $cfg['Servers'][$i]['table_info'] + $result = "\$cfg['Servers'][\$i]['table_info'] ... " + . "not OK"; + $this->assertContains( + $result, + $retval + ); + // Display Features: + $result = 'Display Features: Disabled'; + $this->assertContains( + $result, $retval ); } } +