- add unit test (templates)
authorMichael Wallner <mike@php.net>
Wed, 7 Dec 2005 16:44:00 +0000 (16:44 +0000)
committerMichael Wallner <mike@php.net>
Wed, 7 Dec 2005 16:44:00 +0000 (16:44 +0000)
tests/ut_HttpMessage.phpt [new file with mode: 0644]
tests/ut_HttpRequest.phpt [new file with mode: 0644]
tests/ut_HttpRequestPool.phpt [new file with mode: 0644]
tests/ut_HttpResponse.phpt [new file with mode: 0644]
tests/ut_HttpUtil.phpt [new file with mode: 0644]

diff --git a/tests/ut_HttpMessage.phpt b/tests/ut_HttpMessage.phpt
new file mode 100644 (file)
index 0000000..eb693ef
--- /dev/null
@@ -0,0 +1,268 @@
+--TEST--
+PHPUnit HttpMessage
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkcls('HttpMessage');
+skipif(!@include 'PHPUnit2/Framework/TestCase.php', 'need PHPUnit2');
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+error_reporting(E_ALL);
+
+require_once 'PHPUnit2/Framework/TestSuite.php';
+require_once 'PHPUnit2/Framework/TestCase.php';
+require_once 'PHPUnit2/TextUI/ResultPrinter.php';
+
+class HttpMessageTest extends PHPUnit2_Framework_TestCase
+{
+    function setUp()
+    {
+        $this->emptyMessage = new HttpMessage;
+        $this->responseMessage = new HttpMessage("HTTP/1.1 302 Found\r\nLocation: /foo\r\nHTTP/1.1 200 Ok\r\nServer: Funky/1.0\r\n\r\nHi there!");
+        $this->requestMessage = new HttpMessage("GET /foo HTTP/1.1\r\nHost: example.com\r\nContent-type: text/plain\r\nContent-length: 10\r\n\r\nHi there!\n");
+    }
+    
+    function test___construct()
+    {
+       $this->assertTrue(new HttpMessage instanceof HttpMessage, "new HttpMessage instanceof HttpMessage");
+    }
+
+    function test_getBody()
+    {
+        $this->assertEquals('', $this->emptyMessage->getBody());
+        $this->assertEquals('Hi there!', $this->responseMessage->getBody());
+        $this->assertEquals("Hi there!\n", $this->requestMessage->getBody());
+    }
+
+    function test_setBody()
+    {
+        $this->emptyMessage->setBody('New Body 1');
+        $this->responseMessage->setBody('New Body 2');
+        $this->requestMessage->setBody('New Body 3');
+        $this->assertEquals('New Body 2', $this->responseMessage->getBody());
+        $this->assertEquals('New Body 1', $this->emptyMessage->getBody());
+        $this->assertEquals('New Body 3', $this->requestMessage->getBody());
+    }
+
+    function test_getHeaders()
+    {
+        $this->assertEquals(array(), $this->emptyMessage->getHeaders());
+        $this->assertEquals(array('Server' => 'Funky/1.0'), $this->responseMessage->getHeaders());
+        $this->assertEquals(array('Host' => 'example.com', 'Content-Type' => 'text/plain', 'Content-Length' => '10'), $this->requestMessage->getHeaders());
+    }
+
+    function test_setHeaders()
+    {
+        $this->emptyMessage->setHeaders(array('Foo' => 'Bar'));
+        $this->responseMessage->setHeaders(array());
+        $this->requestMessage->setHeaders(array('Host' => 'www.example.com'));
+        $this->assertEquals(array('Foo' => 'Bar'), $this->emptyMessage->getHeaders());
+        $this->assertEquals(array(), $this->responseMessage->getHeaders());
+        $this->assertEquals(array('Host' => 'www.example.com'), $this->requestMessage->getHeaders());
+    }
+
+    function test_addHeaders()
+    {
+        $this->emptyMessage->addHeaders(array('Foo' => 'Bar'));
+        $this->responseMessage->addHeaders(array('Date' => 'today'));
+        $this->requestMessage->addHeaders(array('Host' => 'www.example.com'));
+        $this->assertEquals(array('Foo' => 'Bar'), $this->emptyMessage->getHeaders());
+        $this->assertEquals(array('Server' => 'Funky/1.0', 'Date' => 'today'), $this->responseMessage->getHeaders());
+        $this->assertEquals(array('Host' => 'www.example.com', 'Content-Type' => 'text/plain', 'Content-Length' => '10'), $this->requestMessage->getHeaders());
+        $this->emptyMessage->addHeaders(array('Foo' => 'Baz'), true);
+        $this->assertEquals(array('Foo' => array('Bar', 'Baz')), $this->emptyMessage->getHeaders());
+    }
+
+    function test_getType()
+    {
+        $this->assertEquals(HTTP_MSG_NONE, $this->emptyMessage->getType());
+        $this->assertEquals(HTTP_MSG_RESPONSE, $this->responseMessage->getType());
+        $this->assertEquals(HTTP_MSG_REQUEST, $this->requestMessage->getType());
+    }
+
+    function test_setType()
+    {
+        $this->emptyMessage->setType(HTTP_MSG_RESPONSE);
+        $this->responseMessage->setType(HTTP_MSG_REQUEST);
+        $this->requestMessage->setType(HTTP_MSG_NONE);
+        $this->assertEquals(HTTP_MSG_RESPONSE, $this->emptyMessage->getType());
+        $this->assertEquals(HTTP_MSG_REQUEST, $this->responseMessage->getType());
+        $this->assertEquals(HTTP_MSG_NONE, $this->requestMessage->getType());
+    }
+
+    function test_getResponseCode()
+    {
+        $this->assertFalse($this->emptyMessage->getResponseCode());
+        $this->assertEquals(200, $this->responseMessage->getResponseCode());
+        $this->assertFalse($this->requestMessage->getResponseCode());
+    }
+
+    function test_setResponseCode()
+    {
+        $this->assertFalse($this->emptyMessage->setResponseCode(301));
+        $this->assertTrue($this->responseMessage->setResponseCode(301));
+        $this->assertFalse($this->requestMessage->setResponseCode(301));
+        $this->assertFalse($this->emptyMessage->getResponseCode());
+        $this->assertEquals(301, $this->responseMessage->getResponseCode());
+        $this->assertFalse($this->requestMessage->getResponseCode());
+    }
+
+    function test_getRequestMethod()
+    {
+        $this->assertFalse($this->emptyMessage->getRequestMethod());
+        $this->assertFalse($this->responseMessage->getRequestMethod());
+        $this->assertEquals('GET', $this->requestMessage->getRequestMethod());
+    }
+
+    function test_setRequestMethod()
+    {
+        $this->assertFalse($this->emptyMessage->setRequestMethod('POST'));
+        $this->assertFalse($this->responseMessage->setRequestMethod('POST'));
+        $this->assertTrue($this->requestMessage->setRequestMethod('POST'));
+        $this->assertFalse($this->emptyMessage->getRequestMethod());
+        $this->assertFalse($this->responseMessage->getRequestMethod());
+        $this->assertEquals('POST', $this->requestMessage->getRequestMethod());
+    }
+
+    function test_getRequestUri()
+    {
+        $this->assertFalse($this->emptyMessage->getRequestUri());
+        $this->assertFalse($this->responseMessage->getRequestUri());
+        $this->assertEquals('/foo', $this->requestMessage->getRequestUri());
+    }
+
+    function test_setRequestUri()
+    {
+        $this->assertFalse($this->emptyMessage->setRequestUri('/bla'));
+        $this->assertFalse($this->responseMessage->setRequestUri('/bla'));
+        $this->assertTrue($this->requestMessage->setRequestUri('/bla'));
+        $this->assertFalse($this->emptyMessage->getRequestUri());
+        $this->assertFalse($this->responseMessage->getRequestUri());
+        $this->assertEquals('/bla', $this->requestMessage->getRequestUri());
+    }
+
+    function test_getHttpVersion()
+    {
+        $this->assertEquals('0.0', $this->emptyMessage->getHttpVersion());
+        $this->assertEquals('1.1', $this->responseMessage->getHttpVersion());
+        $this->assertEquals('1.1', $this->requestMessage->getHttpVersion());
+    }
+
+    function test_setHttpVersion()
+    {
+        $this->assertTrue($this->emptyMessage->setHttpVersion(1.0));
+        $this->assertTrue($this->responseMessage->setHttpVersion(1.0));
+        $this->assertTrue($this->requestMessage->setHttpVersion(1.0));
+        $this->assertEquals('1.0', $this->emptyMessage->getHttpVersion());
+        $this->assertEquals('1.0', $this->responseMessage->getHttpVersion());
+        $this->assertEquals('1.0', $this->requestMessage->getHttpVersion());
+    }
+
+    function test_getParentMessage()
+    {
+        $this->assertNull($this->emptyMessage->getParentMessage());
+        $this->assertTrue($this->responseMessage->getParentMessage() instanceOf HttpMessage);
+        $this->assertNull($this->requestMessage->getParentMessage());
+    }
+
+    function test_send()
+    {
+    }
+
+    function test_toString()
+    {
+        $this->assertEquals('', $this->emptyMessage->toString());
+        $this->assertEquals("HTTP/1.1 200 Ok\r\nServer: Funky/1.0\r\n\r\nHi there!\r\n", $this->responseMessage->toString());
+        $this->assertEquals("GET /foo HTTP/1.1\r\nHost: example.com\r\nContent-Type: text/plain\r\nContent-Length: 10\r\n\r\nHi there!\n\r\n", $this->requestMessage->toString());
+    }
+
+    function test_count()
+    {
+        if (5.1 <= (float)PHP_VERSION) {
+            $this->assertEquals(1, count($this->emptyMessage));
+            $this->assertEquals(2, count($this->responseMessage));
+            $this->assertEquals(1, count($this->requestMessage));
+        } else {
+            $this->assertEquals(1, $this->emptyMessage->count());
+            $this->assertEquals(2, $this->responseMessage->count());
+            $this->assertEquals(1, $this->requestMessage->count());
+        }
+    }
+
+    function test_serialize()
+    {
+    }
+
+    function test_unserialize()
+    {
+    }
+
+    function test___toString()
+    {
+        ob_start();
+        echo $this->responseMessage;
+        $this->assertEquals("HTTP/1.1 200 Ok\r\nServer: Funky/1.0\r\n\r\nHi there!\r\n", ob_get_clean());
+    }
+
+    function test_fromString()
+    {
+        $msg = HttpMessage::fromString("HTTP/1.1 200 Ok\r\nServer: Funky/1.0\r\n\r\nHi there!");
+        $this->assertTrue($msg instanceOf HttpMessage);
+        $this->assertEquals(HTTP_MSG_RESPONSE, $msg->getType());
+        $this->assertEquals("Hi there!", $msg->getBody());
+    }
+}
+
+$s = new PHPUnit2_Framework_TestSuite('HttpMessageTest');
+$p = new PHPUnit2_TextUI_ResultPrinter();
+$p->printResult($s->run(), 0);
+
+echo "Done\n";
+?>
+--EXPECTF--
+%sTEST
+
+Notice: HttpMessage::getResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::getResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::setResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::setResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::getResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::getResponseCode(): HttpMessage is not of type HTTP_MSG_RESPONSE in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::getRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::getRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::setRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::setRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::getRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::getRequestMethod(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::getRequestUri(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::getRequestUri(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::setRequestUri(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::setRequestUri(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::getRequestUri(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+Notice: HttpMessage::getRequestUri(): HttpMessage is not of type HTTP_MSG_REQUEST in %sut_HttpMessage.php on line %d
+
+
+Time: 0
+
+OK (24 tests)
+Done
diff --git a/tests/ut_HttpRequest.phpt b/tests/ut_HttpRequest.phpt
new file mode 100644 (file)
index 0000000..ab3691d
--- /dev/null
@@ -0,0 +1,246 @@
+--TEST--
+PHPUnit HttpRequest
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkcls('HttpRequest');
+skipif(!@include 'PHPUnit2/Framework/TestCase.php', 'need PHPUnit2');
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+require_once 'PHPUnit2/Framework/TestSuite.php';
+require_once 'PHPUnit2/Framework/TestCase.php';
+require_once 'PHPUnit2/TextUI/ResultPrinter.php';
+
+class HttpRequestTest extends PHPUnit2_Framework_TestCase
+{
+    function test___construct()
+    {
+    }
+
+    function test___destruct()
+    {
+    }
+
+    function test_setOptions()
+    {
+    }
+
+    function test_getOptions()
+    {
+    }
+
+    function test_setSslOptions()
+    {
+    }
+
+    function test_getSslOptions()
+    {
+    }
+
+    function test_addHeaders()
+    {
+    }
+
+    function test_getHeaders()
+    {
+    }
+
+    function test_setHeaders()
+    {
+    }
+
+    function test_addCookies()
+    {
+    }
+
+    function test_getCookies()
+    {
+    }
+
+    function test_setCookies()
+    {
+    }
+
+    function test_setMethod()
+    {
+    }
+
+    function test_getMethod()
+    {
+    }
+
+    function test_setUrl()
+    {
+    }
+
+    function test_getUrl()
+    {
+    }
+
+    function test_setContentType()
+    {
+    }
+
+    function test_getContentType()
+    {
+    }
+
+    function test_setQueryData()
+    {
+    }
+
+    function test_getQueryData()
+    {
+    }
+
+    function test_addQueryData()
+    {
+    }
+
+    function test_setPostFields()
+    {
+    }
+
+    function test_getPostFields()
+    {
+    }
+
+    function test_addPostFields()
+    {
+    }
+
+    function test_setRawPostData()
+    {
+    }
+
+    function test_getRawPostData()
+    {
+    }
+
+    function test_addRawPostData()
+    {
+    }
+
+    function test_setPostFiles()
+    {
+    }
+
+    function test_addPostFile()
+    {
+    }
+
+    function test_getPostFiles()
+    {
+    }
+
+    function test_setPutFile()
+    {
+    }
+
+    function test_getPutFile()
+    {
+    }
+
+    function test_send()
+    {
+    }
+
+    function test_getResponseData()
+    {
+    }
+
+    function test_getResponseHeader()
+    {
+    }
+
+    function test_getResponseCookie()
+    {
+    }
+
+    function test_getResponseCode()
+    {
+    }
+
+    function test_getResponseBody()
+    {
+    }
+
+    function test_getResponseInfo()
+    {
+    }
+
+    function test_getResponseMessage()
+    {
+    }
+
+    function test_getRequestMessage()
+    {
+    }
+
+    function test_getHistory()
+    {
+    }
+
+    function test_clearHistory()
+    {
+    }
+
+    function test_get()
+    {
+    }
+
+    function test_head()
+    {
+    }
+
+    function test_postData()
+    {
+    }
+
+    function test_postFields()
+    {
+    }
+
+    function test_putFile()
+    {
+    }
+
+    function test_putStream()
+    {
+    }
+
+    function test_methodRegister()
+    {
+    }
+
+    function test_methodUnregister()
+    {
+    }
+
+    function test_methodName()
+    {
+    }
+
+    function test_methodExists()
+    {
+    }
+
+
+}
+
+$s = new PHPUnit2_Framework_TestSuite('HttpRequestTest');
+$p = new PHPUnit2_TextUI_ResultPrinter();
+$p->printResult($s->run(), 0);
+
+echo "Done\n";
+?>
+--EXPECTF--
+%sTEST
+
+Time: 0
+
+OK (53 tests)
+Done
diff --git a/tests/ut_HttpRequestPool.phpt b/tests/ut_HttpRequestPool.phpt
new file mode 100644 (file)
index 0000000..774fa6f
--- /dev/null
@@ -0,0 +1,98 @@
+--TEST--
+PHPUnit HttpRequestPool
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkcls('HttpRequestPool');
+skipif(!@include 'PHPUnit2/Framework/TestCase.php', 'need PHPUnit2');
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+require_once 'PHPUnit2/Framework/TestSuite.php';
+require_once 'PHPUnit2/Framework/TestCase.php';
+require_once 'PHPUnit2/TextUI/ResultPrinter.php';
+
+class HttpRequestPoolTest extends PHPUnit2_Framework_TestCase
+{
+    function test___construct()
+    {
+    }
+
+    function test___destruct()
+    {
+    }
+
+    function test_attach()
+    {
+    }
+
+    function test_detach()
+    {
+    }
+
+    function test_send()
+    {
+    }
+
+    function test_reset()
+    {
+    }
+
+    function test_socketPerform()
+    {
+    }
+
+    function test_socketSelect()
+    {
+    }
+
+    function test_valid()
+    {
+    }
+
+    function test_current()
+    {
+    }
+
+    function test_key()
+    {
+    }
+
+    function test_next()
+    {
+    }
+
+    function test_rewind()
+    {
+    }
+
+    function test_count()
+    {
+    }
+
+    function test_getAttachedRequests()
+    {
+    }
+
+    function test_getFinishedRequests()
+    {
+    }
+
+
+}
+
+$s = new PHPUnit2_Framework_TestSuite('HttpRequestPoolTest');
+$p = new PHPUnit2_TextUI_ResultPrinter();
+$p->printResult($s->run(), 0);
+
+echo "Done\n";
+?>
+--EXPECTF--
+%sTEST
+
+Time: 0
+
+OK (16 tests)
+Done
diff --git a/tests/ut_HttpResponse.phpt b/tests/ut_HttpResponse.phpt
new file mode 100644 (file)
index 0000000..91b09fd
--- /dev/null
@@ -0,0 +1,166 @@
+--TEST--
+PHPUnit HttpResponse
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkcls('HttpResponse');
+skipif(!@include 'PHPUnit2/Framework/TestCase.php', 'need PHPUnit2');
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+require_once 'PHPUnit2/Framework/TestSuite.php';
+require_once 'PHPUnit2/Framework/TestCase.php';
+require_once 'PHPUnit2/TextUI/ResultPrinter.php';
+
+class HttpResponseTest extends PHPUnit2_Framework_TestCase
+{
+    function test_setHeader()
+    {
+    }
+
+    function test_getHeader()
+    {
+    }
+
+    function test_setETag()
+    {
+    }
+
+    function test_getETag()
+    {
+    }
+
+    function test_setLastModified()
+    {
+    }
+
+    function test_getLastModified()
+    {
+    }
+
+    function test_setContentDisposition()
+    {
+    }
+
+    function test_getContentDisposition()
+    {
+    }
+
+    function test_setContentType()
+    {
+    }
+
+    function test_getContentType()
+    {
+    }
+
+    function test_guessContentType()
+    {
+    }
+
+    function test_setCache()
+    {
+    }
+
+    function test_getCache()
+    {
+    }
+
+    function test_setCacheControl()
+    {
+    }
+
+    function test_getCacheControl()
+    {
+    }
+
+    function test_setGzip()
+    {
+    }
+
+    function test_getGzip()
+    {
+    }
+
+    function test_setThrottleDelay()
+    {
+    }
+
+    function test_getThrottleDelay()
+    {
+    }
+
+    function test_setBufferSize()
+    {
+    }
+
+    function test_getBufferSize()
+    {
+    }
+
+    function test_setData()
+    {
+    }
+
+    function test_getData()
+    {
+    }
+
+    function test_setFile()
+    {
+    }
+
+    function test_getFile()
+    {
+    }
+
+    function test_setStream()
+    {
+    }
+
+    function test_getStream()
+    {
+    }
+
+    function test_send()
+    {
+    }
+
+    function test_capture()
+    {
+    }
+
+    function test_redirect()
+    {
+    }
+
+    function test_status()
+    {
+    }
+
+    function test_getRequestHeaders()
+    {
+    }
+
+    function test_getRequestBody()
+    {
+    }
+
+
+}
+
+$s = new PHPUnit2_Framework_TestSuite('HttpResponseTest');
+$p = new PHPUnit2_TextUI_ResultPrinter();
+$p->printResult($s->run(), 0);
+
+echo "Done\n";
+?>
+--EXPECTF--
+%sTEST
+
+Time: 0
+
+OK (33 tests)
+Done
diff --git a/tests/ut_HttpUtil.phpt b/tests/ut_HttpUtil.phpt
new file mode 100644 (file)
index 0000000..4fd2515
--- /dev/null
@@ -0,0 +1,106 @@
+--TEST--
+PHPUnit HttpUtil
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkcls('HttpUtil');
+skipif(!@include 'PHPUnit2/Framework/TestCase.php', 'need PHPUnit2');
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+require_once 'PHPUnit2/Framework/TestSuite.php';
+require_once 'PHPUnit2/Framework/TestCase.php';
+require_once 'PHPUnit2/TextUI/ResultPrinter.php';
+
+class HttpUtilTest extends PHPUnit2_Framework_TestCase
+{
+    function test_date()
+    {
+    }
+
+    function test_buildUri()
+    {
+    }
+
+    function test_negotiateLanguage()
+    {
+    }
+
+    function test_negotiateCharset()
+    {
+    }
+
+    function test_negotiateContentType()
+    {
+    }
+
+    function test_matchModified()
+    {
+    }
+
+    function test_matchEtag()
+    {
+    }
+
+    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()
+    {
+    }
+
+
+}
+
+$s = new PHPUnit2_Framework_TestSuite('HttpUtilTest');
+$p = new PHPUnit2_TextUI_ResultPrinter();
+$p->printResult($s->run(), 0);
+
+echo "Done\n";
+?>
+--EXPECTF--
+%sTEST
+
+Time: 0
+
+OK (18 tests)
+Done