1488d7fd88f9c195507a0ade8f3004f63fa23678
[lhc/web/wiklou.git] / maintenance / tests / HttpTest.php
1 <?php
2
3 class MockCookie extends Cookie {
4 public function canServeDomain($arg) { return parent::canServeDomain($arg); }
5 public function canServePath($arg) { return parent::canServePath($arg); }
6 public function isUnExpired() { return parent::isUnExpired(); }
7 }
8
9 class HttpTest extends PhpUnit_Framework_TestCase {
10 static $content;
11 static $headers;
12 static $has_curl;
13 static $has_fopen;
14 static $has_proxy = false;
15 static $proxy = "http://hulk:8080/";
16 var $test_geturl = array(
17 "http://www.example.com/",
18 "http://pecl.php.net/feeds/pkg_apc.rss",
19 "http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id=3",
20 "http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw",
21 "http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&format=php",
22 );
23 var $test_requesturl = array( "http://en.wikipedia.org/wiki/Special:Export/User:MarkAHershberger" );
24
25 var $test_posturl = array( "http://www.comp.leeds.ac.uk/cgi-bin/Perl/environment-example" => "review=test" );
26
27 function setup() {
28 putenv("http_proxy"); /* Remove any proxy env var, so curl doesn't get confused */
29 if ( is_array( self::$content ) ) {
30 return;
31 }
32 self::$has_curl = function_exists( 'curl_init' );
33 self::$has_fopen = wfIniGetBool( 'allow_url_fopen' );
34
35 if ( !file_exists("/usr/bin/curl") ) {
36 $this->markTestIncomplete("This test requires the curl binary at /usr/bin/curl. If you have curl, please file a bug on this test, or, better yet, provide a patch.");
37 }
38
39 $content = tempnam( wfTempDir(), "" );
40 $headers = tempnam( wfTempDir(), "" );
41 if ( !$content && !$headers ) {
42 die( "Couldn't create temp file!" );
43 }
44
45 // This probably isn't the best test for a proxy, but it works on my system!
46 system("curl -0 -o $content -s ".self::$proxy);
47 $out = file_get_contents( $content );
48 if( $out ) {
49 self::$has_proxy = true;
50 }
51
52 /* Maybe use wget instead of curl here ... just to use a different codebase? */
53 foreach ( $this->test_geturl as $u ) {
54 system( "curl -0 -s -D $headers '$u' -o $content" );
55 self::$content["GET $u"] = file_get_contents( $content );
56 self::$headers["GET $u"] = file_get_contents( $headers );
57 }
58 foreach ( $this->test_requesturl as $u ) {
59 system( "curl -0 -s -X POST -H 'Content-Length: 0' -D $headers '$u' -o $content" );
60 self::$content["POST $u"] = file_get_contents( $content );
61 self::$headers["POST $u"] = file_get_contents( $headers );
62 }
63 foreach ( $this->test_posturl as $u => $postData ) {
64 system( "curl -0 -s -X POST -d '$postData' -D $headers '$u' -o $content" );
65 self::$content["POST $u => $postData"] = file_get_contents( $content );
66 self::$headers["POST $u => $postData"] = file_get_contents( $headers );
67 }
68 unlink( $content );
69 unlink( $headers );
70 }
71
72
73 function testInstantiation() {
74 Http::$httpEngine = false;
75
76 $r = HttpRequest::factory("http://www.example.com/");
77 if ( self::$has_curl ) {
78 $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
79 } else {
80 $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
81 }
82 unset($r);
83
84 if( !self::$has_fopen ) {
85 $this->setExpectedException( 'MWException' );
86 }
87 Http::$httpEngine = 'php';
88 $r = HttpRequest::factory("http://www.example.com/");
89 $this->assertThat($r, $this->isInstanceOf( 'PhpHttpRequest' ));
90 unset($r);
91
92 if( !self::$has_curl ) {
93 $this->setExpectedException( 'MWException' );
94 }
95 Http::$httpEngine = 'curl';
96 $r = HttpRequest::factory("http://www.example.com/");
97 if( self::$has_curl ) {
98 $this->assertThat($r, $this->isInstanceOf( 'CurlHttpRequest' ));
99 }
100 }
101
102 function runHTTPFailureChecks() {
103 // Each of the following requests should result in a failure.
104
105 $timeout = 1;
106 $start_time = time();
107 $r = HTTP::get( "http://www.example.com:1/", $timeout);
108 $end_time = time();
109 $this->assertLessThan($timeout+2, $end_time - $start_time,
110 "Request took less than {$timeout}s via ".Http::$httpEngine);
111 $this->assertEquals($r, false, "false -- what we get on error from Http::get()");
112
113 $r = HTTP::get( "http://www.example.com/this-file-does-not-exist", $timeout);
114 $this->assertFalse($r, "False on 404s");
115 }
116
117 function testFailureDefault() {
118 Http::$httpEngine = false;
119 self::runHTTPFailureChecks();
120 }
121
122 function testFailurePhp() {
123 if ( !self::$has_fopen ) {
124 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
125 }
126
127 Http::$httpEngine = "php";
128 self::runHTTPFailureChecks();
129 }
130
131 function testFailureCurl() {
132 if ( !self::$has_curl ) {
133 $this->markTestIncomplete( "This test requires curl." );
134 }
135
136 Http::$httpEngine = "curl";
137 self::runHTTPFailureChecks();
138 }
139
140 /* ./phase3/includes/Import.php:1108: $data = Http::request( $method, $url ); */
141 /* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */
142 /* ./includes/Import.php:1134: return ImportStreamSource::newFromURL( $url, "POST" ); */
143 function runHTTPRequests($proxy=null) {
144 $opt = array();
145
146 if($proxy) {
147 $opt['proxy'] = $proxy;
148 } elseif( $proxy === false ) {
149 $opt['noProxy'] = true;
150 }
151
152 /* no postData here because the only request I could find in code so far didn't have any */
153 foreach ( $this->test_requesturl as $u ) {
154 $r = Http::request( "POST", $u, $opt );
155 $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with ".Http::$httpEngine );
156 }
157 }
158
159 function testRequestDefault() {
160 Http::$httpEngine = false;
161 self::runHTTPRequests();
162 }
163
164 function testRequestPhp() {
165 if ( !self::$has_fopen ) {
166 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
167 }
168
169 Http::$httpEngine = "php";
170 self::runHTTPRequests();
171 }
172
173 function testRequestCurl() {
174 if ( !self::$has_curl ) {
175 $this->markTestIncomplete( "This test requires curl." );
176 }
177
178 Http::$httpEngine = "curl";
179 self::runHTTPRequests();
180 }
181
182 /* ./extensions/SpamBlacklist/SpamBlacklist_body.php:164: $httpText = Http::get( $fileName ); */
183 /* ./extensions/ApiSVGProxy/ApiSVGProxy.body.php:44: $contents = Http::get( $file->getFullUrl() ); */
184 /* ./extensions/BookInformation/drivers/IsbnDb.php:24: if( ( $xml = Http::get( $uri ) ) !== false ) { */
185 /* ./extensions/BookInformation/drivers/Amazon.php:23: if( ( $xml = Http::get( $uri ) ) !== false ) { */
186 /* ./extensions/TitleBlacklist/TitleBlacklist.list.php:217: $result = Http::get( $url ); */
187 /* ./extensions/TSPoll/TSPoll.php:68: $get_server = Http::get( 'http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id='.$id ); */
188 /* ./extensions/TSPoll/TSPoll.php:70: $get_server = Http::get( 'http://toolserver.org/~jan/poll/main.php?page=wiki_output&id='.$id ); */
189 /* ./extensions/DoubleWiki/DoubleWiki.php:56: $translation = Http::get( $url.$sep.'action=render' ); */
190 /* ./extensions/ExternalPages/ExternalPages_body.php:177: $serializedText = Http::get( $this->mPageURL ); */
191 /* ./extensions/Translate/utils/TranslationHelpers.php:143: $suggestions = Http::get( $url, $timeout ); */
192 /* ./extensions/Translate/SpecialImportTranslations.php:169: $filedata = Http::get( $url ); ; */
193 /* ./extensions/Translate/TranslateEditAddons.php:338: $suggestions = Http::get( $url, $timeout ); */
194 /* ./extensions/SecurePoll/includes/user/Auth.php:283: $value = Http::get( $url, 20, $curlParams ); */
195 /* ./extensions/DumpHTML/dumpHTML.inc:778: $contents = Http::get( $url ); */
196 /* ./extensions/DumpHTML/dumpHTML.inc:1298: $contents = Http::get( $sourceUrl ); */
197 /* ./extensions/DumpHTML/dumpHTML.inc:1373: $contents = Http::get( $sourceUrl ); */
198 /* ./phase3/maintenance/rebuildInterwiki.inc:101: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
199 /* ./phase3/maintenance/findhooks.php:98: $allhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php' ); */
200 /* ./phase3/maintenance/findhooks.php:109: $oldhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Removed_hooks&cmlimit=500&format=php' ); */
201 /* ./phase3/maintenance/dumpInterwiki.inc:95: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
202 /* ./phase3/includes/parser/Parser.php:3204: $text = Http::get($url); */
203 /* ./phase3/includes/filerepo/ForeignAPIRepo.php:131: $data = Http::get( $url ); */
204 /* ./phase3/includes/filerepo/ForeignAPIRepo.php:205: $thumb = Http::get( $foreignUrl ); */
205 /* ./phase3/includes/filerepo/File.php:1105: $res = Http::get( $renderUrl ); */
206 /* ./phase3/includes/GlobalFunctions.php:2760: * @deprecated Use Http::get() instead */
207 /* ./phase3/includes/GlobalFunctions.php:2764: return Http::get( $url ); */
208 /* ./phase3/includes/ExternalStoreHttp.php:18: $ret = Http::get( $url ); */
209 /* ./phase3/includes/Import.php:357: $data = Http::get( $src ); */
210 /* ./extensions/ExternalData/ED_Utils.php:291: return Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
211 /* ./extensions/ExternalData/ED_Utils.php:293: return Http::get( $url ); */
212 /* ./extensions/ExternalData/ED_Utils.php:306: $page = Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
213 /* ./extensions/ExternalData/ED_Utils.php:308: $page = Http::get( $url ); */
214 /* ./extensions/CodeReview/backend/Subversion.php:320: $blob = Http::get( $target, $this->mTimeout ); */
215 /* ./extensions/AmazonPlus/AmazonPlus.php:214: $this->response = Http::get( $urlstr ); */
216 /* ./extensions/StaticWiki/StaticWiki.php:24: $text = Http::get( $url ) ; */
217 /* ./extensions/StaticWiki/StaticWiki.php:64: $history = Http::get ( $wgStaticWikiExternalSite . "index.php?title=" . urlencode ( $url_title ) . "&action=history" ) ; */
218 /* ./extensions/Configure/scripts/findSettings.php:126: $cont = Http::get( "http://www.mediawiki.org/w/index.php?title={$page}&action=raw" ); */
219 /* ./extensions/TorBlock/TorBlock.class.php:148: $data = Http::get( $url ); */
220 /* ./extensions/HoneypotIntegration/HoneypotIntegration.class.php:60: $data = Http::get( $wgHoneypotURLSource, 'default', */
221 /* ./extensions/SemanticForms/includes/SF_Utils.inc:378: $page_contents = Http::get($url); */
222 /* ./extensions/LocalisationUpdate/LocalisationUpdate.class.php:172: $basefilecontents = Http::get( $basefile ); */
223 /* ./extensions/APC/SpecialAPC.php:245: $rss = Http::get( 'http://pecl.php.net/feeds/pkg_apc.rss' ); */
224 /* ./extensions/Interlanguage/Interlanguage.php:56: $a = Http::get( $url ); */
225 /* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */
226 function runHTTPGets($proxy=null) {
227 $opt = array();
228
229 if($proxy) {
230 $opt['proxy'] = $proxy;
231 } elseif( $proxy === false ) {
232 $opt['noProxy'] = true;
233 }
234
235 foreach ( $this->test_geturl as $u ) {
236 $r = Http::get( $u, 30, $opt ); /* timeout of 30s */
237 $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with ".Http::$httpEngine );
238 }
239 }
240
241 function testGetDefault() {
242 Http::$httpEngine = false;
243 self::runHTTPGets();
244 }
245
246 function testGetPhp() {
247 if ( !self::$has_fopen ) {
248 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
249 }
250
251 Http::$httpEngine = "php";
252 self::runHTTPGets();
253 }
254
255 function testGetCurl() {
256 if ( !self::$has_curl ) {
257 $this->markTestIncomplete( "This test requires curl." );
258 }
259
260 Http::$httpEngine = "curl";
261 self::runHTTPGets();
262 }
263
264 /* ./phase3/maintenance/parserTests.inc:1618: return Http::post( $url, array( 'postData' => wfArrayToCGI( $data ) ) ); */
265 function runHTTPPosts($proxy=null) {
266 $opt = array();
267
268 if($proxy) {
269 $opt['proxy'] = $proxy;
270 } elseif( $proxy === false ) {
271 $opt['noProxy'] = true;
272 }
273
274 foreach ( $this->test_posturl as $u => $postData ) {
275 $opt['postData'] = $postData;
276 $r = Http::post( $u, $opt );
277 $this->assertEquals( self::$content["POST $u => $postData"], "$r",
278 "POST $u (postData=$postData) with ".Http::$httpEngine );
279 }
280 }
281
282 function testPostDefault() {
283 Http::$httpEngine = false;
284 self::runHTTPPosts();
285 }
286
287 function testPostPhp() {
288 if ( !self::$has_fopen ) {
289 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
290 }
291
292 Http::$httpEngine = "php";
293 self::runHTTPPosts();
294 }
295
296 function testPostCurl() {
297 if ( !self::$has_curl ) {
298 $this->markTestIncomplete( "This test requires curl." );
299 }
300
301 Http::$httpEngine = "curl";
302 self::runHTTPPosts();
303 }
304
305 function runProxyRequests() {
306 if(!self::$has_proxy) {
307 $this->markTestIncomplete( "This test requires a proxy." );
308 }
309 self::runHTTPGets(self::$proxy);
310 self::runHTTPPosts(self::$proxy);
311 self::runHTTPRequests(self::$proxy);
312
313 // Set false here to do noProxy
314 self::runHTTPGets(false);
315 self::runHTTPPosts(false);
316 self::runHTTPRequests(false);
317 }
318
319 function testProxyDefault() {
320 Http::$httpEngine = false;
321 self::runProxyRequests();
322 }
323
324 function testProxyPhp() {
325 if ( !self::$has_fopen ) {
326 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
327 }
328
329 Http::$httpEngine = 'php';
330 self::runProxyRequests();
331 }
332
333 function testProxyCurl() {
334 if ( !self::$has_curl ) {
335 $this->markTestIncomplete( "This test requires curl." );
336 }
337
338 Http::$httpEngine = 'curl';
339 self::runProxyRequests();
340 }
341
342 function testIsLocalUrl() {
343 }
344
345 /* ./extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php:559: $user_agent = Http::userAgent(); */
346 function testUserAgent() {
347 }
348
349 function testIsValidUrl() {
350 }
351
352 function testValidateCookieDomain() {
353 $this->assertFalse( Cookie::validateCookieDomain( "co.uk" ) );
354 $this->assertFalse( Cookie::validateCookieDomain( ".co.uk" ) );
355 $this->assertFalse( Cookie::validateCookieDomain( "gov.uk" ) );
356 $this->assertFalse( Cookie::validateCookieDomain( ".gov.uk" ) );
357 $this->assertTrue( Cookie::validateCookieDomain( "supermarket.uk" ) );
358 $this->assertFalse( Cookie::validateCookieDomain( "uk" ) );
359 $this->assertFalse( Cookie::validateCookieDomain( ".uk" ) );
360 $this->assertFalse( Cookie::validateCookieDomain( "127.0.0." ) );
361 $this->assertFalse( Cookie::validateCookieDomain( "127." ) );
362 $this->assertFalse( Cookie::validateCookieDomain( "127.0.0.1." ) );
363 $this->assertTrue( Cookie::validateCookieDomain( "127.0.0.1" ) );
364 $this->assertFalse( Cookie::validateCookieDomain( "333.0.0.1" ) );
365 $this->assertTrue( Cookie::validateCookieDomain( "example.com" ) );
366 $this->assertFalse( Cookie::validateCookieDomain( "example.com." ) );
367 $this->assertTrue( Cookie::validateCookieDomain( ".example.com" ) );
368
369 $this->assertTrue( Cookie::validateCookieDomain( ".example.com", "www.example.com" ) );
370 $this->assertFalse( Cookie::validateCookieDomain( "example.com", "www.example.com" ) );
371 $this->assertTrue( Cookie::validateCookieDomain( "127.0.0.1", "127.0.0.1" ) );
372 $this->assertFalse( Cookie::validateCookieDomain( "127.0.0.1", "localhost" ) );
373
374
375 }
376
377 function testSetCooke() {
378 $c = new MockCookie( "name", "value",
379 array(
380 "domain" => "ac.th",
381 "path" => "/path/",
382 ) );
383 $this->assertFalse($c->canServeDomain("ac.th"));
384
385 $c = new MockCookie( "name", "value",
386 array(
387 "domain" => "example.com",
388 "path" => "/path/",
389 ) );
390
391 $this->assertTrue($c->canServeDomain("example.com"));
392 $this->assertFalse($c->canServeDomain("www.example.com"));
393
394 $c = new MockCookie( "name", "value",
395 array(
396 "domain" => ".example.com",
397 "path" => "/path/",
398 ) );
399
400 $this->assertFalse($c->canServeDomain("www.example.net"));
401 $this->assertFalse($c->canServeDomain("example.com"));
402 $this->assertTrue($c->canServeDomain("www.example.com"));
403
404 $this->assertFalse($c->canServePath("/"));
405 $this->assertFalse($c->canServePath("/bogus/path/"));
406 $this->assertFalse($c->canServePath("/path"));
407 $this->assertTrue($c->canServePath("/path/"));
408
409 $this->assertTrue($c->isUnExpired());
410
411 $this->assertEquals("", $c->serializeToHttpRequest("/path/", "www.example.net"));
412 $this->assertEquals("", $c->serializeToHttpRequest("/", "www.example.com"));
413 $this->assertEquals("name=value", $c->serializeToHttpRequest("/path/", "www.example.com"));
414
415 $c = new MockCookie( "name", "value",
416 array(
417 "domain" => "www.example.com",
418 "path" => "/path/",
419 ) );
420 $this->assertFalse($c->canServeDomain("example.com"));
421 $this->assertFalse($c->canServeDomain("www.example.net"));
422 $this->assertTrue($c->canServeDomain("www.example.com"));
423
424 $c = new MockCookie( "name", "value",
425 array(
426 "domain" => ".example.com",
427 "path" => "/path/",
428 "expires" => "-1 day",
429 ) );
430 $this->assertFalse($c->isUnExpired());
431 $this->assertEquals("", $c->serializeToHttpRequest("/path/", "www.example.com"));
432
433 $c = new MockCookie( "name", "value",
434 array(
435 "domain" => ".example.com",
436 "path" => "/path/",
437 "expires" => "+1 day",
438 ) );
439 $this->assertTrue($c->isUnExpired());
440 $this->assertEquals("name=value", $c->serializeToHttpRequest("/path/", "www.example.com"));
441 }
442
443 function testCookieJarSetCookie() {
444 $cj = new CookieJar;
445 $cj->setCookie( "name", "value",
446 array(
447 "domain" => ".example.com",
448 "path" => "/path/",
449 ) );
450 $cj->setCookie( "name2", "value",
451 array(
452 "domain" => ".example.com",
453 "path" => "/path/sub",
454 ) );
455 $cj->setCookie( "name3", "value",
456 array(
457 "domain" => ".example.com",
458 "path" => "/",
459 ) );
460 $cj->setCookie( "name4", "value",
461 array(
462 "domain" => ".example.net",
463 "path" => "/path/",
464 ) );
465 $cj->setCookie( "name5", "value",
466 array(
467 "domain" => ".example.net",
468 "path" => "/path/",
469 "expires" => "-1 day",
470 ) );
471
472 $this->assertEquals("name4=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
473 $this->assertEquals("name3=value", $cj->serializeToHttpRequest("/", "www.example.com"));
474 $this->assertEquals("name=value; name3=value", $cj->serializeToHttpRequest("/path/", "www.example.com"));
475
476 $cj->setCookie( "name5", "value",
477 array(
478 "domain" => ".example.net",
479 "path" => "/path/",
480 "expires" => "+1 day",
481 ) );
482 $this->assertEquals("name4=value; name5=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
483
484 $cj->setCookie( "name4", "value",
485 array(
486 "domain" => ".example.net",
487 "path" => "/path/",
488 "expires" => "-1 day",
489 ) );
490 $this->assertEquals("name5=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
491 }
492
493 function testParseResponseHeader() {
494 $cj = new CookieJar;
495
496 $h[] = "Set-Cookie: name4=value; domain=.example.com; path=/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
497 $cj->parseCookieResponseHeader( $h[0], "www.example.com" );
498 $this->assertEquals("name4=value", $cj->serializeToHttpRequest("/", "www.example.com"));
499
500 $h[] = "name4=value2; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
501 $cj->parseCookieResponseHeader( $h[1], "www.example.com" );
502 $this->assertEquals("", $cj->serializeToHttpRequest("/", "www.example.com"));
503 $this->assertEquals("name4=value2", $cj->serializeToHttpRequest("/path/", "www.example.com"));
504
505 $h[] = "name5=value3; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
506 $cj->parseCookieResponseHeader( $h[2], "www.example.com" );
507 $this->assertEquals("name4=value2; name5=value3", $cj->serializeToHttpRequest("/path/", "www.example.com"));
508
509 $h[] = "name6=value3; domain=.example.net; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
510 $cj->parseCookieResponseHeader( $h[3], "www.example.com" );
511 $this->assertEquals("", $cj->serializeToHttpRequest("/path/", "www.example.net"));
512
513 $h[] = "name6=value0; domain=.example.net; path=/path/; expires=Mon, 09-Dec-1999 13:46:00 GMT";
514 $cj->parseCookieResponseHeader( $h[4], "www.example.net" );
515 $this->assertEquals("", $cj->serializeToHttpRequest("/path/", "www.example.net"));
516
517 $h[] = "name6=value4; domain=.example.net; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
518 $cj->parseCookieResponseHeader( $h[5], "www.example.net" );
519 $this->assertEquals("name6=value4", $cj->serializeToHttpRequest("/path/", "www.example.net"));
520 }
521
522 function runCookieRequests() {
523 $r = HttpRequest::factory( "http://www.php.net/manual" );
524 $r->execute();
525
526 $jar = $r->getCookieJar();
527
528 $this->assertThat( $jar, $this->isInstanceOf( 'CookieJar' ) );
529 $this->assertRegExp( '/^COUNTRY=.*; LAST_LANG=.*$/', $jar->serializeToHttpRequest( "/search?q=test", "www.php.net" ) );
530 $this->assertEquals( '', $jar->serializeToHttpRequest( "/search?q=test", "www.php.com" ) );
531 }
532
533 function testCookieRequestDefault() {
534 Http::$httpEngine = false;
535 self::runCookieRequests();
536 }
537 function testCookieRequestPhp() {
538 if ( !self::$has_fopen ) {
539 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
540 }
541
542 Http::$httpEngine = 'php';
543 self::runCookieRequests();
544 }
545 function testCookieRequestCurl() {
546 if ( !self::$has_curl ) {
547 $this->markTestIncomplete( "This test requires curl." );
548 }
549
550 Http::$httpEngine = 'curl';
551 self::runCookieRequests();
552 }
553
554 }