diff --git a/test/bootstrap-dist.php b/test/bootstrap-dist.php index cfcacc3404..0edf05e329 100644 --- a/test/bootstrap-dist.php +++ b/test/bootstrap-dist.php @@ -34,4 +34,41 @@ $_SESSION[' PMA_token '] = 'token'; $GLOBALS['lang'] = 'en'; $GLOBALS['is_ajax_request'] = false; + +define('PMA_HAS_RUNKIT', function_exists('runkit_constant_redefine')); +$GLOBALS['runkit_internal_override'] = ini_get('runkit.internal_override'); + + +/** + * Function to emulate headers() function by storing headers in GLOBAL array. + */ +function test_header($string, $replace = true, $http_response_code = 200) +{ + if (! isset($GLOBALS['header'])) { + $GLOBALS['header'] = array(); + } + + $GLOBALS['header'][] = $string; +} + +/** + * Function to emulate headers_hest. + */ +function test_headers_sent() +{ + return false; +} + +if (PMA_HAS_RUNKIT && $GLOBALS['runkit_internal_override']) { + echo "Enabling headers testing...\n"; + runkit_function_rename('header', 'test_header_override'); + runkit_function_rename('headers_sent', 'test_headers_sent_override'); + runkit_function_rename('test_header', 'header'); + runkit_function_rename('test_headers_sent', 'headers_sent'); + define('PMA_TEST_HEADERS', true); +} else { + echo "No headers testing.\n"; + echo "Please install runkit and enable runkit.internal_override!\n"; +} + ?> diff --git a/test/libraries/core/PMA_headerLocation_test.php b/test/libraries/core/PMA_headerLocation_test.php index 61069caf6f..47d1127b50 100644 --- a/test/libraries/core/PMA_headerLocation_test.php +++ b/test/libraries/core/PMA_headerLocation_test.php @@ -50,110 +50,12 @@ class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase protected $runkitExt; protected $apdExt; - public function __construct() - { - parent::__construct(); - $this->runkitExt = false; - if (function_exists("runkit_constant_redefine")) { - $this->runkitExt = true; - } - - $this->apdExt = false; - if (function_exists("rename_function")) { - $this->apdExt = true; - } - - if ($this->apdExt && !$GLOBALS['test_header']) { - - /* - * using apd extension to overriding header and headers_sent - * functions for test purposes - */ - $GLOBALS['test_header'] = 1; - - /* - * rename_function() of header and headers_sent may cause CLI error - * report in Windows XP - */ - rename_function('header', 'test_header'); - rename_function('headers_sent', 'test_headers_sent'); - - /* - * solution from: - * http://unixwars.com/2008/11/29/override_function-in-php/ - * to overriding more than one function - */ - - $substs = array( - 'header' => - 'if (isset($GLOBALS["header"])) {' - . '$GLOBALS["header"] .= $a;' - . '} else {' - . '$GLOBALS["header"] = $a;' - . '}', - 'headers_sent' => 'return false;' - ); - - $args = array( - 'header' => '$a', - 'headers_sent' => '' - ); - - foreach ($substs as $func => $ren_func) { - if (function_exists("__overridden__")) { - rename_function( - "__overridden__", - str_replace( - array('.', ' '), - array('', ''), - microtime() - ) - ); - } - override_function($func, $args[$func], $substs[$func]); - rename_function( - "__overridden__", - str_replace(array('.', ' '), array('', ''), microtime()) - ); - } - - } - } - - public function __destruct() - { - /* - * rename_function may causes CLI error report in Windows XP, but - * nothing more happen - */ - - if ($this->apdExt && $GLOBALS['test_header']) { - $GLOBALS['test_header'] = 0; - - rename_function( - 'header', - 'header' . str_replace( - array('.', ' '), array('', ''), microtime() - ) - ); - rename_function( - 'headers_sent', - 'headers_sent' . str_replace( - array('.', ' '), array('', ''), microtime() - ) - ); - - rename_function('test_header', 'header'); - rename_function('test_headers_sent', 'headers_sent'); - } - } - public function setUp() { //session_start(); // cleaning constants - if ($this->runkitExt) { + if (PMA_HAS_RUNKIT) { $this->oldIISvalue = 'non-defined'; @@ -189,7 +91,7 @@ class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase //session_destroy(); // cleaning constants - if ($this->runkitExt) { + if (PMA_HAS_RUNKIT) { if ($this->oldIISvalue != 'non-defined') { runkit_constant_redefine('PMA_IS_IIS', $this->oldIISvalue); @@ -203,23 +105,19 @@ class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase runkit_constant_remove('SID'); } } - - if ($this->apdExt) { - unset($GLOBALS['header']); - } } public function testSendHeaderLocationWithSidUrlWithQuestionMark() { - if ($this->runkitExt && $this->apdExt) { + if (defined('PMA_TEST_HEADERS')) { runkit_constant_redefine('SID', md5('test_hash')); $testUri = 'http://testurl.com/test.php?test=test'; $separator = PMA_get_arg_separator(); - $header = 'Location: ' . $testUri . $separator . SID; + $header = array('Location: ' . $testUri . $separator . SID); /* sets $GLOBALS['header'] */ PMA_sendHeaderLocation($testUri); @@ -228,7 +126,7 @@ class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase } else { $this->markTestSkipped( - 'Cannot redefine constant/function - missing APD or/and runkit extension' + 'Cannot redefine constant/function - missing runkit extension' ); } @@ -236,74 +134,74 @@ class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase public function testSendHeaderLocationWithSidUrlWithoutQuestionMark() { - if ($this->runkitExt && $this->apdExt) { + if (defined('PMA_TEST_HEADERS')) { runkit_constant_redefine('SID', md5('test_hash')); $testUri = 'http://testurl.com/test.php'; $separator = PMA_get_arg_separator(); - $header = 'Location: ' . $testUri . '?' . SID; + $header = array('Location: ' . $testUri . '?' . SID); PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] $this->assertEquals($header, $GLOBALS['header']); } else { - $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension'); + $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension'); } } public function testSendHeaderLocationWithoutSidWithIis() { - if ($this->runkitExt && $this->apdExt) { + if (defined('PMA_TEST_HEADERS')) { runkit_constant_redefine('PMA_IS_IIS', true); $testUri = 'http://testurl.com/test.php'; $separator = PMA_get_arg_separator(); - $header = 'Location: ' . $testUri; + $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 = 'Refresh: 0; ' . $testUri; + $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 APD or/and runkit extension'); + $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension'); } } public function testSendHeaderLocationWithoutSidWithoutIis() { - if ($this->apdExt) { + if (defined('PMA_TEST_HEADERS')) { $testUri = 'http://testurl.com/test.php'; - $header = 'Location: ' . $testUri; + $header = array('Location: ' . $testUri); PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header'] $this->assertEquals($header, $GLOBALS['header']); } else { - $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension'); + $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension'); } } public function testSendHeaderLocationIisLongUri() { - if (defined('PMA_IS_IIS') && $this->runkitExt) { + if (defined('PMA_IS_IIS') && PMA_HAS_RUNKIT) { runkit_constant_redefine('PMA_IS_IIS', true); } elseif (!defined('PMA_IS_IIS')) { define('PMA_IS_IIS', true); } else { - $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension'); + $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension'); } // over 600 chars