From 2de967f07dd086f965959af72b33ca2a18030563 Mon Sep 17 00:00:00 2001 From: tof <> Date: Mon, 18 Jun 2007 13:12:30 +0000 Subject: Partial implementation of unit tests for THttpResponseTest --- tests/unit/Web/THttpResponseTest.php | 88 ++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/unit/Web/THttpResponseTest.php b/tests/unit/Web/THttpResponseTest.php index 54d25830..6cc453e4 100644 --- a/tests/unit/Web/THttpResponseTest.php +++ b/tests/unit/Web/THttpResponseTest.php @@ -1,51 +1,119 @@ init (null); + self::assertEquals ($response, self::$app->getResponse()); } public function testSetCacheExpire() { - throw new PHPUnit_Framework_IncompleteTestError(); + $response=new THttpResponse (); + $response->init (null); + $response->setCacheExpire (300); + self::assertEquals(300, $response->getCacheExpire()); } public function testSetCacheControl() { - throw new PHPUnit_Framework_IncompleteTestError(); + $response=new THttpResponse (); + $response->init (null); + foreach (array ('none','nocache','private','private_no_expire','public') as $cc) { + $response->setCacheControl($cc); + self::assertEquals($cc, $response->getCacheControl()); + } + try { + $response->setCacheControl('invalid'); + self::fail ('Expected TInvalidDataValueException not thrown'); + } catch (TInvalidDataValueException $e) {} + } public function testSetContentType() { - throw new PHPUnit_Framework_IncompleteTestError(); + $response=new THttpResponse (); + $response->init (null); + $response->setContentType('image/jpeg'); + self::assertEquals('image/jpeg', $response->getContentType()); + $response->setContentType('text/plain'); + self::assertEquals('text/plain', $response->getContentType()); } public function testSetCharset() { - throw new PHPUnit_Framework_IncompleteTestError(); + $response=new THttpResponse (); + $response->init (null); + $response->setCharset ('UTF-8'); + self::assertEquals('UTF-8', $response->getCharset()); + $response->setCharset ('ISO8859-1'); + self::assertEquals('ISO8859-1', $response->getCharset()); + } public function testSetBufferOutput() { - throw new PHPUnit_Framework_IncompleteTestError(); + $response=new THttpResponse (); + $response->setBufferOutput(true); + self::assertTrue($response->getBufferOutput()); + $response->init (null); + try { + $response->setBufferOutput(false); + self::fail ('Expected TInvalidOperationException not thrown'); + } catch (TInvalidOperationException $e) {} } public function testSetStatusCode() { - throw new PHPUnit_Framework_IncompleteTestError(); + $response=new THttpResponse (); + $response->init (null); + $response->setStatusCode(401); + self::assertEquals(401, $response->getStatusCode()); + $response->setStatusCode(200); + self::assertEquals(200, $response->getStatusCode()); } public function testGetCookies() { - throw new PHPUnit_Framework_IncompleteTestError(); + $response=new THttpResponse (); + $response->init (null); + self::assertType('THttpCookieCollection', $response->getCookies()); + self::assertEquals(0, $response->getCookies()->getCount()); } public function testWrite() { - throw new PHPUnit_Framework_IncompleteTestError(); + $response=new THttpResponse (); + //self::expectOutputString("test string"); + $response->write("test string"); + self::assertContains ('test string', ob_get_clean()); + } public function testWriteFile() { - throw new PHPUnit_Framework_IncompleteTestError(); + + // Don't know how to test headers :(( ... + throw new PHPUnit_Framework_IncompleteTestError(); + + $response=new THttpResponse (); + $response->setBufferOutput(true); + // Suppress warning with headers + $response->writeFile(dirname(__FILE__).'/data/aTarFile.md5', null, 'text/plain', array ('Pragma: public', 'Expires: 0')); + + self::assertContains('4b1ecb0b243918a8bbfbb4515937be98 aTarFile.tar', ob_get_clean()); + } public function testRedirect() { -- cgit v1.2.3