X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=tests%2Fclient021.phpt;h=702685dd125f6efb8c30b976d9f2c9a4d1271195;hp=ef649093e077d243b11379f2df031d4581155478;hb=531e6007bd10cbda6e1e96a9c27228086d85c5a9;hpb=a2aa970a129880a247baea08927f0d84188a0b19 diff --git a/tests/client021.phpt b/tests/client021.phpt index ef64909..702685d 100644 --- a/tests/client021.phpt +++ b/tests/client021.phpt @@ -12,124 +12,130 @@ include "helper/server.inc"; echo "Test\n"; -function dump($f) { - return; - readfile($f); +function dump() { + global $tmpfile, $section; + printf("# %s\n", $section); + foreach (file($tmpfile) as $line) { + if ($line[0] === "#" || $line === "\n") { + continue; + } + printf("%s:\t%s", $tmpfile, $line); + } } -function cookies($client) { - foreach ($client->getResponse()->getCookies() as $cookie) { - echo trim($cookie), "\n"; +function send_and_check($client, $cmp) { + global $section, $request; + $client->requeue($request)->send(); + foreach ($client->getResponse()->getCookies() as $list) { + foreach ($list->getCookies() as $name => $value) { + if ($cmp[$name] != $value) { + printf("# %s\nExpected %s=%s, got %s\n", + $section, $name, $cmp[$name], $value); + } + } } + #dump(); } $tmpfile = tempnam(sys_get_temp_dir(), "cookie."); $request = new http\Client\Request("GET", "http://localhost"); +$section = "distinct clients"; + server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port)); $client = new http\Client; - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 1]); }); server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port)); $client = new http\Client; - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 1]); }); server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port)); $client = new http\Client; - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 1]); }); +$section = "reusing curl handles"; + server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port)); $client = new http\Client("curl", "test"); - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 1]); }); server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port)); $client = new http\Client("curl", "test"); - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 2]); }); server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port)); $client = new http\Client("curl", "test"); - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 3]); }); +$section = "distict client with persistent cookies"; + $request->setOptions(array("cookiestore" => $tmpfile)); server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port)); $client = new http\Client; - cookies($client->requeue($request)->send()); -dump($tmpfile); - cookies($client->requeue($request)->send()); -dump($tmpfile); - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 1]); + send_and_check($client, ["counter" => 2]); + send_and_check($client, ["counter" => 3]); }); server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port)); $client = new http\Client; - cookies($client->requeue($request)->send()); -dump($tmpfile); - cookies($client->requeue($request)->send()); -dump($tmpfile); - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 4]); + send_and_check($client, ["counter" => 5]); + send_and_check($client, ["counter" => 6]); }); +$section = "distinct client with persistent cookies, but session cookies removed"; + server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port, "cookiesession" => true)); $client = new http\Client; - cookies($client->requeue($request)->send()); -dump($tmpfile); - cookies($client->requeue($request)->send()); -dump($tmpfile); - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 1]); + send_and_check($client, ["counter" => 1]); + send_and_check($client, ["counter" => 1]); }); +$section = "distinct client with persistent cookies, and session cookies kept"; + server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port, "cookiesession" => false)); $client = new http\Client; - cookies($client->requeue($request)->send()); -dump($tmpfile); - cookies($client->requeue($request)->send()); -dump($tmpfile); - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 2]); + send_and_check($client, ["counter" => 3]); + send_and_check($client, ["counter" => 4]); }); +$section = "reusing curl handles without persistent cookies and disabling cookie_share"; -(new http\Client("curl", "test"))->configure(["share_cookies" => false]); -$request->setOptions(["cookiestore" => null]); +$c = new http\Client("curl", "test"); +$c->configure(array("share_cookies" => false)); +$c = null; +$request->setOptions(array("cookiestore" => null)); server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port)); $client = new http\Client("curl", "test"); - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 1]); }); server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port)); $client = new http\Client("curl", "test"); - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 1]); }); server("cookie.inc", function($port) use($request, $tmpfile) { $request->setOptions(array("port" => $port)); $client = new http\Client("curl", "test"); - cookies($client->requeue($request)->send()); -dump($tmpfile); + send_and_check($client, ["counter" => 1]); }); @@ -139,25 +145,4 @@ unlink($tmpfile); ===DONE=== --EXPECT-- Test -counter=1; -counter=1; -counter=1; -counter=1; -counter=2; -counter=3; -counter=1; -counter=2; -counter=3; -counter=4; -counter=5; -counter=6; -counter=1; -counter=1; -counter=1; -counter=2; -counter=3; -counter=4; -counter=1; -counter=1; -counter=1; ===DONE===