added mockResponse function for sharing code and used it in headerlocationtest Signed-Off-By: Osaid <osaid.nasir@gmail.com>
This commit is contained in:
parent
eb54c43fb6
commit
2a62427b67
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user