tests++
authorMichael Wallner <mike@php.net>
Wed, 12 Dec 2012 11:53:02 +0000 (11:53 +0000)
committerMichael Wallner <mike@php.net>
Wed, 12 Dec 2012 11:53:02 +0000 (11:53 +0000)
phpunit/EncodingTest.php
phpunit/HeaderTest.php
phpunit/QueryStringTest.php
tests/response003.phpt

index b57e2a4ccff11ca09c17054bcaf51ed3cf6c132a..46426130f9ef46b90e9af6db0cd0339f4fad901d 100644 (file)
@@ -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());
         }
index 41d3af82c4ae6ea981b3b24a4b2bf7577133d388..b34adcb5e9e525183d71f0129b1008645552c575 100644 (file)
@@ -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));
+    }
 }
index 2fde23ac7695d5014742925df17169b366127ef2..fb2eb4741f253dba81be89fa13e2f7627135d07e 100644 (file)
@@ -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() {
index 8331e0f8c721cb1c2759c17c8ec4961cdf2a3358..d2f91c1e59b30eeec3a9558f675ef506dd67bc97 100644 (file)
@@ -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();