X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=phpunit%2FRequestTest.php;h=0072714c4c953789cd389da55125afd242ba3e76;hb=0327131cf87a5be32585fea1291178b60a359cbf;hp=a327f6dff2440eb49a26a118dadeb6a9ae649e5d;hpb=575f4ce7a82c2c2bf4fb597f6a3a3de077403910;p=m6w6%2Fext-http diff --git a/phpunit/RequestTest.php b/phpunit/RequestTest.php index a327f6d..0072714 100644 --- a/phpunit/RequestTest.php +++ b/phpunit/RequestTest.php @@ -28,7 +28,8 @@ class RequestTest extends PHPUnit_Framework_TestCase protected $r; function setUp() { - $this->r = (new http\Client\Factory)->createClient(); + $f = new http\Client\Factory; + $this->r = $f->createClient(); $this->r->setOptions( array( "connecttimeout" => 30, @@ -55,19 +56,20 @@ class RequestTest extends PHPUnit_Framework_TestCase } function testObserver() { + $test = $this; $this->r->attach($o1 = new ProgressObserver1); $this->r->attach($o2 = new ProgressObserver2); $this->r->attach( $o3 = new CallbackObserver( - function ($r) { + function ($r) use ($test) { $p = (array) $r->getProgress(); - $this->assertArrayHasKey("started", $p); - $this->assertArrayHasKey("finished", $p); - $this->assertArrayHasKey("dlnow", $p); - $this->assertArrayHasKey("ulnow", $p); - $this->assertArrayHasKey("dltotal", $p); - $this->assertArrayHasKey("ultotal", $p); - $this->assertArrayHasKey("info", $p); + $test->assertArrayHasKey("started", $p); + $test->assertArrayHasKey("finished", $p); + $test->assertArrayHasKey("dlnow", $p); + $test->assertArrayHasKey("ulnow", $p); + $test->assertArrayHasKey("dltotal", $p); + $test->assertArrayHasKey("ultotal", $p); + $test->assertArrayHasKey("info", $p); } ) ); @@ -91,7 +93,27 @@ class RequestTest extends PHPUnit_Framework_TestCase $this->assertNotContains("Cookie", (string) $this->r->getRequestMessage()); $this->r->send(null); $this->assertContains("Cookie", (string) $this->r->getRequestMessage()); - $this->assertCount(2, $this->r->getResponseMessage()->getCookies()); + $cookies = $this->r->getResponseMessage()->getCookies(0, array("extra")); + $this->assertCount(2, $cookies); + foreach ($cookies as $cookie) { + if ($cookie->getCookie("perm")) { + $this->assertTrue(0 < $cookie->getExpires()); + } + if ($cookie->getCookie("temp")) { + $this->assertEquals(-1, $cookie->getExpires()); + } + } + $this->r->send(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.cookie1.php")); + $cookies = $this->r->getResponseMessage()->getCookies(0, array("bar")); + $this->assertCount(1, $cookies); + $cookies = $cookies[0]; + $this->assertEquals(array("bar"=>"foo"), $cookies->getExtras()); + $this->assertEquals(array("foo"=>"bar"), $cookies->getCookies()); + $cookies = $this->r->getResponseMessage()->getCookies(0, array("foo")); + $this->assertCount(1, $cookies); + $cookies = $cookies[0]; + $this->assertEquals(array("foo"=>"bar","bar"=>"foo"), $cookies->getCookies()); + $this->assertEquals(array(), $cookies->getExtras()); } function testResetCookies() {