X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fclient021.phpt;h=aaf462556b6f02aaf5176ac181c65dfd629c245d;hb=f3b5b84017131e5354aacaa01836d317dad38686;hp=c31afd0c3e9e705efddb83b358834c031d01e711;hpb=343738ad56eb70017704fdac57cf0d74da3d0f2e;p=m6w6%2Fext-http diff --git a/tests/client021.phpt b/tests/client021.phpt index c31afd0..aaf4625 100644 --- a/tests/client021.phpt +++ b/tests/client021.phpt @@ -4,6 +4,9 @@ client cookies --FILE-- 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; + send_and_check($client, ["counter" => 1]); +}); +server("cookie.inc", function($port) use($request, $tmpfile) { + $request->setOptions(array("port" => $port)); + $client = new http\Client; + send_and_check($client, ["counter" => 1]); +}); +server("cookie.inc", function($port) use($request, $tmpfile) { + $request->setOptions(array("port" => $port)); + $client = new http\Client; + 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"); + 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"); + 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"); + 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; - echo $client->requeue($request)->send()->getResponse(); -#dump($tmpfile); - echo $client->requeue($request)->send()->getResponse(); -#dump($tmpfile); - echo $client->requeue($request)->send()->getResponse(); -#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; - echo $client->requeue($request)->send()->getResponse(); -#dump($tmpfile); - echo $client->requeue($request)->send()->getResponse(); -#dump($tmpfile); - echo $client->requeue($request)->send()->getResponse(); -#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; - echo $client->requeue($request)->send()->getResponse(); -dump($tmpfile); - echo $client->requeue($request)->send()->getResponse(); -dump($tmpfile); - echo $client->requeue($request)->send()->getResponse(); -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; - echo $client->requeue($request)->send()->getResponse(); -dump($tmpfile); - echo $client->requeue($request)->send()->getResponse(); -dump($tmpfile); - echo $client->requeue($request)->send()->getResponse(); -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"; + +$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"); + 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"); + 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"); + send_and_check($client, ["counter" => 1]); +}); + unlink($tmpfile); @@ -70,54 +148,4 @@ unlink($tmpfile); ===DONE=== --EXPECT-- Test -HTTP/1.1 200 OK -Set-Cookie: counter=1; -Etag: "" -X-Original-Transfer-Encoding: chunked -HTTP/1.1 200 OK -Set-Cookie: counter=2; -Etag: "" -X-Original-Transfer-Encoding: chunked -HTTP/1.1 200 OK -Set-Cookie: counter=3; -Etag: "" -X-Original-Transfer-Encoding: chunked -HTTP/1.1 200 OK -Set-Cookie: counter=4; -Etag: "" -X-Original-Transfer-Encoding: chunked -HTTP/1.1 200 OK -Set-Cookie: counter=5; -Etag: "" -X-Original-Transfer-Encoding: chunked -HTTP/1.1 200 OK -Set-Cookie: counter=6; -Etag: "" -X-Original-Transfer-Encoding: chunked -HTTP/1.1 200 OK -Set-Cookie: counter=1; -Etag: "" -X-Original-Transfer-Encoding: chunked -HTTP/1.1 200 OK -Set-Cookie: counter=1; -Etag: "" -X-Original-Transfer-Encoding: chunked -HTTP/1.1 200 OK -Set-Cookie: counter=1; -Etag: "" -X-Original-Transfer-Encoding: chunked -HTTP/1.1 200 OK -Set-Cookie: counter=2; -Etag: "" -X-Original-Transfer-Encoding: chunked -HTTP/1.1 200 OK -Set-Cookie: counter=3; -Etag: "" -X-Original-Transfer-Encoding: chunked -HTTP/1.1 200 OK -Set-Cookie: counter=4; -Etag: "" -X-Original-Transfer-Encoding: chunked ===DONE=== ---XFAIL-- -TBD