From 2fc0f1875846114e57571bee1b0fa663deb1722d Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 7 Dec 2005 22:28:22 +0000 Subject: [PATCH] - PHPUnit HttpUtil --- tests/ut_HttpUtil.phpt | 106 ++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 44 deletions(-) diff --git a/tests/ut_HttpUtil.phpt b/tests/ut_HttpUtil.phpt index 4fd2515..19df49a 100644 --- a/tests/ut_HttpUtil.phpt +++ b/tests/ut_HttpUtil.phpt @@ -10,6 +10,8 @@ skipif(!@include 'PHPUnit2/Framework/TestCase.php', 'need PHPUnit2'); assertEquals('Thu, 01 Jan 1970 00:00:01 GMT', HttpUtil::date(1)); } function test_buildUri() { + $_SERVER['SERVER_NAME'] = 'www.example.com'; + $this->assertEquals('http://www.example.com/test.php?foo=bar', HttpUtil::buildUri('/test.php?foo=bar', null, null, 80)); + $this->assertEquals('https://www.example.com/', HttpUtil::buildUri('/', 'https')); + $this->assertEquals('ftp://ftp.example.com/pub', HttpUtil::buildUri('/pub', null, 'ftp.example.com', 21)); } function test_negotiateLanguage() { + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en, de;q=0.5, it-IT; q = 0.5 '; + $this->assertEquals('de', HttpUtil::negotiateLanguage(array('de','it'), $r)); + $this->assertEquals(array('de'=>0.5,'it'=>0.45), $r); } function test_negotiateCharset() { + $_SERVER['HTTP_ACCEPT_CHARSET'] = ' iso-8859-1, Unicode ;q=0 , utf-8 '; + $this->assertEquals('iso-8859-1', HttpUtil::negotiateCharset(array('utf-8','iso-8859-1'), $r)); + $this->assertEquals(array('iso-8859-1'=>1000.0,'utf-8'=>999.0), $r); } function test_negotiateContentType() { + $_SERVER['HTTP_ACCEPT'] = ' text/xml+xhtml, text/html;q = .9, *'; + $this->assertEquals('text/xml+xhtml', HttpUtil::negotiateContentType(array('text/xml+xhtml', 'text/html'), $r)); + $this->assertEquals(array('text/xml+xhtml'=>1000.0,'text/html'=>0.9), $r); } function test_matchModified() { + $_SERVER['HTTP_IF_MODIFIED_SINCE'] = 'Fri, 02 Jan 1970 00:00:01 GMT'; + $this->assertTrue(HttpUtil::matchModified(1)); + $this->assertFalse(HttpUtil::matchModified(2*24*60*60+1)); + unset($_SERVER['HTTP_IF_MODIFIED_SINCE']); + + $_SERVER['HTTP_IF_UNMODIFIED_SINCE'] = 'Fri, 02 Jan 1970 00:00:01 GMT'; + $this->assertTrue(HttpUtil::matchModified(1, true)); + $this->assertFalse(HttpUtil::matchModified(2*24*60*60+1, true)); + unset($_SERVER['HTTP_IF_UNMODIFIED_SINCE']); } function test_matchEtag() { + $_SERVER['HTTP_IF_NONE_MATCH'] = '"abc"'; + $this->assertTrue(HttpUtil::matchEtag('abc')); + $this->assertFalse(HttpUtil::matchEtag('ABC')); + unset($_SERVER['HTTP_IF_NONE_MATCH']); + + $_SERVER['HTTP_IF_MATCH'] = '"abc"'; + $this->assertTrue(HttpUtil::matchEtag('abc', true)); + $this->assertFalse(HttpUtil::matchEtag('ABC', true)); + unset($_SERVER['HTTP_IF_MATCH']); + + $_SERVER['HTTP_IF_NONE_MATCH'] = '*'; + $this->assertTrue(HttpUtil::matchEtag('abc')); + $this->assertTrue(HttpUtil::matchEtag('ABC')); + unset($_SERVER['HTTP_IF_NONE_MATCH']); + + $_SERVER['HTTP_IF_MATCH'] = '*'; + $this->assertTrue(HttpUtil::matchEtag('abc', true)); + $this->assertTrue(HttpUtil::matchEtag('ABC', true)); + unset($_SERVER['HTTP_IF_MATCH']); } function test_matchRequestHeader() { - } - - function test_parseMessage() - { - } - - function test_parseHeaders() - { - } - - function test_chunkedDecode() - { - } - - function test_gzEncode() - { - } - - function test_gzDecode() - { - } - - function test_deflate() - { - } - - function test_inflate() - { - } - - function test_compress() - { - } - - function test_uncompress() - { - } - - function test_support() - { - } - - + $_SERVER['HTTP_FOO'] = 'FoObAr'; + $this->assertTrue(HttpUtil::matchRequestHeader('foo', 'foobar', false)); + $this->assertTrue(HttpUtil::matchRequestHeader('foo', 'FoObAr', true)); + $this->assertFalse(HttpUtil::matchRequestHeader('foo', 'foobar', true)); + } + + function test_zlib() + { + if ($support = http_support(HTTP_SUPPORT_ENCODINGS)) { + $this->assertEquals(file_get_contents(__FILE__), http_gzdecode(http_gzencode(file_get_contents(__FILE__)))); + $this->assertEquals(file_get_contents(__FILE__), http_inflate(http_deflate(file_get_contents(__FILE__)))); + $this->assertEquals(file_get_contents(__FILE__), http_uncompress(http_compress(file_get_contents(__FILE__)))); + } else { + $this->assertFalse($support); + } + } } $s = new PHPUnit2_Framework_TestSuite('HttpUtilTest'); @@ -100,7 +117,8 @@ echo "Done\n"; --EXPECTF-- %sTEST + Time: 0 -OK (18 tests) +OK (9 tests) Done -- 2.30.2