Skip to content

Commit

Permalink
Use Header class for headers manipulation
Browse files Browse the repository at this point in the history
* Added mocking of response object
* Rectified mistake of calling method once
* implemented mock properly
* replaced header with response header 

Issue #12079

Signed-off-by: Osaid osaid.nasir@gmail.com
  • Loading branch information
osaid-r authored and nijel committed Dec 20, 2016
1 parent 92aa487 commit 73c6a7e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
9 changes: 6 additions & 3 deletions setup/lib/form_processing.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
use PMA\libraries\config\FormDisplay;
use PMA\libraries\URL;
use PMA\libraries\Response;

/**
* Processes forms registered in $form_display, handles error correction
Expand Down Expand Up @@ -72,11 +73,13 @@ function PMA_Process_formset(FormDisplay $form_display)
*/
function PMA_generateHeader303()
{
$response = Response::getInstance();

// drop post data
header('HTTP/1.1 303 See Other');
header('Location: index.php' . URL::getCommonRaw());
$response->header('HTTP/1.1 303 See Other');
$response->header('Location: index.php' . URL::getCommonRaw());

if (!defined('TESTSUITE')) {
exit;
}
}
}
33 changes: 22 additions & 11 deletions test/libraries/PMA_Form_Processing_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,28 @@ public function setUp()
*/
public function testProcessFormSet()
{
if (!defined('PMA_TEST_HEADERS')) {
$this->markTestSkipped(
'Cannot redefine constant/function - missing runkit extension'
$restoreInstance = PMA\libraries\Response::getInstance();

$mockResponse = $this->getMockBuilder('PMA\libraries\Response')
->disableOriginalConstructor()
->setMethods(array('header', 'headersSent'))
->getMock();

$mockResponse->expects($this->exactly(2))
->method('header')
->withConsecutive(
['HTTP/1.1 303 See Other'],
['Location: index.php?lang=en']
);
}

$mockResponse->expects($this->any())
->method('headersSent')
->with()
->will($this->returnValue(false));

$attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
$attrInstance->setAccessible(true);
$attrInstance->setValue($mockResponse);

// case 1
$formDisplay = $this->getMockBuilder('PMA\libraries\config\FormDisplay')
Expand Down Expand Up @@ -118,12 +135,6 @@ public function testProcessFormSet()

PMA_Process_formset($formDisplay);

$this->assertEquals(
array('HTTP/1.1 303 See Other', 'Location: index.php?lang=en'),
$GLOBALS['header']
);

}


}
}

0 comments on commit 73c6a7e

Please sign in to comment.