diff options
author | aude <aude.wiki@gmail.com> | 2012-10-10 16:11:45 +0000 |
---|---|---|
committer | aude <aude.wiki@gmail.com> | 2012-10-11 08:04:49 +0000 |
commit | f8b054388c8fd0055245ea8ee03776f9a7fb4ebb (patch) | |
tree | 0162adfeeef9deb028cdd82f2f77c311146f37ec /tests/phpunit/includes/HttpTest.php | |
parent | 1df5e7aa89e58ab86a9158ea320b9a8436df7791 (diff) | |
download | mediawikicore-f8b054388c8fd0055245ea8ee03776f9a7fb4ebb.tar.gz mediawikicore-f8b054388c8fd0055245ea8ee03776f9a7fb4ebb.zip |
fix fatal error in HttpTest
Change-Id: I29d31974bd467a501109e7817152ac4aa2c8c75b
Diffstat (limited to 'tests/phpunit/includes/HttpTest.php')
-rw-r--r-- | tests/phpunit/includes/HttpTest.php | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/tests/phpunit/includes/HttpTest.php b/tests/phpunit/includes/HttpTest.php index 155bd3123ab2..b49de6524a31 100644 --- a/tests/phpunit/includes/HttpTest.php +++ b/tests/phpunit/includes/HttpTest.php @@ -131,13 +131,10 @@ class HttpTest extends MediaWikiTestCase { * handles header reporting on redirect pages, and will need to be * rewritten when bug 29232 is taken care of (high-level handling of * HTTP redirects). - * @group Broken - * MWHttpRequestTester's constructor is private, needs to use - * MWHttpRequestTester::factory instead. However the objects coming - * from that won't have MWHttpRequestTester::setRespHeaders... */ function testRelativeRedirections() { - $h = new MWHttpRequestTester( 'http://oldsite/file.ext' ); + $h = MWHttpRequestTester::factory( 'http://oldsite/file.ext' ); + # Forge a Location header $h->setRespHeaders( 'location', array( 'http://newsite/file.ext', @@ -175,10 +172,42 @@ class HttpTest extends MediaWikiTestCase { } /** - * Class to let us overwrite MWHttpREquest respHeaders variable + * Class to let us overwrite MWHttpRequest respHeaders variable */ class MWHttpRequestTester extends MWHttpRequest { + + // function derived from the MWHttpRequest factory function but + // returns appropriate tester class here + public static function factory( $url, $options = null ) { + if ( !Http::$httpEngine ) { + Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php'; + } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) { + throw new MWException( __METHOD__ . ': curl (http://php.net/curl) is not installed, but' . + 'Http::$httpEngine is set to "curl"' ); + } + + switch( Http::$httpEngine ) { + case 'curl': + return new CurlHttpRequestTester( $url, $options ); + case 'php': + if ( !wfIniGetBool( 'allow_url_fopen' ) ) { + throw new MWException( __METHOD__ . ': allow_url_fopen needs to be enabled for pure PHP' . + ' http requests to work. If possible, curl should be used instead. See http://php.net/curl.' ); + } + return new PhpHttpRequestTester( $url, $options ); + default: + } + } +} + +class CurlHttpRequestTester extends CurlHttpRequest { + function setRespHeaders( $name, $value ) { + $this->respHeaders[$name] = $value; + } +} + +class PhpHttpRequestTester extends PhpHttpRequest { function setRespHeaders( $name, $value ) { - $this->respHeaders[$name] = $value ; + $this->respHeaders[$name] = $value; } } |