$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");
$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());
}
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));
$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));
+ }
}
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);
}
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() {