Permalink
Browse files

Fix tests to make sure they pass

  • Loading branch information...
1 parent 1646166 commit d5930e28fe59a5118cd2aab8b8fe3737590b27d2 @baileylo baileylo committed May 1, 2012
Showing with 16 additions and 23 deletions.
  1. +2 −0 phpunit.xml
  2. +5 −10 tests/HTTP_Header2Test.php
  3. +5 −9 tests/HTTP_Header2_CacheTest.php
  4. +2 −2 tests/README.txt
  5. +1 −1 tests/cacheresponse.php
  6. +1 −1 tests/response.php
View
@@ -19,5 +19,7 @@
</testsuites>
<php>
<includePath>lib/HTTP2</includePath>
+ <const name="TEST_URL" value="http://local/www/mike/pear/HTTP_Header2/tests/response.php'"/>
+ <const name="CACHE_TEST_URL" value="http://local/www/mike/pear/HTTP_Header2/tests/cacheresponse.php"/>
</php>
</phpunit>
@@ -4,18 +4,13 @@
*
* $Id$
*/
-
require_once 'PHPUnit/Framework/TestCase.php';
require_once 'HTTP/Header2.php';
require_once 'HTTP/Request2.php';
+require_once 'Net/URL2.php';
class HTTP_Header2Test extends PHPUnit_Framework_TestCase
{
- function setUp()
- {
- $this->testScript = 'http://local/www/mike/pear/HTTP_Header2/tests/response.php';
- }
-
function testHTTP_Header2()
{
$h = new HTTP_Header2;
@@ -78,7 +73,7 @@ function testgetHeader()
function testsendHeaders()
{
- $url = new Net_URL2($this->testScript);
+ $url = new Net_URL2(TEST_URL);
$url->setQueryVariable('X-Foo', 'blablubb');
$r = new HTTP_Request2($url);
@@ -90,7 +85,7 @@ function testsendHeaders()
function testsendStatusCode()
{
- $url = new Net_URL2($this->testScript);
+ $url = new Net_URL2(TEST_URL);
$r = new HTTP_Request2($url);
$r->setMethod(HTTP_Request2::METHOD_GET);
@@ -113,15 +108,15 @@ function testdateToTimestamp()
function testredirect()
{
- $url = new Net_URL2($this->testScript);
+ $url = new Net_URL2(TEST_URL);
$url->setQueryVariable('redirect', 'response.php?abc=123');
$r = new HTTP_Request2($url);
$r->setConfig('follow_redirects', false);
$r->setMethod(HTTP_Request2::METHOD_GET);
$response = $r->send();
$this->assertEquals(302, $response->getStatus(), 'test for response code 302');
- $this->assertTrue(strstr($response->getHeader('location'), 'response.php'));
+ $this->assertContains('response.php', $response->getHeader('location'));
unset($h, $r);
}
@@ -11,10 +11,6 @@
class HTTP_Header2_CacheTest extends PHPUnit_Framework_TestCase
{
- function setUp()
- {
- $this->testScript = 'http://local/www/mike/pear/HTTP_Header2/tests/cacheresponse.php';
- }
function testgetCacheStart()
{
@@ -50,20 +46,20 @@ function testexitIfCached()
{
$http = new HTTP2();
- $r = new HTTP_Request2($this->testScript);
+ $r = new HTTP_Request2(CACHE_TEST_URL);
$r->setMethod(HTTP_Request2::METHOD_GET);
$r->setHeader('If-Modified-Since', $http->date());
$response = $r->send();
$this->assertEquals(304, $response->getStatus(), 'HTTP 304 Not Modified');
$r->setHeader('If-Modified-Since', $http->date(strtotime('yesterday')));
- $r->send();
+ $response = $r->send();
$this->assertEquals(200, $response->getStatus(), 'HTTP 200 Ok');
unset($r);
}
function testget()
{
- $r = new HTTP_Request2($this->testScript);
+ $r = new HTTP_Request2(CACHE_TEST_URL);
$r->setMethod(HTTP_Request2::METHOD_GET);
$response = $r->send();
$this->assertEquals(200, $response->getStatus(), 'HTTP 200 Ok (simple plain GET)');
@@ -76,7 +72,7 @@ function testget()
function testhead()
{
- $r = new HTTP_Request2($this->testScript);
+ $r = new HTTP_Request2(CACHE_TEST_URL);
$r->setMethod(HTTP_Request2::METHOD_HEAD);
$response = $r->send();
$this->assertEquals(200, $response->getStatus(), 'HTTP 200 Ok (simple plain GET)');
@@ -91,7 +87,7 @@ function testpost()
{
$http = new HTTP2();
- $r = new HTTP_Request2($this->testScript);
+ $r = new HTTP_Request2(CACHE_TEST_URL);
$r->setMethod(HTTP_Request2::METHOD_GET);
$response = $r->send();
$lm = $response->getHeader('last-modified');
View
@@ -3,8 +3,8 @@ Running the TestSuite
$Id$
Copy response.php and cacheresponse.php into an
-accessible webfolder and adjust the script locations
-in the setUp() methods of header.php and header_cache.php
+accessible webfolder and TEST_URL and CACHE_TEST URL
+constants in phpunit.xml.
Now run header.php and header_cache.php with PHPUnit
and HTTP_Request installed. The caching test will
@@ -1,5 +1,5 @@
<?php
-require_once 'HTTP/Header/Cache.php';
+require_once 'HTTP/Header2/Cache.php';
$h = new HTTP_Header2_Cache(1, 'hour');
$h->sendHeaders();
echo date('r');
View
@@ -6,7 +6,7 @@
foreach ($_GET as $header => $value) {
if (!strcasecmp('redirect', $header)) {
- HTTP_Header2::redirect($value);
+ $h->redirect($value);
}
if (strcasecmp('status', $header)) {
$h->setHeader($header, $value);

0 comments on commit d5930e2

Please sign in to comment.