From fe717f57f7a1c262eb6104ccb575ee3294712afa Mon Sep 17 00:00:00 2001 From: lisps Date: Tue, 4 Feb 2014 10:59:06 +0100 Subject: fix content check test cases add test case new Input check add global variables to execute --- _test/core/TestRequest.php | 9 ++++++++- _test/tests/test/basic.test.php | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to '_test') diff --git a/_test/core/TestRequest.php b/_test/core/TestRequest.php index 0a54910ed..060e37d28 100644 --- a/_test/core/TestRequest.php +++ b/_test/core/TestRequest.php @@ -44,13 +44,18 @@ class TestRequest { * @return TestResponse the resulting output of the request */ public function execute($uri='/doku.php') { + global $INPUT; + global $ID; + global $INFO; + // save old environment $server = $_SERVER; $session = $_SESSION; $get = $_GET; $post = $_POST; $request = $_REQUEST; - + $input = $INPUT; + // prepare the right URI $this->setUri($uri); @@ -74,6 +79,7 @@ class TestRequest { // now execute dokuwiki and grep the output header_remove(); ob_start('ob_start_callback'); + $INPUT = new Input(); include(DOKU_INC.$this->script); ob_end_flush(); @@ -89,6 +95,7 @@ class TestRequest { $_GET = $get; $_POST = $post; $_REQUEST = $request; + $INPUT = $input; return $response; } diff --git a/_test/tests/test/basic.test.php b/_test/tests/test/basic.test.php index 86acef935..0639f0c5a 100644 --- a/_test/tests/test/basic.test.php +++ b/_test/tests/test/basic.test.php @@ -33,7 +33,7 @@ class InttestsBasicTest extends DokuWikiTest { $response = $request->execute(); $this->assertTrue( - strpos($response->getContent(), 'DokuWiki') >= 0, + strpos($response->getContent(), 'DokuWiki') !== false, 'DokuWiki was not a word in the output' ); } @@ -60,7 +60,7 @@ class InttestsBasicTest extends DokuWikiTest { $this->assertEquals('wiki:dokuwiki', $request->getPost('id')); // output check - $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0); + $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') !== false); } function testPostGet() { @@ -84,7 +84,7 @@ class InttestsBasicTest extends DokuWikiTest { $this->assertEquals('wiki:dokuwiki', $request->getGet('id')); // output check - $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0); + $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') !== false); } function testGet() { @@ -116,7 +116,7 @@ class InttestsBasicTest extends DokuWikiTest { $this->assertEquals('bar', $request->getGet('test')); // output check - $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0); + $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') !== false); } function testScripts() { @@ -168,5 +168,13 @@ class InttestsBasicTest extends DokuWikiTest { $response = new TestResponse('',array_slice($this->some_headers,0,-2)); // slice off the last two headers to leave no status header $this->assertNull($response->getStatusCode()); } + + function testINPUT() { + $request = new TestRequest(); + $response = $request->get(array('id' => 'mailinglist'), '/doku.php'); + + // output check + $this->assertTrue(strpos($response->getContent(), 'Netiquette') !== false); + } } -- cgit v1.2.3 From 1eb1257b8846c2228e3f3bb9a3afb5398df3b4fe Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 9 Feb 2014 09:30:01 +0100 Subject: always show error on HTTP test fails --- _test/tests/inc/httpclient_http.test.php | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index 43dd4478f..a19f2d238 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -9,7 +9,7 @@ class httpclient_http_test extends DokuWikiTest { function test_simpleget(){ $http = new HTTPClient(); $data = $http->get($this->server.'/get?foo=bar'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('args',$resp); @@ -22,7 +22,7 @@ class httpclient_http_test extends DokuWikiTest { function test_dget(){ $http = new HTTPClient(); $data = $http->dget($this->server.'/get',array('foo'=>'bar')); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('args',$resp); @@ -35,7 +35,7 @@ class httpclient_http_test extends DokuWikiTest { function test_gzip(){ $http = new HTTPClient(); $data = $http->get($this->server.'/gzip'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('gzipped',$resp); @@ -48,7 +48,7 @@ class httpclient_http_test extends DokuWikiTest { function test_simplepost(){ $http = new HTTPClient(); $data = $http->post($this->server.'/post',array('foo'=>'bar')); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('form',$resp); @@ -61,7 +61,7 @@ class httpclient_http_test extends DokuWikiTest { function test_redirect(){ $http = new HTTPClient(); $data = $http->get($this->server.'/redirect/3'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('url',$resp); @@ -74,7 +74,7 @@ class httpclient_http_test extends DokuWikiTest { function test_relredirect(){ $http = new HTTPClient(); $data = $http->get($this->server.'/relative-redirect/3'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('url',$resp); @@ -87,7 +87,7 @@ class httpclient_http_test extends DokuWikiTest { function test_redirectfail(){ $http = new HTTPClient(); $data = $http->get($this->server.'/redirect/5'); - $this->assertTrue($data === false, 'HTTP response'); + $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals('Maximum number of redirects exceeded',$http->error); } @@ -99,7 +99,7 @@ class httpclient_http_test extends DokuWikiTest { $http->get($this->server.'/cookies/set/foo/bar'); $this->assertEquals(array('foo' => 'bar'), $http->cookies); $data = $http->get($this->server.'/cookies'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('cookies',$resp); @@ -112,7 +112,7 @@ class httpclient_http_test extends DokuWikiTest { function test_teapot(){ $http = new HTTPClient(); $data = $http->get($this->server.'/status/418'); - $this->assertTrue($data === false, 'HTTP response'); + $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals(418,$http->status); } @@ -125,13 +125,13 @@ class httpclient_http_test extends DokuWikiTest { // this should abort completely $data = $http->get($this->server.'/stream/30'); - $this->assertTrue($data === false, 'HTTP response'); + $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'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); /* should read no more than max_bodysize+1 */ $this->assertLessThanOrEqual(251,strlen($data)); } @@ -143,10 +143,10 @@ class httpclient_http_test extends DokuWikiTest { $http = new HTTPClient(); $http->max_bodysize = 500*1024; $data = $http->get($this->server.'/stream/5'); - $this->assertTrue($data !== false, 'HTTP response'); + $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'); + $this->assertTrue($data !== false, 'HTTP response '.$http->error); } /** @@ -157,7 +157,7 @@ class httpclient_http_test extends DokuWikiTest { $http->user = 'user'; $http->pass = 'pass'; $data = $http->get($this->server.'/basic-auth/user/pass'); - $this->assertFalse($data === false, 'HTTP response'); + $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); @@ -171,7 +171,7 @@ class httpclient_http_test extends DokuWikiTest { $http->user = 'user'; $http->pass = 'invalid'; $data = $http->get($this->server.'/basic-auth/user/pass'); - $this->assertTrue($data === false, 'HTTP response'); + $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals(401,$http->status); } @@ -182,7 +182,7 @@ class httpclient_http_test extends DokuWikiTest { $http = new HTTPClient(); $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); } @@ -192,7 +192,7 @@ class httpclient_http_test extends DokuWikiTest { function test_headers(){ $http = new HTTPClient(); $data = $http->get($this->server.'/response-headers?baz=&foo=bar'); - $this->assertFalse($data === false, 'HTTP response'); + $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); @@ -206,7 +206,7 @@ class httpclient_http_test extends DokuWikiTest { function test_chunked(){ $http = new HTTPClient(); $data = $http->get('http://whoopdedo.org/cgi-bin/chunked/2550'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $this->assertEquals(2550,strlen($data)); } @@ -218,7 +218,7 @@ class httpclient_http_test extends DokuWikiTest { function test_wikimatrix(){ $http = new HTTPClient(); $data = $http->get('http://www.wikimatrix.org/cfeed/dokuwiki/-/-'); - $this->assertTrue($data !== false, $http->error); + $this->assertTrue($data !== false, 'HTTP response '.$http->error); } function test_postencode(){ -- cgit v1.2.3 From 95e6ded1b26c14b1ef55699b171ce422827364b1 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 9 Feb 2014 10:08:48 +0100 Subject: more robust HTTP testing connections are now retried after timeout and failing connections will be marked as skipped instead of failing. This should reduce false alarms on travis --- _test/tests/inc/httpclient_http.test.php | 115 +++++++++++++++++++++---- _test/tests/inc/httpclient_http_proxy.test.php | 4 +- _test/tests/inc/httpclient_mock.php | 46 ++++++++++ _test/tests/inc/mailer.test.php | 5 +- 4 files changed, 150 insertions(+), 20 deletions(-) create mode 100644 _test/tests/inc/httpclient_mock.php (limited to '_test') diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index a19f2d238..3446e1184 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -1,14 +1,21 @@ get($this->server.'/get?foo=bar'); + 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'); @@ -20,8 +27,12 @@ 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')); + 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'); @@ -33,8 +44,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_gzip(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get($this->server.'/gzip'); + 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'); @@ -46,8 +61,12 @@ 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')); + 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'); @@ -59,8 +78,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_redirect(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get($this->server.'/redirect/3'); + 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'); @@ -72,8 +95,12 @@ 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'); + 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'); @@ -85,8 +112,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_redirectfail(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get($this->server.'/redirect/5'); + 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,10 +126,18 @@ 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'); + 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'); @@ -110,8 +149,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_teapot(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get($this->server.'/status/418'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals(418,$http->status); } @@ -120,17 +163,25 @@ 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'); + 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'); + 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,12 +191,20 @@ 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'); + 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'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertTrue($data !== false, 'HTTP response '.$http->error); } @@ -153,10 +212,14 @@ class httpclient_http_test extends DokuWikiTest { * @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'); + 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'); @@ -167,10 +230,14 @@ 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'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals(401,$http->status); } @@ -179,7 +246,7 @@ 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 '.$http->error); @@ -190,8 +257,12 @@ 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'); + 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'); @@ -204,8 +275,12 @@ 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'); + 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/-/-'); + 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 diff --git a/_test/tests/inc/httpclient_http_proxy.test.php b/_test/tests/inc/httpclient_http_proxy.test.php index 4aa039fcc..61228ad94 100644 --- a/_test/tests/inc/httpclient_http_proxy.test.php +++ b/_test/tests/inc/httpclient_http_proxy.test.php @@ -1,5 +1,7 @@ $http->proxy_host = 'proxy.andrwe.org'; $http->proxy_port = 8080; diff --git a/_test/tests/inc/httpclient_mock.php b/_test/tests/inc/httpclient_mock.php new file mode 100644 index 000000000..038045c8b --- /dev/null +++ b/_test/tests/inc/httpclient_mock.php @@ -0,0 +1,46 @@ +timeout = 8; // slightly faster timeouts + } + + /** + * Returns true if the connection timed out + * + * @return bool + */ + function noconnection() { + return ($this->tries === 0); + } + + /** + * Retries sending the request multiple times + * + * @param string $url + * @param string $data + * @param string $method + * @return bool + */ + function sendRequest($url, $data = '', $method = 'GET') { + $this->tries = 2; // configures the number of retries + $return = false; + while($this->tries) { + $return = parent::sendRequest($url, $data, $method); + if($this->status != -100) break; + $this->tries--; + } + return $return; + } +} \ No newline at end of file diff --git a/_test/tests/inc/mailer.test.php b/_test/tests/inc/mailer.test.php index 4541d9906..50d282864 100644 --- a/_test/tests/inc/mailer.test.php +++ b/_test/tests/inc/mailer.test.php @@ -191,7 +191,10 @@ class mailer_test extends DokuWikiTest { // ask message lint if it is okay $html = new HTTPClient(); $results = $html->post('http://tools.ietf.org/tools/msglint/msglint', array('msg'=>$msg)); - $this->assertTrue($results !== false); + if($results === false) { + $this->markTestSkipped('no response from validator'); + return; + } // parse the result lines $lines = explode("\n", $results); -- cgit v1.2.3 From 2bbe40cf8802bbc3bbf83d454cc294080ebaf241 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 11 Feb 2014 23:01:29 +0100 Subject: HTTPClient: correctly abort a proxy connection if a needed CONNECT tunnel fails --- _test/tests/inc/httpclient_http_proxy.test.php | 1 - _test/tests/inc/httpclient_https_proxy.test.php | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to '_test') diff --git a/_test/tests/inc/httpclient_http_proxy.test.php b/_test/tests/inc/httpclient_http_proxy.test.php index 61228ad94..c44dc7ed7 100644 --- a/_test/tests/inc/httpclient_http_proxy.test.php +++ b/_test/tests/inc/httpclient_http_proxy.test.php @@ -18,5 +18,4 @@ class httpclient_http_proxy_test extends DokuWikiTest { $this->assertFalse($data === false, 'HTTP response '.$http->error); $this->assertTrue(strpos($data,'DokuWiki') !== false, 'response content'); } - } \ No newline at end of file diff --git a/_test/tests/inc/httpclient_https_proxy.test.php b/_test/tests/inc/httpclient_https_proxy.test.php index aca3b3be2..9402e91af 100644 --- a/_test/tests/inc/httpclient_https_proxy.test.php +++ b/_test/tests/inc/httpclient_https_proxy.test.php @@ -12,4 +12,19 @@ class httpclient_https_proxy_test extends httpclient_http_proxy_test { } parent::setUp(); } + + /** + * @group internet + */ + function test_connectfail(){ + $http = new HTTPMockClient(); + // proxy provided by Andrwe Lord Weber + $http->proxy_host = 'proxy.andrwe.org'; + $http->proxy_port = 8080; + + // the proxy accepts connections to dokuwiki.org only - the connect call should fail + $data = $http->get('https://www.google.com'); + $this->assertFalse($data); + $this->assertEquals(-150, $http->status); + } } \ No newline at end of file -- cgit v1.2.3 From 04180aa92fd6a23e4a6c154bc248e7b09d60d21d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 15 Feb 2014 16:57:04 +0100 Subject: unit test for FS#2173 --- _test/tests/inc/utf8_strtolower.test.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 _test/tests/inc/utf8_strtolower.test.php (limited to '_test') diff --git a/_test/tests/inc/utf8_strtolower.test.php b/_test/tests/inc/utf8_strtolower.test.php new file mode 100644 index 000000000..85f5b270b --- /dev/null +++ b/_test/tests/inc/utf8_strtolower.test.php @@ -0,0 +1,23 @@ + 'αρχιτεκτονική μελέτη', // FS#2173 + ); + + foreach($data as $input => $expected) { + $this->assertEquals($expected, utf8_strtolower($input)); + } + + // just make sure our data was correct + if(function_exists('mb_strtolower')) { + foreach($data as $input => $expected) { + $this->assertEquals($expected, mb_strtolower($input, 'utf-8')); + } + } + } +} \ No newline at end of file -- cgit v1.2.3 From 5d873dd4ce31c79403a01ac0e40ff148be282592 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 23 Feb 2014 10:09:11 +0100 Subject: fixed test cases for last commit --- _test/tests/inc/common_pageinfo.test.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/common_pageinfo.test.php b/_test/tests/inc/common_pageinfo.test.php index 0a1ea0a8f..2b230d9ce 100644 --- a/_test/tests/inc/common_pageinfo.test.php +++ b/_test/tests/inc/common_pageinfo.test.php @@ -38,6 +38,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['writable'] = true; $info['editable'] = true; $info['lastmod'] = false; + $info['currentrev'] = false; $info['meta'] = array(); $info['ip'] = null; $info['user'] = null; @@ -77,6 +78,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['filepath'] = $filename; $info['exists'] = true; $info['lastmod'] = $rev; + $info['currentrev'] = $rev; $info['meta'] = p_get_metadata($ID); $this->assertEquals($info, pageinfo()); @@ -101,6 +103,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['filepath'] = $filename; $info['exists'] = true; $info['lastmod'] = $rev; + $info['currentrev'] = $rev; $info['meta'] = p_get_metadata($ID); $info['rev'] = ''; @@ -131,6 +134,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['namespace'] = 'wiki'; $info['meta'] = p_get_metadata($ID); $info['rev'] = $REV; + $info['currentrev'] = $rev; $info['filepath'] = str_replace('pages','attic',substr($filename,0,-3).$REV.'.txt.gz'); $this->assertEquals($info, pageinfo()); @@ -153,6 +157,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['namespace'] = 'wiki'; $info['exists'] = true; $info['lastmod'] = $rev; + $info['currentrev'] = $rev; $info['meta'] = p_get_metadata($ID); $info['filepath'] = $filename; @@ -197,6 +202,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['filepath'] = $filename; $info['exists'] = true; $info['lastmod'] = $rev; + $info['currentrev'] = $rev; $info['meta'] = p_get_metadata($ID); // need $INFO set correctly for addLogEntry() global $INFO; @@ -226,6 +232,7 @@ class common_pageinfo_test extends DokuWikiTest { touch($filename,$now); $info['lastmod'] = $now; + $info['currentrev'] = $now; $info['meta']['last_change'] = false; $info['ip'] = null; $info['user'] = null; @@ -251,6 +258,7 @@ class common_pageinfo_test extends DokuWikiTest { $info['filepath'] = $filename; $info['exists'] = true; $info['lastmod'] = $rev; + $info['currentrev'] = $rev; $info['meta'] = p_get_metadata($ID); // setup a draft, make it more recent than the current page -- cgit v1.2.3 From 9377d909ce85b1b96b0e953b3c09a2539797d54b Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Tue, 25 Feb 2014 03:00:26 +0000 Subject: add test for p_get_renderer() with fallback --- _test/tests/inc/parserutils_get_renderer.test.php | 79 +++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 _test/tests/inc/parserutils_get_renderer.test.php (limited to '_test') diff --git a/_test/tests/inc/parserutils_get_renderer.test.php b/_test/tests/inc/parserutils_get_renderer.test.php new file mode 100644 index 000000000..0f373227d --- /dev/null +++ b/_test/tests/inc/parserutils_get_renderer.test.php @@ -0,0 +1,79 @@ +assertInstanceOf('Doku_Renderer_xhtml', p_get_renderer('xhtml')); + + $conf = $old_conf; + } + + // test get a renderer plugin + function test_p_get_renderer_plugin() { + global $conf; + global $plugin_controller; + + $old_conf = $conf; + $conf['renderer_xhtml'] = 'get_renderer_test'; + $this->plugin_controller = $plugin_controller; + $plugin_controller = $this; + + $this->assertInstanceOf('renderer_plugin_test', p_get_renderer('xhtml')); + + $conf = $old_conf; + $plugin_controller = $this->plugin_controller; + } + + // test fallback succeeds + function test_p_get_renderer_fallback() { + global $conf; + + $old_conf = $conf; + $conf['renderer_xhtml'] = 'badvalue'; + + $this->assertInstanceOf('Doku_Renderer_xhtml', p_get_renderer('xhtml')); + + $conf = $old_conf; + } + + // test fallback fails + function test_p_get_renderer_fallback_fail() { + global $conf; + + $old_conf = $conf; + $conf['renderer_junk'] = 'badvalue'; + + $this->assertNull(p_get_renderer('junk')); + + $conf = $old_conf; + } + + // wrapper function for the fake plugin controller, return $this for the fake syntax of this test + function load($type,$name,$new=false,$disabled=false){ + if ($name == 'get_renderer_test') { + return new renderer_plugin_test(); + } else { + return $this->plugin_controller->load($type, $name, $new, $disabled); + } + } + } + +require_once DOKU_INC . 'inc/parser/xhtml.php'; + +class renderer_plugin_test extends Doku_Renderer_xhtml { + + function canRender($format) { + return ($format=='xhtml'); + } + +} + +// vim:ts=4:sw=4:et: -- cgit v1.2.3 From f3283f02766b2a2730b81c5a5a0b0a6240af054c Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Tue, 25 Feb 2014 21:15:43 +0000 Subject: change to an Exception and expect it --- _test/tests/inc/parserutils_get_renderer.test.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/parserutils_get_renderer.test.php b/_test/tests/inc/parserutils_get_renderer.test.php index 0f373227d..540063e19 100644 --- a/_test/tests/inc/parserutils_get_renderer.test.php +++ b/_test/tests/inc/parserutils_get_renderer.test.php @@ -45,6 +45,10 @@ class parserutils_get_renderer_test extends DokuWikiTest { } // test fallback fails + /** + * @expectedException Exception + * @expectedExceptionCode E_USER_WARNING + */ function test_p_get_renderer_fallback_fail() { global $conf; -- cgit v1.2.3 From a049856df3f316114a9d936d830d5b6d419b11e6 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Wed, 26 Feb 2014 01:12:33 +0000 Subject: revert back to trigger error --- _test/tests/inc/parserutils_get_renderer.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test') diff --git a/_test/tests/inc/parserutils_get_renderer.test.php b/_test/tests/inc/parserutils_get_renderer.test.php index 540063e19..69aeb3b19 100644 --- a/_test/tests/inc/parserutils_get_renderer.test.php +++ b/_test/tests/inc/parserutils_get_renderer.test.php @@ -46,7 +46,7 @@ class parserutils_get_renderer_test extends DokuWikiTest { // test fallback fails /** - * @expectedException Exception + * @expectedException PHPUnit_Framework_Error * @expectedExceptionCode E_USER_WARNING */ function test_p_get_renderer_fallback_fail() { -- cgit v1.2.3 From c01cdb709fd0bf8c91333c5134743e33bf587833 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 6 Mar 2014 19:58:09 +0000 Subject: Fix unittests broken by previous two commits Mostly this is for unit tests which use of \$_SERVER['REMOTE_USER'] It ensures the reference/alias connection between \$INPUT->server and \$_SERVER is renewed before each test. Tests using TestRequest class will replace this \$INPUT with their own. --- _test/core/DokuWikiTest.php | 3 +++ 1 file changed, 3 insertions(+) (limited to '_test') diff --git a/_test/core/DokuWikiTest.php b/_test/core/DokuWikiTest.php index 91eb5293b..f4521256a 100644 --- a/_test/core/DokuWikiTest.php +++ b/_test/core/DokuWikiTest.php @@ -115,5 +115,8 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase { // reload language $local = $conf['lang']; trigger_event('INIT_LANG_LOAD', $local, 'init_lang', true); + + global $INPUT; + $INPUT = new Input(); } } -- cgit v1.2.3