diff --git a/test/PMATestCase.php b/test/PMATestCase.php index 6a13ed3fe2..a850e1e9a9 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. */ @@ -21,4 +18,47 @@ class PMATestCase extends PHPUnit_Framework_TestCase require 'libraries/config.default.php'; $GLOBALS['cfg'] = $cfg; } + /** + * Creates mock of Response object for header testing + * + * @param string $param parameter for header method + * + * @return void + */ + public function mockResponse($param) + { + $this->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)); + + $this->attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance'); + $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 442d983cc0..18864415a1 100644 --- a/test/libraries/core/PMA_headerLocation_test.php +++ b/test/libraries/core/PMA_headerLocation_test.php @@ -33,7 +33,7 @@ use PMA\libraries\Sanitize; * @package PhpMyAdmin-test */ -class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase +class PMA_HeaderLocation_Test extends PMATestCase { protected $runkitExt; @@ -61,29 +61,17 @@ 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'; + $this->mockResponse('Location: ' . $testUri); + PMA_sendHeaderLocation($testUri); // sets $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' - ); - } + $this->tearDown(); + $this->mockResponse('Refresh: 0; ' . $testUri); + PMA_sendHeaderLocation($testUri, true); // sets $GLOBALS['header'] } /** @@ -93,20 +81,10 @@ 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'; + $this->mockResponse('Location: ' . $testUri); + PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] } /** @@ -171,4 +149,4 @@ class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase $attrInstance->setValue($restoreInstance); } -} +} \ No newline at end of file