3 class HeaderTest
extends PHPUnit_Framework_TestCase
{
7 function testString() {
8 $h = new http\
Header("foo", "bar");
9 $this->assertEquals("Foo: bar", (string) $h);
12 function testSerialize() {
13 $h = new http\
Header("foo", "bar");
14 $this->assertEquals("Foo: bar", (string) unserialize(serialize($h)));
17 function testNumeric() {
18 $h = new http\
Header(123, 456);
19 $this->assertEquals("123: 456", (string) $h);
20 $this->assertEquals("123: 456", (string) unserialize(serialize($h)));
23 function testMatch() {
24 $ae = new http\
Header("Accept-encoding", "gzip, deflate");
25 $this->assertTrue($ae->match("gzip", http\Header
::MATCH_WORD
));
26 $this->assertTrue($ae->match("gzip", http\Header
::MATCH_WORD|http\Header
::MATCH_CASE
));
27 $this->assertFalse($ae->match("gzip", http\Header
::MATCH_STRICT
));
28 $this->assertTrue($ae->match("deflate", http\Header
::MATCH_WORD
));
29 $this->assertTrue($ae->match("deflate", http\Header
::MATCH_WORD|http\Header
::MATCH_CASE
));
30 $this->assertFalse($ae->match("deflate", http\Header
::MATCH_STRICT
));
32 $this->assertFalse($ae->match("zip", http\Header
::MATCH_WORD
));
33 $this->assertFalse($ae->match("gzip", http\Header
::MATCH_FULL
));
36 function testNegotiate() {
37 $a = new http\
Header("Accept", "text/html, text/plain;q=0.5, */*;q=0");
38 $this->assertEquals("text/html", $a->negotiate(array("text/plain","text/html")));
39 $this->assertEquals("text/html", $a->negotiate(array("text/plain","text/html"), $rs));
40 $this->assertEquals(array("text/html"=>0.99, "text/plain"=>0.5), $rs);
41 $this->assertEquals("text/plain", $a->negotiate(array("foo/bar", "text/plain"), $rs));
42 $this->assertEquals(array("text/plain"=>0.5), $rs);
43 $this->assertEquals("foo/bar", $a->negotiate(array("foo/bar"), $rs));
44 $this->assertEquals(array(), $rs);
47 function testParse() {
48 $header = "Foo: bar\nBar: foo\n";
49 $this->assertEquals(array("Foo"=>"bar","Bar"=>"foo"), http\Header
::parse($header));
50 $header = http\Header
::parse($header, "http\\Header");
51 $this->assertCount(2, $header);
52 $this->assertContainsOnlyInstancesOf("http\\Header", $header);
55 function testParseError() {
57 $this->setExpectedException("PHPUnit_Framework_Error_Warning", "Could not parse headers");
58 $this->assertFalse(http\Header
::parse($header));