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); } /**