From eb54c43fb646c45f526bf61a56e27e2372e15bc4 Mon Sep 17 00:00:00 2001 From: osaid Date: Sat, 24 Dec 2016 22:31:38 +0530 Subject: [PATCH 01/10] Removed PMA_TEST_HEADERS checking as they have been defined --- .../core/PMA_headerLocation_test.php | 48 ++++++------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/test/libraries/core/PMA_headerLocation_test.php b/test/libraries/core/PMA_headerLocation_test.php index 442d983cc0..bf07ffceb7 100644 --- a/test/libraries/core/PMA_headerLocation_test.php +++ b/test/libraries/core/PMA_headerLocation_test.php @@ -61,29 +61,20 @@ class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase */ public function testSendHeaderLocationWithoutSidWithIis() { - if (defined('PMA_TEST_HEADERS')) { + $GLOBALS['PMA_Config']->set('PMA_IS_IIS', true); - $GLOBALS['PMA_Config']->set('PMA_IS_IIS', true); + $testUri = 'https://example.com/test.php'; - $testUri = 'https://example.com/test.php'; + $header = array('Location: ' . $testUri); + PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] + $this->assertEquals($header, $GLOBALS['header']); - $header = array('Location: ' . $testUri); - PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] - $this->assertEquals($header, $GLOBALS['header']); - - //reset $GLOBALS['header'] for the next assertion - unset($GLOBALS['header']); - - $header = array('Refresh: 0; ' . $testUri); - PMA_sendHeaderLocation($testUri, true); // sets $GLOBALS['header'] - $this->assertEquals($header, $GLOBALS['header']); - - } else { - $this->markTestSkipped( - 'Cannot redefine constant/function - missing runkit extension' - ); - } + //reset $GLOBALS['header'] for the next assertion + unset($GLOBALS['header']); + $header = array('Refresh: 0; ' . $testUri); + PMA_sendHeaderLocation($testUri, true); // sets $GLOBALS['header'] + $this->assertEquals($header, $GLOBALS['header']); } /** @@ -93,20 +84,11 @@ class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase */ public function testSendHeaderLocationWithoutSidWithoutIis() { - if (defined('PMA_TEST_HEADERS')) { - - $testUri = 'https://example.com/test.php'; - $header = array('Location: ' . $testUri); - - PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] - $this->assertEquals($header, $GLOBALS['header']); - - } else { - $this->markTestSkipped( - 'Cannot redefine constant/function - missing runkit extension' - ); - } + $testUri = 'https://example.com/test.php'; + $header = array('Location: ' . $testUri); + PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] + $this->assertEquals($header, $GLOBALS['header']); } /** @@ -171,4 +153,4 @@ class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase $attrInstance->setValue($restoreInstance); } -} +} \ No newline at end of file From 2a62427b67bfa2561e6b6184e194b543a02dc71a Mon Sep 17 00:00:00 2001 From: osaid Date: Tue, 3 Jan 2017 22:23:40 +0530 Subject: [PATCH 02/10] added mockResponse function for sharing code and used it in headerlocationtest Signed-Off-By: Osaid --- test/PMATestCase.php | 29 +++++++++++++++++++ .../core/PMA_headerLocation_test.php | 10 +++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/test/PMATestCase.php b/test/PMATestCase.php index 6a13ed3fe2..42634405b4 100644 --- a/test/PMATestCase.php +++ b/test/PMATestCase.php @@ -21,4 +21,33 @@ class PMATestCase extends PHPUnit_Framework_TestCase require 'libraries/config.default.php'; $GLOBALS['cfg'] = $cfg; } + /** + * Creates mock of Response object + * + * @param string $param parameter for header method + * + * @return void + */ + public static function mockResponse($param) + { + $restoreInstance = PMA\libraries\Response::getInstance(); + + $mockResponse = $this->getMockBuilder('PMA\libraries\Response') + ->disableOriginalConstructor() + ->setMethods(array('header', 'headersSent')) + ->getMock(); + + $mockResponse->expects($this->once()) + ->method('header') + ->with($param); + + $mockResponse->expects($this->any()) + ->method('headersSent') + ->with() + ->will($this->returnValue(false)); + + $attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance'); + $attrInstance->setAccessible(true); + $attrInstance->setValue($mockResponse); + } } \ No newline at end of file diff --git a/test/libraries/core/PMA_headerLocation_test.php b/test/libraries/core/PMA_headerLocation_test.php index bf07ffceb7..e6005ff1d1 100644 --- a/test/libraries/core/PMA_headerLocation_test.php +++ b/test/libraries/core/PMA_headerLocation_test.php @@ -12,6 +12,7 @@ use PMA\libraries\Theme; use PMA\libraries\URL; use PMA\libraries\Sanitize; +use PMA\test\PMATestCase; /** * Test function sending headers. @@ -65,16 +66,14 @@ class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase $testUri = 'https://example.com/test.php'; - $header = array('Location: ' . $testUri); PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] - $this->assertEquals($header, $GLOBALS['header']); + PMATestCase::mockResponse('Location: ' . $testUri); //reset $GLOBALS['header'] for the next assertion unset($GLOBALS['header']); - $header = array('Refresh: 0; ' . $testUri); PMA_sendHeaderLocation($testUri, true); // sets $GLOBALS['header'] - $this->assertEquals($header, $GLOBALS['header']); + PMATestCase::mockResponse('Refresh: 0; ' . $testUri); } /** @@ -85,10 +84,9 @@ class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase public function testSendHeaderLocationWithoutSidWithoutIis() { $testUri = 'https://example.com/test.php'; - $header = array('Location: ' . $testUri); PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] - $this->assertEquals($header, $GLOBALS['header']); + PMATestCase::mockResponse('Location: ' . $testUri); } /** From 1616ecb79b3dbe973b5999ed19d0c482d989f384 Mon Sep 17 00:00:00 2001 From: osaid Date: Wed, 4 Jan 2017 10:59:07 +0530 Subject: [PATCH 03/10] headerlocation_test inherits from PMATestCase Signed-off-by: osaid --- test/libraries/core/PMA_headerLocation_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libraries/core/PMA_headerLocation_test.php b/test/libraries/core/PMA_headerLocation_test.php index e6005ff1d1..ac9fb0498b 100644 --- a/test/libraries/core/PMA_headerLocation_test.php +++ b/test/libraries/core/PMA_headerLocation_test.php @@ -34,7 +34,7 @@ use PMA\test\PMATestCase; * @package PhpMyAdmin-test */ -class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase +class PMA_HeaderLocation_Test extends PMATestCase { protected $runkitExt; From f1863bf6ac0f20e586b3a8185889e08c6830af92 Mon Sep 17 00:00:00 2001 From: osaid Date: Wed, 4 Jan 2017 15:21:02 +0530 Subject: [PATCH 04/10] calling class method using Signed-off-by: osaid --- test/libraries/core/PMA_headerLocation_test.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/libraries/core/PMA_headerLocation_test.php b/test/libraries/core/PMA_headerLocation_test.php index ac9fb0498b..f33308c988 100644 --- a/test/libraries/core/PMA_headerLocation_test.php +++ b/test/libraries/core/PMA_headerLocation_test.php @@ -12,7 +12,6 @@ use PMA\libraries\Theme; use PMA\libraries\URL; use PMA\libraries\Sanitize; -use PMA\test\PMATestCase; /** * Test function sending headers. @@ -67,13 +66,13 @@ class PMA_HeaderLocation_Test extends PMATestCase $testUri = 'https://example.com/test.php'; PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] - PMATestCase::mockResponse('Location: ' . $testUri); + $this->mockResponse('Location: ' . $testUri); //reset $GLOBALS['header'] for the next assertion unset($GLOBALS['header']); PMA_sendHeaderLocation($testUri, true); // sets $GLOBALS['header'] - PMATestCase::mockResponse('Refresh: 0; ' . $testUri); + $this->mockResponse('Refresh: 0; ' . $testUri); } /** @@ -86,7 +85,7 @@ class PMA_HeaderLocation_Test extends PMATestCase $testUri = 'https://example.com/test.php'; PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] - PMATestCase::mockResponse('Location: ' . $testUri); + $this->mockResponse('Location: ' . $testUri); } /** From 0f3b55c81abefdd2710b5127b195d45f6ab75035 Mon Sep 17 00:00:00 2001 From: osaid Date: Thu, 5 Jan 2017 21:08:43 +0530 Subject: [PATCH 05/10] made mock before testing function Signed-off-by: osaid --- test/libraries/core/PMA_headerLocation_test.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/libraries/core/PMA_headerLocation_test.php b/test/libraries/core/PMA_headerLocation_test.php index f33308c988..0bbc0b822e 100644 --- a/test/libraries/core/PMA_headerLocation_test.php +++ b/test/libraries/core/PMA_headerLocation_test.php @@ -65,14 +65,11 @@ class PMA_HeaderLocation_Test extends PMATestCase $testUri = 'https://example.com/test.php'; - PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] $this->mockResponse('Location: ' . $testUri); + PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] - //reset $GLOBALS['header'] for the next assertion - unset($GLOBALS['header']); - - PMA_sendHeaderLocation($testUri, true); // sets $GLOBALS['header'] $this->mockResponse('Refresh: 0; ' . $testUri); + PMA_sendHeaderLocation($testUri, true); // sets $GLOBALS['header'] } /** @@ -84,8 +81,8 @@ class PMA_HeaderLocation_Test extends PMATestCase { $testUri = 'https://example.com/test.php'; - PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] $this->mockResponse('Location: ' . $testUri); + PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] } /** From 149916cbda5220830129a953c51abf8adbd262f4 Mon Sep 17 00:00:00 2001 From: osaid Date: Thu, 5 Jan 2017 21:42:48 +0530 Subject: [PATCH 06/10] making method non-static --- test/PMATestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/PMATestCase.php b/test/PMATestCase.php index 42634405b4..2b00ed97b3 100644 --- a/test/PMATestCase.php +++ b/test/PMATestCase.php @@ -28,7 +28,7 @@ class PMATestCase extends PHPUnit_Framework_TestCase * * @return void */ - public static function mockResponse($param) + public function mockResponse($param) { $restoreInstance = PMA\libraries\Response::getInstance(); From 02125d2fc999802f5491ab3a4152153add0ca7b6 Mon Sep 17 00:00:00 2001 From: osaid Date: Fri, 6 Jan 2017 14:12:44 +0530 Subject: [PATCH 07/10] restoring instance after mock object is used Signed-off-by: osaid --- test/PMATestCase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/PMATestCase.php b/test/PMATestCase.php index 2b00ed97b3..c20e04fb67 100644 --- a/test/PMATestCase.php +++ b/test/PMATestCase.php @@ -49,5 +49,6 @@ class PMATestCase extends PHPUnit_Framework_TestCase $attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue($mockResponse); + $attrInstance->setValue($restoreInstance); } } \ No newline at end of file From 887b66169010b8e77ab978c8a4518026e2a3997a Mon Sep 17 00:00:00 2001 From: osaid Date: Sat, 7 Jan 2017 16:11:32 +0530 Subject: [PATCH 08/10] added tearDown method for header tests Signed-off-by: osaid --- test/PMATestCase.php | 18 +++++++----------- .../libraries/core/PMA_headerLocation_test.php | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/test/PMATestCase.php b/test/PMATestCase.php index c20e04fb67..e4a690725b 100644 --- a/test/PMATestCase.php +++ b/test/PMATestCase.php @@ -6,13 +6,10 @@ * @package PhpMyAdmin-test */ -/** - * Base class for phpMyAdmin tests. - * - * @package PhpMyAdmin-test - */ class PMATestCase extends PHPUnit_Framework_TestCase { + public $restoreInstance; + public $attrInstance; /** * This method is called before the first test of this test class is run. */ @@ -22,7 +19,7 @@ class PMATestCase extends PHPUnit_Framework_TestCase $GLOBALS['cfg'] = $cfg; } /** - * Creates mock of Response object + * Creates mock of Response object for header testing * * @param string $param parameter for header method * @@ -30,7 +27,7 @@ class PMATestCase extends PHPUnit_Framework_TestCase */ public function mockResponse($param) { - $restoreInstance = PMA\libraries\Response::getInstance(); + $this->restoreInstance = PMA\libraries\Response::getInstance(); $mockResponse = $this->getMockBuilder('PMA\libraries\Response') ->disableOriginalConstructor() @@ -46,9 +43,8 @@ class PMATestCase extends PHPUnit_Framework_TestCase ->with() ->will($this->returnValue(false)); - $attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance'); - $attrInstance->setAccessible(true); - $attrInstance->setValue($mockResponse); - $attrInstance->setValue($restoreInstance); + $this->attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance'); + $this->attrInstance->setAccessible(true); + $this->attrInstance->setValue($mockResponse); } } \ No newline at end of file diff --git a/test/libraries/core/PMA_headerLocation_test.php b/test/libraries/core/PMA_headerLocation_test.php index 0bbc0b822e..f311196778 100644 --- a/test/libraries/core/PMA_headerLocation_test.php +++ b/test/libraries/core/PMA_headerLocation_test.php @@ -68,6 +68,8 @@ class PMA_HeaderLocation_Test extends PMATestCase $this->mockResponse('Location: ' . $testUri); PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] + $this->tearDown(); + $this->mockResponse('Refresh: 0; ' . $testUri); PMA_sendHeaderLocation($testUri, true); // sets $GLOBALS['header'] } @@ -147,4 +149,18 @@ class PMA_HeaderLocation_Test extends PMATestCase $attrInstance->setValue($restoreInstance); } + /** + *Tear down function for mockResponse method + * + *@return void + */ + public function tearDown() + { + if(isset($this->attrInstance, $this->restoreInstance)) + { + $this->attrInstance->setValue($this->restoreInstance); + unset($this->restoreInstance); + unset($this->attrInstance); + } + } } \ No newline at end of file From 01b3509d94436de0e9d84d0e0a371c99a5237264 Mon Sep 17 00:00:00 2001 From: osaid Date: Sat, 7 Jan 2017 16:37:17 +0530 Subject: [PATCH 09/10] remove tabs Signed-off-by: osaid --- test/PMATestCase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/PMATestCase.php b/test/PMATestCase.php index e4a690725b..2d170cce9f 100644 --- a/test/PMATestCase.php +++ b/test/PMATestCase.php @@ -8,8 +8,8 @@ class PMATestCase extends PHPUnit_Framework_TestCase { - public $restoreInstance; - public $attrInstance; + public $restoreInstance; + public $attrInstance; /** * This method is called before the first test of this test class is run. */ From fd6a02b215ad70af247922f547299f19d12dfe7f Mon Sep 17 00:00:00 2001 From: osaid Date: Sun, 8 Jan 2017 13:03:28 +0530 Subject: [PATCH 10/10] moved tearDown method to PMATestCase Signed-off-by: osaid --- test/PMATestCase.php | 14 ++++++++++++++ test/libraries/core/PMA_headerLocation_test.php | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/PMATestCase.php b/test/PMATestCase.php index 2d170cce9f..a850e1e9a9 100644 --- a/test/PMATestCase.php +++ b/test/PMATestCase.php @@ -47,4 +47,18 @@ class PMATestCase extends PHPUnit_Framework_TestCase $this->attrInstance->setAccessible(true); $this->attrInstance->setValue($mockResponse); } + /** + *Tear down function for mockResponse method + * + *@return void + */ + protected function tearDown() + { + if(isset($this->attrInstance, $this->restoreInstance)) + { + $this->attrInstance->setValue($this->restoreInstance); + unset($this->restoreInstance); + unset($this->attrInstance); + } + } } \ No newline at end of file diff --git a/test/libraries/core/PMA_headerLocation_test.php b/test/libraries/core/PMA_headerLocation_test.php index f311196778..18864415a1 100644 --- a/test/libraries/core/PMA_headerLocation_test.php +++ b/test/libraries/core/PMA_headerLocation_test.php @@ -149,18 +149,4 @@ class PMA_HeaderLocation_Test extends PMATestCase $attrInstance->setValue($restoreInstance); } - /** - *Tear down function for mockResponse method - * - *@return void - */ - public function tearDown() - { - if(isset($this->attrInstance, $this->restoreInstance)) - { - $this->attrInstance->setValue($this->restoreInstance); - unset($this->restoreInstance); - unset($this->attrInstance); - } - } } \ No newline at end of file