Fix problem of incorrect Status message use.
[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 $r = HttpRequest::factory( "http://www.example.com/this-file-does-not-exist" );
118 $er = $r->execute();
119 $this->assertRegexp("/404 Not Found/", $er->getWikiText());
120 }
121
122 function testFailureDefault() {
123 Http::$httpEngine = false;
124 self::runHTTPFailureChecks();
125 }
126
127 function testFailurePhp() {
128 if ( !self::$has_fopen ) {
129 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
130 }
131
132 Http::$httpEngine = "php";
133 self::runHTTPFailureChecks();
134 }
135
136 function testFailureCurl() {
137 if ( !self::$has_curl ) {
138 $this->markTestIncomplete( "This test requires curl." );
139 }
140
141 Http::$httpEngine = "curl";
142 self::runHTTPFailureChecks();
143 }
144
145 /* ./phase3/includes/Import.php:1108: $data = Http::request( $method, $url ); */
146 /* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */
147 /* ./includes/Import.php:1134: return ImportStreamSource::newFromURL( $url, "POST" ); */
148 function runHTTPRequests($proxy=null) {
149 $opt = array();
150
151 if($proxy) {
152 $opt['proxy'] = $proxy;
153 } elseif( $proxy === false ) {
154 $opt['noProxy'] = true;
155 }
156
157 /* no postData here because the only request I could find in code so far didn't have any */
158 foreach ( $this->test_requesturl as $u ) {
159 $r = Http::request( "POST", $u, $opt );
160 $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with ".Http::$httpEngine );
161 }
162 }
163
164 function testRequestDefault() {
165 Http::$httpEngine = false;
166 self::runHTTPRequests();
167 }
168
169 function testRequestPhp() {
170 if ( !self::$has_fopen ) {
171 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
172 }
173
174 Http::$httpEngine = "php";
175 self::runHTTPRequests();
176 }
177
178 function testRequestCurl() {
179 if ( !self::$has_curl ) {
180 $this->markTestIncomplete( "This test requires curl." );
181 }
182
183 Http::$httpEngine = "curl";
184 self::runHTTPRequests();
185 }
186
187 /* ./extensions/SpamBlacklist/SpamBlacklist_body.php:164: $httpText = Http::get( $fileName ); */
188 /* ./extensions/ApiSVGProxy/ApiSVGProxy.body.php:44: $contents = Http::get( $file->getFullUrl() ); */
189 /* ./extensions/BookInformation/drivers/IsbnDb.php:24: if( ( $xml = Http::get( $uri ) ) !== false ) { */
190 /* ./extensions/BookInformation/drivers/Amazon.php:23: if( ( $xml = Http::get( $uri ) ) !== false ) { */
191 /* ./extensions/TitleBlacklist/TitleBlacklist.list.php:217: $result = Http::get( $url ); */
192 /* ./extensions/TSPoll/TSPoll.php:68: $get_server = Http::get( 'http://toolserver.org/~jan/poll/dev/main.php?page=wiki_output&id='.$id ); */
193 /* ./extensions/TSPoll/TSPoll.php:70: $get_server = Http::get( 'http://toolserver.org/~jan/poll/main.php?page=wiki_output&id='.$id ); */
194 /* ./extensions/DoubleWiki/DoubleWiki.php:56: $translation = Http::get( $url.$sep.'action=render' ); */
195 /* ./extensions/ExternalPages/ExternalPages_body.php:177: $serializedText = Http::get( $this->mPageURL ); */
196 /* ./extensions/Translate/utils/TranslationHelpers.php:143: $suggestions = Http::get( $url, $timeout ); */
197 /* ./extensions/Translate/SpecialImportTranslations.php:169: $filedata = Http::get( $url ); ; */
198 /* ./extensions/Translate/TranslateEditAddons.php:338: $suggestions = Http::get( $url, $timeout ); */
199 /* ./extensions/SecurePoll/includes/user/Auth.php:283: $value = Http::get( $url, 20, $curlParams ); */
200 /* ./extensions/DumpHTML/dumpHTML.inc:778: $contents = Http::get( $url ); */
201 /* ./extensions/DumpHTML/dumpHTML.inc:1298: $contents = Http::get( $sourceUrl ); */
202 /* ./extensions/DumpHTML/dumpHTML.inc:1373: $contents = Http::get( $sourceUrl ); */
203 /* ./phase3/maintenance/rebuildInterwiki.inc:101: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
204 /* ./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' ); */
205 /* ./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' ); */
206 /* ./phase3/maintenance/dumpInterwiki.inc:95: $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); */
207 /* ./phase3/includes/parser/Parser.php:3204: $text = Http::get($url); */
208 /* ./phase3/includes/filerepo/ForeignAPIRepo.php:131: $data = Http::get( $url ); */
209 /* ./phase3/includes/filerepo/ForeignAPIRepo.php:205: $thumb = Http::get( $foreignUrl ); */
210 /* ./phase3/includes/filerepo/File.php:1105: $res = Http::get( $renderUrl ); */
211 /* ./phase3/includes/GlobalFunctions.php:2760: * @deprecated Use Http::get() instead */
212 /* ./phase3/includes/GlobalFunctions.php:2764: return Http::get( $url ); */
213 /* ./phase3/includes/ExternalStoreHttp.php:18: $ret = Http::get( $url ); */
214 /* ./phase3/includes/Import.php:357: $data = Http::get( $src ); */
215 /* ./extensions/ExternalData/ED_Utils.php:291: return Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
216 /* ./extensions/ExternalData/ED_Utils.php:293: return Http::get( $url ); */
217 /* ./extensions/ExternalData/ED_Utils.php:306: $page = Http::get( $url, 'default', array(CURLOPT_SSL_VERIFYPEER => false) ); */
218 /* ./extensions/ExternalData/ED_Utils.php:308: $page = Http::get( $url ); */
219 /* ./extensions/CodeReview/backend/Subversion.php:320: $blob = Http::get( $target, $this->mTimeout ); */
220 /* ./extensions/AmazonPlus/AmazonPlus.php:214: $this->response = Http::get( $urlstr ); */
221 /* ./extensions/StaticWiki/StaticWiki.php:24: $text = Http::get( $url ) ; */
222 /* ./extensions/StaticWiki/StaticWiki.php:64: $history = Http::get ( $wgStaticWikiExternalSite . "index.php?title=" . urlencode ( $url_title ) . "&action=history" ) ; */
223 /* ./extensions/Configure/scripts/findSettings.php:126: $cont = Http::get( "http://www.mediawiki.org/w/index.php?title={$page}&action=raw" ); */
224 /* ./extensions/TorBlock/TorBlock.class.php:148: $data = Http::get( $url ); */
225 /* ./extensions/HoneypotIntegration/HoneypotIntegration.class.php:60: $data = Http::get( $wgHoneypotURLSource, 'default', */
226 /* ./extensions/SemanticForms/includes/SF_Utils.inc:378: $page_contents = Http::get($url); */
227 /* ./extensions/LocalisationUpdate/LocalisationUpdate.class.php:172: $basefilecontents = Http::get( $basefile ); */
228 /* ./extensions/APC/SpecialAPC.php:245: $rss = Http::get( 'http://pecl.php.net/feeds/pkg_apc.rss' ); */
229 /* ./extensions/Interlanguage/Interlanguage.php:56: $a = Http::get( $url ); */
230 /* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */
231 function runHTTPGets($proxy=null) {
232 $opt = array();
233
234 if($proxy) {
235 $opt['proxy'] = $proxy;
236 } elseif( $proxy === false ) {
237 $opt['noProxy'] = true;
238 }
239
240 foreach ( $this->test_geturl as $u ) {
241 $r = Http::get( $u, 30, $opt ); /* timeout of 30s */
242 $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with ".Http::$httpEngine );
243 }
244 }
245
246 function testGetDefault() {
247 Http::$httpEngine = false;
248 self::runHTTPGets();
249 }
250
251 function testGetPhp() {
252 if ( !self::$has_fopen ) {
253 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
254 }
255
256 Http::$httpEngine = "php";
257 self::runHTTPGets();
258 }
259
260 function testGetCurl() {
261 if ( !self::$has_curl ) {
262 $this->markTestIncomplete( "This test requires curl." );
263 }
264
265 Http::$httpEngine = "curl";
266 self::runHTTPGets();
267 }
268
269 /* ./phase3/maintenance/parserTests.inc:1618: return Http::post( $url, array( 'postData' => wfArrayToCGI( $data ) ) ); */
270 function runHTTPPosts($proxy=null) {
271 $opt = array();
272
273 if($proxy) {
274 $opt['proxy'] = $proxy;
275 } elseif( $proxy === false ) {
276 $opt['noProxy'] = true;
277 }
278
279 foreach ( $this->test_posturl as $u => $postData ) {
280 $opt['postData'] = $postData;
281 $r = Http::post( $u, $opt );
282 $this->assertEquals( self::$content["POST $u => $postData"], "$r",
283 "POST $u (postData=$postData) with ".Http::$httpEngine );
284 }
285 }
286
287 function testPostDefault() {
288 Http::$httpEngine = false;
289 self::runHTTPPosts();
290 }
291
292 function testPostPhp() {
293 if ( !self::$has_fopen ) {
294 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
295 }
296
297 Http::$httpEngine = "php";
298 self::runHTTPPosts();
299 }
300
301 function testPostCurl() {
302 if ( !self::$has_curl ) {
303 $this->markTestIncomplete( "This test requires curl." );
304 }
305
306 Http::$httpEngine = "curl";
307 self::runHTTPPosts();
308 }
309
310 function runProxyRequests() {
311 if(!self::$has_proxy) {
312 $this->markTestIncomplete( "This test requires a proxy." );
313 }
314 self::runHTTPGets(self::$proxy);
315 self::runHTTPPosts(self::$proxy);
316 self::runHTTPRequests(self::$proxy);
317
318 // Set false here to do noProxy
319 self::runHTTPGets(false);
320 self::runHTTPPosts(false);
321 self::runHTTPRequests(false);
322 }
323
324 function testProxyDefault() {
325 Http::$httpEngine = false;
326 self::runProxyRequests();
327 }
328
329 function testProxyPhp() {
330 if ( !self::$has_fopen ) {
331 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
332 }
333
334 Http::$httpEngine = 'php';
335 self::runProxyRequests();
336 }
337
338 function testProxyCurl() {
339 if ( !self::$has_curl ) {
340 $this->markTestIncomplete( "This test requires curl." );
341 }
342
343 Http::$httpEngine = 'curl';
344 self::runProxyRequests();
345 }
346
347 function testIsLocalUrl() {
348 }
349
350 /* ./extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php:559: $user_agent = Http::userAgent(); */
351 function testUserAgent() {
352 }
353
354 function testIsValidUrl() {
355 }
356
357 function testValidateCookieDomain() {
358 $this->assertFalse( Cookie::validateCookieDomain( "co.uk" ) );
359 $this->assertFalse( Cookie::validateCookieDomain( ".co.uk" ) );
360 $this->assertFalse( Cookie::validateCookieDomain( "gov.uk" ) );
361 $this->assertFalse( Cookie::validateCookieDomain( ".gov.uk" ) );
362 $this->assertTrue( Cookie::validateCookieDomain( "supermarket.uk" ) );
363 $this->assertFalse( Cookie::validateCookieDomain( "uk" ) );
364 $this->assertFalse( Cookie::validateCookieDomain( ".uk" ) );
365 $this->assertFalse( Cookie::validateCookieDomain( "127.0.0." ) );
366 $this->assertFalse( Cookie::validateCookieDomain( "127." ) );
367 $this->assertFalse( Cookie::validateCookieDomain( "127.0.0.1." ) );
368 $this->assertTrue( Cookie::validateCookieDomain( "127.0.0.1" ) );
369 $this->assertFalse( Cookie::validateCookieDomain( "333.0.0.1" ) );
370 $this->assertTrue( Cookie::validateCookieDomain( "example.com" ) );
371 $this->assertFalse( Cookie::validateCookieDomain( "example.com." ) );
372 $this->assertTrue( Cookie::validateCookieDomain( ".example.com" ) );
373
374 $this->assertTrue( Cookie::validateCookieDomain( ".example.com", "www.example.com" ) );
375 $this->assertFalse( Cookie::validateCookieDomain( "example.com", "www.example.com" ) );
376 $this->assertTrue( Cookie::validateCookieDomain( "127.0.0.1", "127.0.0.1" ) );
377 $this->assertFalse( Cookie::validateCookieDomain( "127.0.0.1", "localhost" ) );
378
379
380 }
381
382 function testSetCooke() {
383 $c = new MockCookie( "name", "value",
384 array(
385 "domain" => "ac.th",
386 "path" => "/path/",
387 ) );
388 $this->assertFalse($c->canServeDomain("ac.th"));
389
390 $c = new MockCookie( "name", "value",
391 array(
392 "domain" => "example.com",
393 "path" => "/path/",
394 ) );
395
396 $this->assertTrue($c->canServeDomain("example.com"));
397 $this->assertFalse($c->canServeDomain("www.example.com"));
398
399 $c = new MockCookie( "name", "value",
400 array(
401 "domain" => ".example.com",
402 "path" => "/path/",
403 ) );
404
405 $this->assertFalse($c->canServeDomain("www.example.net"));
406 $this->assertFalse($c->canServeDomain("example.com"));
407 $this->assertTrue($c->canServeDomain("www.example.com"));
408
409 $this->assertFalse($c->canServePath("/"));
410 $this->assertFalse($c->canServePath("/bogus/path/"));
411 $this->assertFalse($c->canServePath("/path"));
412 $this->assertTrue($c->canServePath("/path/"));
413
414 $this->assertTrue($c->isUnExpired());
415
416 $this->assertEquals("", $c->serializeToHttpRequest("/path/", "www.example.net"));
417 $this->assertEquals("", $c->serializeToHttpRequest("/", "www.example.com"));
418 $this->assertEquals("name=value", $c->serializeToHttpRequest("/path/", "www.example.com"));
419
420 $c = new MockCookie( "name", "value",
421 array(
422 "domain" => "www.example.com",
423 "path" => "/path/",
424 ) );
425 $this->assertFalse($c->canServeDomain("example.com"));
426 $this->assertFalse($c->canServeDomain("www.example.net"));
427 $this->assertTrue($c->canServeDomain("www.example.com"));
428
429 $c = new MockCookie( "name", "value",
430 array(
431 "domain" => ".example.com",
432 "path" => "/path/",
433 "expires" => "-1 day",
434 ) );
435 $this->assertFalse($c->isUnExpired());
436 $this->assertEquals("", $c->serializeToHttpRequest("/path/", "www.example.com"));
437
438 $c = new MockCookie( "name", "value",
439 array(
440 "domain" => ".example.com",
441 "path" => "/path/",
442 "expires" => "+1 day",
443 ) );
444 $this->assertTrue($c->isUnExpired());
445 $this->assertEquals("name=value", $c->serializeToHttpRequest("/path/", "www.example.com"));
446 }
447
448 function testCookieJarSetCookie() {
449 $cj = new CookieJar;
450 $cj->setCookie( "name", "value",
451 array(
452 "domain" => ".example.com",
453 "path" => "/path/",
454 ) );
455 $cj->setCookie( "name2", "value",
456 array(
457 "domain" => ".example.com",
458 "path" => "/path/sub",
459 ) );
460 $cj->setCookie( "name3", "value",
461 array(
462 "domain" => ".example.com",
463 "path" => "/",
464 ) );
465 $cj->setCookie( "name4", "value",
466 array(
467 "domain" => ".example.net",
468 "path" => "/path/",
469 ) );
470 $cj->setCookie( "name5", "value",
471 array(
472 "domain" => ".example.net",
473 "path" => "/path/",
474 "expires" => "-1 day",
475 ) );
476
477 $this->assertEquals("name4=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
478 $this->assertEquals("name3=value", $cj->serializeToHttpRequest("/", "www.example.com"));
479 $this->assertEquals("name=value; name3=value", $cj->serializeToHttpRequest("/path/", "www.example.com"));
480
481 $cj->setCookie( "name5", "value",
482 array(
483 "domain" => ".example.net",
484 "path" => "/path/",
485 "expires" => "+1 day",
486 ) );
487 $this->assertEquals("name4=value; name5=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
488
489 $cj->setCookie( "name4", "value",
490 array(
491 "domain" => ".example.net",
492 "path" => "/path/",
493 "expires" => "-1 day",
494 ) );
495 $this->assertEquals("name5=value", $cj->serializeToHttpRequest("/path/", "www.example.net"));
496 }
497
498 function testParseResponseHeader() {
499 $cj = new CookieJar;
500
501 $h[] = "Set-Cookie: name4=value; domain=.example.com; path=/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
502 $cj->parseCookieResponseHeader( $h[0], "www.example.com" );
503 $this->assertEquals("name4=value", $cj->serializeToHttpRequest("/", "www.example.com"));
504
505 $h[] = "name4=value2; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
506 $cj->parseCookieResponseHeader( $h[1], "www.example.com" );
507 $this->assertEquals("", $cj->serializeToHttpRequest("/", "www.example.com"));
508 $this->assertEquals("name4=value2", $cj->serializeToHttpRequest("/path/", "www.example.com"));
509
510 $h[] = "name5=value3; domain=.example.com; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
511 $cj->parseCookieResponseHeader( $h[2], "www.example.com" );
512 $this->assertEquals("name4=value2; name5=value3", $cj->serializeToHttpRequest("/path/", "www.example.com"));
513
514 $h[] = "name6=value3; domain=.example.net; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
515 $cj->parseCookieResponseHeader( $h[3], "www.example.com" );
516 $this->assertEquals("", $cj->serializeToHttpRequest("/path/", "www.example.net"));
517
518 $h[] = "name6=value0; domain=.example.net; path=/path/; expires=Mon, 09-Dec-1999 13:46:00 GMT";
519 $cj->parseCookieResponseHeader( $h[4], "www.example.net" );
520 $this->assertEquals("", $cj->serializeToHttpRequest("/path/", "www.example.net"));
521
522 $h[] = "name6=value4; domain=.example.net; path=/path/; expires=Mon, 09-Dec-2029 13:46:00 GMT";
523 $cj->parseCookieResponseHeader( $h[5], "www.example.net" );
524 $this->assertEquals("name6=value4", $cj->serializeToHttpRequest("/path/", "www.example.net"));
525 }
526
527 function runCookieRequests() {
528 $r = HttpRequest::factory( "http://www.php.net/manual" );
529 $r->execute();
530
531 $jar = $r->getCookieJar();
532
533 $this->assertThat( $jar, $this->isInstanceOf( 'CookieJar' ) );
534 $this->assertRegExp( '/^COUNTRY=.*; LAST_LANG=.*$/', $jar->serializeToHttpRequest( "/search?q=test", "www.php.net" ) );
535 $this->assertEquals( '', $jar->serializeToHttpRequest( "/search?q=test", "www.php.com" ) );
536 }
537
538 function testCookieRequestDefault() {
539 Http::$httpEngine = false;
540 self::runCookieRequests();
541 }
542 function testCookieRequestPhp() {
543 if ( !self::$has_fopen ) {
544 $this->markTestIncomplete( "This test requires allow_url_fopen=true." );
545 }
546
547 Http::$httpEngine = 'php';
548 self::runCookieRequests();
549 }
550 function testCookieRequestCurl() {
551 if ( !self::$has_curl ) {
552 $this->markTestIncomplete( "This test requires curl." );
553 }
554
555 Http::$httpEngine = 'curl';
556 self::runCookieRequests();
557 }
558 }