From: aude Date: Wed, 10 Oct 2012 16:11:45 +0000 (+0000) Subject: fix fatal error in HttpTest X-Git-Tag: 1.31.0-rc.0~21877^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=f8b054388c8fd0055245ea8ee03776f9a7fb4ebb;p=lhc%2Fweb%2Fwiklou.git fix fatal error in HttpTest Change-Id: I29d31974bd467a501109e7817152ac4aa2c8c75b --- diff --git a/tests/phpunit/includes/HttpTest.php b/tests/phpunit/includes/HttpTest.php index 155bd3123a..b49de6524a 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; } }