From: Michael Wallner Date: Wed, 12 Dec 2012 11:53:02 +0000 (+0000) Subject: tests++ X-Git-Tag: RELEASE_2_1_0_RC3~10^2^2~74 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=cd4b861addec695f3b7d78c5184294c34c5ab732 tests++ --- diff --git a/phpunit/EncodingTest.php b/phpunit/EncodingTest.php index b57e2a4..4642613 100644 --- a/phpunit/EncodingTest.php +++ b/phpunit/EncodingTest.php @@ -62,9 +62,12 @@ class EncodingStreamTest extends PHPUnit_Framework_TestCase { $data .= $dech->update(sprintf("%lx\r\n%s\r\n", strlen($line), $line)); } else { $data .= $dech->update(sprintf("%lx\r\n", strlen($line))); + $data .= $dech->flush(); $data .= $dech->update($line); + $data .= $dech->flush(); $data .= $dech->update("\r\n"); } + $dech->flush(); $this->assertFalse($dech->done()); } $data .= $dech->update("0\r\n"); @@ -141,11 +144,14 @@ class EncodingStreamTest extends PHPUnit_Framework_TestCase { $file = file(__FILE__); $data = ""; foreach ($file as $line) { + $data .= $infl->flush(); if (strlen($temp = $defl->update($line))) { $data .= $infl->update($temp); + $data .= $infl->flush(); } if (strlen($temp = $defl->flush())) { $data .= $infl->update($temp); + $data .= $infl->flush(); } $this->assertTrue($defl->done()); } diff --git a/phpunit/HeaderTest.php b/phpunit/HeaderTest.php index 41d3af8..b34adcb 100644 --- a/phpunit/HeaderTest.php +++ b/phpunit/HeaderTest.php @@ -2,16 +2,24 @@ class HeaderTest extends PHPUnit_Framework_TestCase { function setUp() { - $this->h = new http\Header("foo", "bar"); + } function testString() { - $this->assertEquals("Foo: bar", (string) $this->h); + $h = new http\Header("foo", "bar"); + $this->assertEquals("Foo: bar", (string) $h); } function testSerialize() { - $this->assertEquals("Foo: bar", (string) unserialize(serialize($this->h))); + $h = new http\Header("foo", "bar"); + $this->assertEquals("Foo: bar", (string) unserialize(serialize($h))); } + function testNumeric() { + $h = new http\Header(123, 456); + $this->assertEquals("123: 456", (string) $h); + $this->assertEquals("123: 456", (string) unserialize(serialize($h))); + } + function testMatch() { $ae = new http\Header("Accept-encoding", "gzip, deflate"); $this->assertTrue($ae->match("gzip", http\Header::MATCH_WORD)); @@ -24,4 +32,29 @@ class HeaderTest extends PHPUnit_Framework_TestCase { $this->assertFalse($ae->match("zip", http\Header::MATCH_WORD)); $this->assertFalse($ae->match("gzip", http\Header::MATCH_FULL)); } + + function testNegotiate() { + $a = new http\Header("Accept", "text/html, text/plain;q=0.5, */*;q=0"); + $this->assertEquals("text/html", $a->negotiate(array("text/plain","text/html"))); + $this->assertEquals("text/html", $a->negotiate(array("text/plain","text/html"), $rs)); + $this->assertEquals(array("text/html"=>0.99, "text/plain"=>0.5), $rs); + $this->assertEquals("text/plain", $a->negotiate(array("foo/bar", "text/plain"), $rs)); + $this->assertEquals(array("text/plain"=>0.5), $rs); + $this->assertEquals("foo/bar", $a->negotiate(array("foo/bar"), $rs)); + $this->assertEquals(array(), $rs); + } + + function testParse() { + $header = "Foo: bar\nBar: foo\n"; + $this->assertEquals(array("Foo"=>"bar","Bar"=>"foo"), http\Header::parse($header)); + $header = http\Header::parse($header, "http\\Header"); + $this->assertCount(2, $header); + $this->assertContainsOnlyInstancesOf("http\\Header", $header); + } + + function testParseError() { + $header = "wass\nup"; + $this->setExpectedException("PHPUnit_Framework_Error_Warning", "Could not parse headers"); + $this->assertFalse(http\Header::parse($header)); + } } diff --git a/phpunit/QueryStringTest.php b/phpunit/QueryStringTest.php index 2fde23a..fb2eb47 100644 --- a/phpunit/QueryStringTest.php +++ b/phpunit/QueryStringTest.php @@ -2,8 +2,8 @@ class QueryStringTest extends PHPUnit_Framework_TestCase { protected $q; - protected $s = "a=b&r[]=0&r[]=1&r[]=2&rr[][]=00&rr[][]=10&1=2"; - protected $e = "a=b&r%5B0%5D=0&r%5B1%5D=1&r%5B2%5D=2&rr%5B0%5D%5B0%5D=00&rr%5B1%5D%5B0%5D=10&1=2"; + protected $s = "a=b&r[]=0&r[]=1&r[]=2&rr[][]=00&rr[][]=01&1=2"; + protected $e = "a=b&r%5B0%5D=0&r%5B1%5D=1&r%5B2%5D=2&rr%5B0%5D%5B0%5D=00&rr%5B0%5D%5B1%5D=01&1=2"; function setUp() { $this->q = new http\QueryString($this->s); @@ -31,7 +31,7 @@ class QueryStringTest extends PHPUnit_Framework_TestCase { } function testGetRR() { - $this->assertEquals(array(array("00"),array("10")), $this->q->get("rr")); + $this->assertEquals(array(array("00","01")), $this->q->get("rr")); } function testGet1() { diff --git a/tests/response003.phpt b/tests/response003.phpt index 8331e0f..d2f91c1 100644 --- a/tests/response003.phpt +++ b/tests/response003.phpt @@ -12,7 +12,7 @@ a=b $r = new http\Env\Response; $r->setContentType("text/plain"); $r->setContentDisposition( - array("attachment" => array("filename" => basename(__FILE__))) + array("attachment" => array(array("filename" => basename(__FILE__)))) ); $r->setBody(new http\Message\Body(fopen(__FILE__, "rb"))); $r->send();