Index: trunk/phase3/tests/phpunit/includes/HttpTest.php |
— | — | @@ -82,7 +82,16 @@ |
83 | 83 | } else { |
84 | 84 | $this->assertThat( $r, $this->isInstanceOf( 'PhpHttpRequest' ) ); |
85 | 85 | } |
| 86 | + $this->assertTrue( $r->status->isGood(), '$r->status is good' ); |
86 | 87 | unset( $r ); |
| 88 | + |
| 89 | + $r = MWHttpRequest::factory( "//www.example.com/" ); |
| 90 | + if ( self::$has_curl ) { |
| 91 | + $this->assertThat( $r, $this->isInstanceOf( 'CurlHttpRequest' ) ); |
| 92 | + } else { |
| 93 | + $this->assertThat( $r, $this->isInstanceOf( 'PhpHttpRequest' ) ); |
| 94 | + } |
| 95 | + $this->assertTrue( $r->status->isGood(), '$r->status is good' ); |
87 | 96 | |
88 | 97 | if ( !self::$has_fopen ) { |
89 | 98 | $this->setExpectedException( 'MWException' ); |
— | — | @@ -90,6 +99,7 @@ |
91 | 100 | Http::$httpEngine = 'php'; |
92 | 101 | $r = MWHttpRequest::factory( "http://www.example.com/" ); |
93 | 102 | $this->assertThat( $r, $this->isInstanceOf( 'PhpHttpRequest' ) ); |
| 103 | + $this->assertTrue( $r->status->isGood(), '$r->status is good' ); |
94 | 104 | unset( $r ); |
95 | 105 | |
96 | 106 | if ( !self::$has_curl ) { |
— | — | @@ -99,6 +109,7 @@ |
100 | 110 | $r = MWHttpRequest::factory( "http://www.example.com/" ); |
101 | 111 | if ( self::$has_curl ) { |
102 | 112 | $this->assertThat( $r, $this->isInstanceOf( 'CurlHttpRequest' ) ); |
| 113 | + $this->assertTrue( $r->status->isGood(), '$r->status is good' ); |
103 | 114 | } |
104 | 115 | } |
105 | 116 | |
— | — | @@ -165,6 +176,15 @@ |
166 | 177 | foreach ( $this->test_requesturl as $u ) { |
167 | 178 | $r = Http::request( "POST", $u, $opt ); |
168 | 179 | $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with " . Http::$httpEngine ); |
| 180 | + |
| 181 | + // If this was an HTTP URL, repeat the same test with a protocol-relative URL |
| 182 | + // We can't do this with HTTPS URLs because MWHttpRequest expands protocol-relative |
| 183 | + // URLs to HTTP. |
| 184 | + list( $prot, $url ) = explode( ':', $u, 2 ); |
| 185 | + if ( $prot === 'http' ) { |
| 186 | + $r = Http::request( "POST", $url, $opt ); |
| 187 | + $this->assertEquals( self::$content["POST $u"], "$r", "POST $url with " . Http::$httpEngine ); |
| 188 | + } |
169 | 189 | } |
170 | 190 | } |
171 | 191 | |
— | — | @@ -203,6 +223,15 @@ |
204 | 224 | foreach ( $this->test_geturl as $u ) { |
205 | 225 | $r = Http::get( $u, 30, $opt ); /* timeout of 30s */ |
206 | 226 | $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with " . Http::$httpEngine ); |
| 227 | + |
| 228 | + // If this was an HTTP URL, repeat the same test with a protocol-relative URL |
| 229 | + // We can't do this with HTTPS URLs because MWHttpRequest expands protocol-relative |
| 230 | + // URLs to HTTP. |
| 231 | + list( $prot, $url ) = explode( ':', $u, 2 ); |
| 232 | + if ( $prot === 'http' ) { |
| 233 | + $r = Http::get( $url, 30, $opt ); |
| 234 | + $this->assertEquals( self::$content["GET $u"], "$r", "Get $url with " . Http::$httpEngine ); |
| 235 | + } |
207 | 236 | } |
208 | 237 | } |
209 | 238 | |
— | — | @@ -243,6 +272,16 @@ |
244 | 273 | $r = Http::post( $u, $opt ); |
245 | 274 | $this->assertEquals( self::$content["POST $u => $postData"], "$r", |
246 | 275 | "POST $u (postData=$postData) with " . Http::$httpEngine ); |
| 276 | + |
| 277 | + // If this was an HTTP URL, repeat the same test with a protocol-relative URL |
| 278 | + // We can't do this with HTTPS URLs because MWHttpRequest expands protocol-relative |
| 279 | + // URLs to HTTP. |
| 280 | + list( $prot, $url ) = explode( ':', $u, 2 ); |
| 281 | + if ( $prot === 'http' ) { |
| 282 | + $r = Http::post( $url, $opt ); |
| 283 | + $this->assertEquals( self::$content["POST $u => $postData"], "$r", |
| 284 | + "POST $u (postData=$postData) with " . Http::$httpEngine ); |
| 285 | + } |
247 | 286 | } |
248 | 287 | } |
249 | 288 | |