[moriarty] r323 committed - HttpResponse was causing error with HEAD requests, because the check f...

0 views
Skip to first unread message

mori...@googlecode.com

unread,
Sep 23, 2011, 9:46:02 AM9/23/11
to moriarty...@googlegroups.com
Revision: 323
Author: jhi...@gmail.com
Date: Fri Sep 23 06:45:02 2011
Log: HttpResponse was causing error with HEAD requests, because the
check for compressed body content assumes first 2 chars are present (and
failure was dependent on current error reporting levels). Added unit test
for HttpResponse. Also removed spurious whitespace from end of
store.class.php which appears in rendered responses.
http://code.google.com/p/moriarty/source/detail?r=323

Modified:
/trunk/httpresponse.class.php
/trunk/store.class.php
/trunk/tests/httpresponse.test.php
/trunk/tests/runtests.php

=======================================
--- /trunk/httpresponse.class.php Fri Sep 9 16:09:37 2011
+++ /trunk/httpresponse.class.php Fri Sep 23 06:45:02 2011
@@ -55,13 +55,14 @@
public function __get($k){
return $this->$k;
}
+
public function __set($k, $v){
if($k=='body' AND $this->content_is_gzip_encoded()){
- //strip the gzip header
- if(ord($v[0]) == 0x1f && ord($v[1]) == 0x8b)
- {
- $v = substr($v,10);
- $v = gzinflate($v);
+ //strip the gzip header, explicitly suppressing errors
+ if(ord(@$v[0]) == 0x1f && ord(@$v[1]) == 0x8b)
+ {
+ $v = substr($v,10);
+ $v = gzinflate($v);
}
}
$this->$k=$v;
=======================================
--- /trunk/store.class.php Tue Aug 9 01:22:12 2011
+++ /trunk/store.class.php Fri Sep 23 06:45:02 2011
@@ -298,4 +298,3 @@

}
?>
-
=======================================
--- /trunk/tests/httpresponse.test.php Fri Jul 29 08:34:10 2011
+++ /trunk/tests/httpresponse.test.php Fri Sep 23 06:45:02 2011
@@ -6,15 +6,31 @@

class HttpResponseTest extends PHPUnit_Framework_TestCase {

-
- function test_get_content_type(){
-
- $response = new HttpResponse('200');
- $response->headers = array('content-type'=> 'text/html');
- $this->assertEquals('text/html',
$response->get_content_type(), 'Content type should be text/html');
- $response->headers = array('Content-Type'=> 'text/xml');
- $this->assertEquals('text/xml',
$response->get_content_type(), 'Content type should be text/xml');
-
+ private $old_error_reporting = 0;
+
+ // switch off error suppression while we test test_set_body_empty
+ // because the error reporting in an end-user environment can't be
guaranteed
+ // after the tests, restore the error reporting
+
+ function setUp() {
+ $this->old_error_reporting = error_reporting();
+ error_reporting(E_ALL);
+ }
+
+ function tearDown() {
+ error_reporting($this->old_error_reporting);
+ }
+
+ function test_set_body_with_empty_string(){
+
+ $response = new HttpResponse(200);
+
+ $headers = array();
+ $headers['content-encoding'] = 'gzip';
+ $response->headers = $headers;
+ $response->body = "";
+
+ $this->assertTrue($response->is_success(), 'Should have handled empty
body without causing error');
}
}
?>
=======================================
--- /trunk/tests/runtests.php Tue Aug 2 01:13:40 2011
+++ /trunk/tests/runtests.php Fri Sep 23 06:45:02 2011
@@ -17,6 +17,7 @@
require_once MORIARTY_TEST_DIR . 'fieldpredicatemap.test.php';
require_once MORIARTY_TEST_DIR . 'valuepool.test.php';
require_once MORIARTY_TEST_DIR . 'httprequest.test.php';
+require_once MORIARTY_TEST_DIR . 'httpresponse.test.php';
require_once MORIARTY_TEST_DIR . 'credentials.test.php';
require_once MORIARTY_TEST_DIR . 'privategraph.test.php';
require_once MORIARTY_TEST_DIR . 'contentbox.test.php';
@@ -42,6 +43,7 @@
require_once MORIARTY_TEST_DIR . 'datatableresult.test.php';

error_reporting(E_ALL && ~E_STRICT);
+
function exceptions_error_handler($severity, $message, $filename, $lineno)
{
if (error_reporting() == 0) {
return;
@@ -81,6 +83,7 @@
$suite->addTestSuite('CredentialsTest');
$suite->addTestSuite('ValuePoolTest');
$suite->addTestSuite('HttpRequestTest');
+ $suite->addTestSuite('HttpResponseTest');
$suite->addTestSuite('PrivateGraphTest');
$suite->addTestSuite('MetaboxTest');
$suite->addTestSuite('ContentboxTest');

Reply all
Reply to author
Forward
0 new messages