summaryrefslogtreecommitdiff
path: root/_test/tests/inc/httpclient_http.test.php
diff options
context:
space:
mode:
Diffstat (limited to '_test/tests/inc/httpclient_http.test.php')
-rw-r--r--_test/tests/inc/httpclient_http.test.php153
1 files changed, 116 insertions, 37 deletions
diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php
index 43dd4478f..3446e1184 100644
--- a/_test/tests/inc/httpclient_http.test.php
+++ b/_test/tests/inc/httpclient_http.test.php
@@ -1,15 +1,22 @@
<?php
+require_once (__DIR__ . '/httpclient_mock.php');
+
class httpclient_http_test extends DokuWikiTest {
protected $server = 'http://httpbin.org';
+
/**
* @group internet
*/
function test_simpleget(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$data = $http->get($this->server.'/get?foo=bar');
- $this->assertFalse($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertFalse($data === false, 'HTTP response '.$http->error);
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('args',$resp);
@@ -20,9 +27,13 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_dget(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$data = $http->dget($this->server.'/get',array('foo'=>'bar'));
- $this->assertFalse($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertFalse($data === false, 'HTTP response '.$http->error);
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('args',$resp);
@@ -33,9 +44,13 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_gzip(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$data = $http->get($this->server.'/gzip');
- $this->assertFalse($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertFalse($data === false, 'HTTP response '.$http->error);
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('gzipped',$resp);
@@ -46,9 +61,13 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_simplepost(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$data = $http->post($this->server.'/post',array('foo'=>'bar'));
- $this->assertFalse($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertFalse($data === false, 'HTTP response '.$http->error);
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('form',$resp);
@@ -59,9 +78,13 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_redirect(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$data = $http->get($this->server.'/redirect/3');
- $this->assertFalse($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertFalse($data === false, 'HTTP response '.$http->error);
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('url',$resp);
@@ -72,9 +95,13 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_relredirect(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$data = $http->get($this->server.'/relative-redirect/3');
- $this->assertFalse($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertFalse($data === false, 'HTTP response '.$http->error);
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('url',$resp);
@@ -85,9 +112,13 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_redirectfail(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$data = $http->get($this->server.'/redirect/5');
- $this->assertTrue($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertTrue($data === false, 'HTTP response '.$http->error);
$this->assertEquals('Maximum number of redirects exceeded',$http->error);
}
@@ -95,11 +126,19 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_cookies(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$http->get($this->server.'/cookies/set/foo/bar');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
$this->assertEquals(array('foo' => 'bar'), $http->cookies);
$data = $http->get($this->server.'/cookies');
- $this->assertFalse($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertFalse($data === false, 'HTTP response '.$http->error);
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('cookies',$resp);
@@ -110,9 +149,13 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_teapot(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$data = $http->get($this->server.'/status/418');
- $this->assertTrue($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertTrue($data === false, 'HTTP response '.$http->error);
$this->assertEquals(418,$http->status);
}
@@ -120,18 +163,26 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_maxbody(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$http->max_bodysize = 250;
// this should abort completely
$data = $http->get($this->server.'/stream/30');
- $this->assertTrue($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertTrue($data === false, 'HTTP response '.$http->error);
// this should read just the needed bytes
$http->max_bodysize_abort = false;
$http->keep_alive = false;
$data = $http->get($this->server.'/stream/30');
- $this->assertFalse($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertFalse($data === false, 'HTTP response '.$http->error);
/* should read no more than max_bodysize+1 */
$this->assertLessThanOrEqual(251,strlen($data));
}
@@ -140,24 +191,36 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_maxbodyok(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$http->max_bodysize = 500*1024;
$data = $http->get($this->server.'/stream/5');
- $this->assertTrue($data !== false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertTrue($data !== false, 'HTTP response '.$http->error);
$http->max_bodysize_abort = false;
$data = $http->get($this->server.'/stream/5');
- $this->assertTrue($data !== false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertTrue($data !== false, 'HTTP response '.$http->error);
}
/**
* @group internet
*/
function test_basicauth(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$http->user = 'user';
$http->pass = 'pass';
$data = $http->get($this->server.'/basic-auth/user/pass');
- $this->assertFalse($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertFalse($data === false, 'HTTP response '.$http->error);
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertEquals(array('authenticated'=>true,'user'=>'user'), $resp);
@@ -167,11 +230,15 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_basicauthfail(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$http->user = 'user';
$http->pass = 'invalid';
$data = $http->get($this->server.'/basic-auth/user/pass');
- $this->assertTrue($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertTrue($data === false, 'HTTP response '.$http->error);
$this->assertEquals(401,$http->status);
}
@@ -179,10 +246,10 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_timeout(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$http->timeout = 5;
$data = $http->get($this->server.'/delay/10');
- $this->assertTrue($data === false, 'HTTP response');
+ $this->assertTrue($data === false, 'HTTP response '.$http->error);
$this->assertEquals(-100,$http->status);
}
@@ -190,9 +257,13 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_headers(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$data = $http->get($this->server.'/response-headers?baz=&foo=bar');
- $this->assertFalse($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertFalse($data === false, 'HTTP response '.$http->error);
$resp = json_decode($data, true);
$this->assertTrue(is_array($resp), 'JSON response');
$this->assertArrayHasKey('baz',$http->resp_headers);
@@ -204,9 +275,13 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_chunked(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$data = $http->get('http://whoopdedo.org/cgi-bin/chunked/2550');
- $this->assertFalse($data === false, 'HTTP response');
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertFalse($data === false, 'HTTP response '.$http->error);
$this->assertEquals(2550,strlen($data));
}
@@ -216,13 +291,17 @@ class httpclient_http_test extends DokuWikiTest {
* @group internet
*/
function test_wikimatrix(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
$data = $http->get('http://www.wikimatrix.org/cfeed/dokuwiki/-/-');
- $this->assertTrue($data !== false, $http->error);
+ if($http->noconnection()) {
+ $this->markTestSkipped('connection timed out');
+ return;
+ }
+ $this->assertTrue($data !== false, 'HTTP response '.$http->error);
}
function test_postencode(){
- $http = new HTTPClient();
+ $http = new HTTPMockClient();
// check simple data