diff options
Diffstat (limited to '_test/tests')
-rw-r--r-- | _test/tests/general/general_languagelint.php | 47 | ||||
-rw-r--r-- | _test/tests/inc/changelog_getRevisionsAround.test.php (renamed from _test/tests/inc/changelog_getRevisionsAround.php) | 47 | ||||
-rw-r--r-- | _test/tests/inc/common_basicinfo.test.php | 10 | ||||
-rw-r--r-- | _test/tests/inc/common_mediainfo.test.php | 10 | ||||
-rw-r--r-- | _test/tests/inc/common_pageinfo.test.php | 66 | ||||
-rw-r--r-- | _test/tests/inc/httpclient_http.test.php | 153 | ||||
-rw-r--r-- | _test/tests/inc/httpclient_http_proxy.test.php | 5 | ||||
-rw-r--r-- | _test/tests/inc/httpclient_https_proxy.test.php | 15 | ||||
-rw-r--r-- | _test/tests/inc/httpclient_mock.php | 46 | ||||
-rw-r--r-- | _test/tests/inc/indexer_indexing.test.php | 17 | ||||
-rw-r--r-- | _test/tests/inc/io_rmdir.test.php | 219 | ||||
-rw-r--r-- | _test/tests/inc/mailer.test.php | 19 | ||||
-rw-r--r-- | _test/tests/inc/parser/parser_table.test.php | 19 | ||||
-rw-r--r-- | _test/tests/test/basic.test.php | 28 |
14 files changed, 586 insertions, 115 deletions
diff --git a/_test/tests/general/general_languagelint.php b/_test/tests/general/general_languagelint.php new file mode 100644 index 000000000..c11462640 --- /dev/null +++ b/_test/tests/general/general_languagelint.php @@ -0,0 +1,47 @@ +<?php + +class general_languagelint_test extends DokuWikiTest { + + + function test_core() { + $this->checkFiles(glob(DOKU_INC.'inc/lang/*/*.php')); + } + + function test_plugins() { + $this->checkFiles(glob(DOKU_INC.'lib/plugins/*/lang/*/*.php')); + } + + /** + * Run checks over the given PHP language files + * + * @param $files + */ + private function checkFiles($files){ + foreach($files as $file){ + // try to load the file + include $file; + // check it defines an array + $this->assertTrue(is_array($lang), $file); + unset($lang); + + $this->checkUgly($file); + } + } + + /** + * Checks if the file contains any ugly things like leading whitespace, BOM or trailing + * PHP closing mark + * + * @param $file + * @throws Exception + */ + private function checkUgly($file){ + $content = rtrim(file_get_contents($file)); + if(substr($content,0,5) != '<?php') + throw new Exception("$file does not start with '<?php' - check for BOM"); + + if(substr($content,-2) == '?>') + throw new Exception("$file ends with '?>' - remove it!"); + } + +} diff --git a/_test/tests/inc/changelog_getRevisionsAround.php b/_test/tests/inc/changelog_getRevisionsAround.test.php index d4d6b8496..2a5cb849e 100644 --- a/_test/tests/inc/changelog_getRevisionsAround.php +++ b/_test/tests/inc/changelog_getRevisionsAround.test.php @@ -12,19 +12,19 @@ class changelog_getrevisionsaround_test extends DokuWikiTest { * list of revisions in mailinglist.changes */ private $revsexpected = array( - 1360110636, - 1361901536, 1362524799, - 1362525145, 1362525359, - 1362525899, 1362525926, - 1362526039, 1362526119, - 1362526167, 1362526767, - 1362526861, 1362527046, - 1362527164, 1363436892, - 1368575634, 1368609772, - 1368612506, 1368612599, - 1368622152, 1368622195, - 1368622240, 1371579614, - 1374261194 //current page + 1374261194, //current page + 1371579614, 1368622240, + 1368622195, 1368622152, + 1368612599, 1368612506, + 1368609772, 1368575634, + 1363436892, 1362527164, + 1362527046, 1362526861, + 1362526767, 1362526167, + 1362526119, 1362526039, + 1362525926, 1362525899, + 1362525359, 1362525145, + 1362524799, 1361901536, + 1360110636 ); private $pageid = 'mailinglist'; @@ -63,8 +63,8 @@ class changelog_getrevisionsaround_test extends DokuWikiTest { $rev2 = 1362527164; $max = 10; $revsexpected = array( - array_slice($this->revsexpected, 5, 11), - array_slice($this->revsexpected, 8, 11) + array_slice($this->revsexpected, 8, 11), + array_slice($this->revsexpected, 5, 11) ); $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); @@ -88,8 +88,8 @@ class changelog_getrevisionsaround_test extends DokuWikiTest { $rev2 = 1368612599; $max = 10; $revsexpected = array( - array_slice($this->revsexpected, 0, 11), - array_slice($this->revsexpected, 13, 11) + array_slice($this->revsexpected, 13, 11), + array_slice($this->revsexpected, 0, 11) ); $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); @@ -114,14 +114,19 @@ class changelog_getrevisionsaround_test extends DokuWikiTest { $rev2 = 1374261194; $max = 10; $revsexpected = array( - array_slice($this->revsexpected, 0, 11), - array_slice($this->revsexpected, 13, 11) + array_slice($this->revsexpected, 13, 11), + array_slice($this->revsexpected, 0, 11) ); $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max); $this->assertEquals($revsexpected, $revs); + //todo: number of revisions on the left side is not (yet) completed until max number + $revsexpected = array( + array_slice($this->revsexpected, 18, 6), + array_slice($this->revsexpected, 0, 11) + ); $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512); $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max); $this->assertEquals($revsexpected, $revs); @@ -163,8 +168,8 @@ class changelog_getrevisionsaround_test extends DokuWikiTest { $rev2 = 1362526767; $max = 10; $revsexpected = array( - array_slice($this->revsexpected, 5, 11), - array_slice($this->revsexpected, 8, 11) + array_slice($this->revsexpected, 8, 11), + array_slice($this->revsexpected, 5, 11) ); $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192); diff --git a/_test/tests/inc/common_basicinfo.test.php b/_test/tests/inc/common_basicinfo.test.php index 0369474c9..8359c0877 100644 --- a/_test/tests/inc/common_basicinfo.test.php +++ b/_test/tests/inc/common_basicinfo.test.php @@ -18,12 +18,12 @@ class common_infofunctions_test extends DokuWikiTest { function _get_info() { global $USERINFO; - $info = array (
- 'isadmin' => true,
+ $info = array ( + 'isadmin' => true, 'ismanager' => true, - 'userinfo' => $USERINFO,
- 'perm' => 255,
- 'namespace' => false,
+ 'userinfo' => $USERINFO, + 'perm' => 255, + 'namespace' => false, 'ismobile' => false, 'client' => 'testuser', ); diff --git a/_test/tests/inc/common_mediainfo.test.php b/_test/tests/inc/common_mediainfo.test.php index 0e67fbcd9..cc5b17ec7 100644 --- a/_test/tests/inc/common_mediainfo.test.php +++ b/_test/tests/inc/common_mediainfo.test.php @@ -18,12 +18,12 @@ class common_basicinfo_test extends DokuWikiTest { function _get_info() { global $USERINFO; - $info = array (
- 'isadmin' => true,
+ $info = array ( + 'isadmin' => true, 'ismanager' => true, - 'userinfo' => $USERINFO,
- 'perm' => 255,
- 'namespace' => false,
+ 'userinfo' => $USERINFO, + 'perm' => 255, + 'namespace' => false, 'ismobile' => false, 'client' => 'testuser', ); diff --git a/_test/tests/inc/common_pageinfo.test.php b/_test/tests/inc/common_pageinfo.test.php index c54fbce26..0a1ea0a8f 100644 --- a/_test/tests/inc/common_pageinfo.test.php +++ b/_test/tests/inc/common_pageinfo.test.php @@ -31,18 +31,18 @@ class common_pageinfo_test extends DokuWikiTest { 'ismobile' => false, 'client' => 'testuser', ); - $info['rev'] = null;
- $info['subscribed'] = false;
- $info['locked'] = false;
- $info['exists'] = false;
- $info['writable'] = true;
- $info['editable'] = true;
- $info['lastmod'] = false;
- $info['meta'] = array();
- $info['ip'] = null;
- $info['user'] = null;
- $info['sum'] = null;
- $info['editor'] = null;
+ $info['rev'] = null; + $info['subscribed'] = false; + $info['locked'] = false; + $info['exists'] = false; + $info['writable'] = true; + $info['editable'] = true; + $info['lastmod'] = false; + $info['meta'] = array(); + $info['ip'] = null; + $info['user'] = null; + $info['sum'] = null; + $info['editor'] = null; return $info; } @@ -72,15 +72,15 @@ class common_pageinfo_test extends DokuWikiTest { $rev = filemtime($filename); $info = $this->_get_expected_pageinfo(); - $info['id'] = 'wiki:syntax';
+ $info['id'] = 'wiki:syntax'; $info['namespace'] = 'wiki'; $info['filepath'] = $filename; - $info['exists'] = true;
- $info['lastmod'] = $rev;
- $info['meta'] = p_get_metadata($ID);
+ $info['exists'] = true; + $info['lastmod'] = $rev; + $info['meta'] = p_get_metadata($ID); $this->assertEquals($info, pageinfo()); - }
+ } /** * check info keys and values for anonymous user @@ -88,8 +88,8 @@ class common_pageinfo_test extends DokuWikiTest { function test_anonymoususer(){ global $ID,$conf,$REV; - unset($_SERVER['REMOTE_USER']);
- global $USERINFO; $USERINFO = array();
+ unset($_SERVER['REMOTE_USER']); + global $USERINFO; $USERINFO = array(); $ID = 'wiki:syntax'; $filename = $conf['datadir'].'/wiki/syntax.txt'; @@ -104,15 +104,15 @@ class common_pageinfo_test extends DokuWikiTest { $info['meta'] = p_get_metadata($ID); $info['rev'] = ''; - $info = array_merge($info, array(
- 'isadmin' => false,
- 'ismanager' => false,
- 'perm' => 8,
- 'client' => '1.2.3.4',
+ $info = array_merge($info, array( + 'isadmin' => false, + 'ismanager' => false, + 'perm' => 8, + 'client' => '1.2.3.4', )); unset($info['userinfo']); $this->assertEquals($info, pageinfo()); - }
+ } /** * check info keys and values with $REV @@ -135,7 +135,7 @@ class common_pageinfo_test extends DokuWikiTest { $this->assertEquals($info, pageinfo()); $this->assertEquals($rev-100, $REV); - }
+ } /** * check info keys and values with $RANGE @@ -146,7 +146,7 @@ class common_pageinfo_test extends DokuWikiTest { $ID = 'wiki:syntax'; $filename = $conf['datadir'].'/wiki/syntax.txt'; $rev = filemtime($filename); - $range = '1000-2000';
+ $range = '1000-2000'; $info = $this->_get_expected_pageinfo(); $info['id'] = 'wiki:syntax'; @@ -160,18 +160,18 @@ class common_pageinfo_test extends DokuWikiTest { // expected result $RANGE unchanged $RANGE = $range; - $this->assertEquals($info, pageinfo());
+ $this->assertEquals($info, pageinfo()); $this->assertFalse(isset($REV)); - $this->assertEquals($range,$RANGE);
+ $this->assertEquals($range,$RANGE); // check $RANGE with $REV = current // expected result: $RANGE unchanged, $REV cleared $REV = $rev; - $info['rev'] = '';
+ $info['rev'] = ''; - $this->assertEquals($info, pageinfo());
+ $this->assertEquals($info, pageinfo()); $this->assertEquals('',$REV); - $this->assertEquals($range,$RANGE);
+ $this->assertEquals($range,$RANGE); // check with a real $REV // expected result: $REV and $RANGE are cleared @@ -218,7 +218,7 @@ class common_pageinfo_test extends DokuWikiTest { p_set_metadata($ID,array('last_change' => false)); $this->assertEquals($info, pageinfo()); - $this->assertEquals($info['meta']['last_change'], p_get_metadata($ID,'last_change'));
+ $this->assertEquals($info['meta']['last_change'], p_get_metadata($ID,'last_change')); // fake an external edit, pageinfo should clear the last change from meta data // and not return any editor data 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 diff --git a/_test/tests/inc/httpclient_http_proxy.test.php b/_test/tests/inc/httpclient_http_proxy.test.php index 4aa039fcc..c44dc7ed7 100644 --- a/_test/tests/inc/httpclient_http_proxy.test.php +++ b/_test/tests/inc/httpclient_http_proxy.test.php @@ -1,5 +1,7 @@ <?php +require_once (__DIR__ . '/httpclient_mock.php'); + class httpclient_http_proxy_test extends DokuWikiTest { protected $url = 'http://test.dokuwiki.org/README'; @@ -7,7 +9,7 @@ class httpclient_http_proxy_test extends DokuWikiTest { * @group internet */ function test_simpleget(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); // proxy provided by Andrwe Lord Weber <dokuwiki@andrwe.org> $http->proxy_host = 'proxy.andrwe.org'; $http->proxy_port = 8080; @@ -16,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 <dokuwiki@andrwe.org> + $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 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 @@ +<?php +/** + * Class HTTPMockClient + * + * Does not really mock the client, it still does real connections but will retry failed connections + * to work around shaky connectivity. + */ +class HTTPMockClient extends HTTPClient { + protected $tries; + + /** + * Sets shorter timeout + */ + function __construct() { + parent::__construct(); + $this->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/indexer_indexing.test.php b/_test/tests/inc/indexer_indexing.test.php index 628e82e00..3d8278d6c 100644 --- a/_test/tests/inc/indexer_indexing.test.php +++ b/_test/tests/inc/indexer_indexing.test.php @@ -42,4 +42,21 @@ class indexer_indexing_test extends DokuWikiTest { $query = array('001', '01'); $this->assertEquals(array('001' => array(), '01' => array('testpage')), $indexer->lookupKey('numkey', $query)); } + + public function test_numeric_twice() { + $indexer = idx_get_indexer(); + $indexer->addPageWords('testpage', '| 1010 | Dallas |'); + $query = array('1010'); + $this->assertEquals(array('1010' => array('testpage' => 1)), $indexer->lookup($query)); + $indexer->addPageWords('notfound', '| 1010 | Dallas |'); + $this->assertEquals(array('1010' => array('testpage' => 1, 'notfound' => 1)), $indexer->lookup($query)); + } + + public function test_numeric_twice_meta() { + $indexer = idx_get_indexer(); + $indexer->addMetaKeys('testpage', 'onezero', array('1010')); + $indexer->addMetaKeys('notfound', 'onezero', array('1010')); + $query = '1010'; + $this->assertEquals(array('notfound', 'testpage'), $indexer->lookupKey('onezero', $query)); + } }
\ No newline at end of file diff --git a/_test/tests/inc/io_rmdir.test.php b/_test/tests/inc/io_rmdir.test.php new file mode 100644 index 000000000..3de57fa86 --- /dev/null +++ b/_test/tests/inc/io_rmdir.test.php @@ -0,0 +1,219 @@ +<?php + +class io_rmdir_test extends DokuWikiTest { + + function test_nopes(){ + // set up test dir + $dir = io_mktmpdir(); + $top = dirname($dir); + $this->assertTrue($dir !== false); + $this->assertTrue(is_dir($dir)); + + // switch into it + $this->assertTrue(chdir($dir)); + $this->assertEquals($dir, getcwd()); + + + $this->assertFalse(io_rmdir('', false)); + clearstatcache(); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + $this->assertFalse(io_rmdir('', true)); + clearstatcache(); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + $this->assertFalse(io_rmdir(null, false)); + clearstatcache(); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + $this->assertFalse(io_rmdir(null, true)); + clearstatcache(); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + $this->assertFalse(io_rmdir(false, false)); + clearstatcache(); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + $this->assertFalse(io_rmdir(false, true)); + clearstatcache(); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + $this->assertFalse(io_rmdir(array(), false)); + clearstatcache(); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + $this->assertFalse(io_rmdir(array(), true)); + clearstatcache(); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + $this->assertFileNotExists("$dir/this/does/not/exist"); + $this->assertTrue(io_rmdir("$dir/this/does/not/exist")); + clearstatcache(); + $this->assertFileNotExists("$dir/this/does/not/exist"); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_dir($top)); + } + + + function test_empty_single(){ + // set up test dir + $dir = io_mktmpdir(); + $top = dirname($dir); + $this->assertTrue($dir !== false); + $this->assertTrue(is_dir($dir)); + + // delete successfully + $this->assertTrue(io_rmdir($dir, false)); + + // check result + clearstatcache(); + $this->assertFalse(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + // same again with deletefiles + + // set up test dir + $dir = io_mktmpdir(); + $this->assertTrue($dir !== false); + $this->assertTrue(is_dir($dir)); + + // delete successfully + $this->assertTrue(io_rmdir($dir, true)); + + // check result + clearstatcache(); + $this->assertFalse(is_dir($dir)); + $this->assertTrue(is_dir($top)); + } + + + function test_empty_hierarchy(){ + // setup hierachy and test it exists + $dir = io_mktmpdir(); + $top = dirname($dir); + $this->assertTrue($dir !== false); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(io_mkdir_p("$dir/foo/bar/baz")); + $this->assertTrue(is_dir("$dir/foo/bar/baz")); + $this->assertTrue(io_mkdir_p("$dir/foobar/bar/baz")); + $this->assertTrue(is_dir("$dir/foobar/bar/baz")); + + // delete successfully + $this->assertTrue(io_rmdir($dir, false)); + + // check result + clearstatcache(); + $this->assertFalse(is_dir("$dir/foo/bar/baz")); + $this->assertFalse(is_dir("$dir/foobar/bar/baz")); + $this->assertFalse(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + // same again with deletefiles + + // setup hierachy and test it exists + $dir = io_mktmpdir(); + $this->assertTrue($dir !== false); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(io_mkdir_p("$dir/foo/bar/baz")); + $this->assertTrue(is_dir("$dir/foo/bar/baz")); + $this->assertTrue(io_mkdir_p("$dir/foobar/bar/baz")); + $this->assertTrue(is_dir("$dir/foobar/bar/baz")); + + // delete successfully + $this->assertTrue(io_rmdir($dir, true)); + + // check result + clearstatcache(); + $this->assertFalse(is_dir("$dir/foo/bar/baz")); + $this->assertFalse(is_dir("$dir/foobar/bar/baz")); + $this->assertFalse(is_dir($dir)); + $this->assertTrue(is_dir($top)); + } + + function test_full_single(){ + // set up test dir + $dir = io_mktmpdir(); + $top = dirname($dir); + $this->assertTrue($dir !== false); + $this->assertTrue(is_dir($dir)); + + // put file + $this->assertTrue(io_saveFile("$dir/testfile.txt", 'foobar')); + $this->assertFileExists("$dir/testfile.txt"); + + // delete unsuccessfully + $this->assertFalse(io_rmdir($dir, false)); + + // check result + clearstatcache(); + $this->assertFileExists("$dir/testfile.txt"); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + // same again with deletefiles + + // delete successfully + $this->assertTrue(io_rmdir($dir, true)); + + // check result + clearstatcache(); + $this->assertFileNotExists("$dir/testfile.txt"); + $this->assertFalse(is_dir($dir)); + $this->assertTrue(is_dir($top)); + } + + function test_full_hierarchy(){ + // setup hierachy and test it exists + $dir = io_mktmpdir(); + $top = dirname($dir); + $this->assertTrue($dir !== false); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(io_mkdir_p("$dir/foo/bar/baz")); + $this->assertTrue(is_dir("$dir/foo/bar/baz")); + $this->assertTrue(io_mkdir_p("$dir/foobar/bar/baz")); + $this->assertTrue(is_dir("$dir/foobar/bar/baz")); + + // put files + $this->assertTrue(io_saveFile("$dir/testfile.txt", 'foobar')); + $this->assertFileExists("$dir/testfile.txt"); + $this->assertTrue(io_saveFile("$dir/foo/testfile.txt", 'foobar')); + $this->assertFileExists("$dir/foo/testfile.txt"); + $this->assertTrue(io_saveFile("$dir/foo/bar/baz/testfile.txt", 'foobar')); + $this->assertFileExists("$dir/foo/bar/baz/testfile.txt"); + + // delete unsuccessfully + $this->assertFalse(io_rmdir($dir, false)); + + // check result + clearstatcache(); + $this->assertFileExists("$dir/testfile.txt"); + $this->assertFileExists("$dir/foo/testfile.txt"); + $this->assertFileExists("$dir/foo/bar/baz/testfile.txt"); + $this->assertTrue(is_dir("$dir/foo/bar/baz")); + $this->assertTrue(is_dir("$dir/foobar/bar/baz")); + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_dir($top)); + + // delete successfully + $this->assertTrue(io_rmdir($dir, true)); + + // check result + clearstatcache(); + $this->assertFileNotExists("$dir/testfile.txt"); + $this->assertFileNotExists("$dir/foo/testfile.txt"); + $this->assertFileNotExists("$dir/foo/bar/baz/testfile.txt"); + $this->assertFalse(is_dir("$dir/foo/bar/baz")); + $this->assertFalse(is_dir("$dir/foobar/bar/baz")); + $this->assertFalse(is_dir($dir)); + $this->assertTrue(is_dir($top)); + } + +}
\ No newline at end of file diff --git a/_test/tests/inc/mailer.test.php b/_test/tests/inc/mailer.test.php index bac0c39ba..50d282864 100644 --- a/_test/tests/inc/mailer.test.php +++ b/_test/tests/inc/mailer.test.php @@ -154,7 +154,19 @@ class mailer_test extends DokuWikiTest { $headers['Cc'] = ''; $header = $mail->prepareHeaders(); $this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.'); - $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Bcc found in headers.'); + $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Cc found in headers.'); + } + + function test_nullTOorCCorBCC() { + $mail = new TestMailer(); + $headers = &$mail->propRef('headers'); + $headers['Bcc'] = NULL; + $headers['Cc'] = NULL; + $headers['To'] = NULL; + $header = $mail->prepareHeaders(); + $this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.'); + $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Cc found in headers.'); + $this->assertEquals(0, preg_match('/(^|\n)To: (\n|$)/', $header), 'To found in headers.'); } /** @@ -179,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); diff --git a/_test/tests/inc/parser/parser_table.test.php b/_test/tests/inc/parser/parser_table.test.php index 542a307b8..bc19ebff9 100644 --- a/_test/tests/inc/parser/parser_table.test.php +++ b/_test/tests/inc/parser/parser_table.test.php @@ -626,5 +626,24 @@ def'); ); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } + + function testTable_FS1833() { + $syntax = " \n| Row 0 Col 1 |\n"; + $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->parse($syntax); + $calls = array ( + array('document_start',array()), + array('table_open',array(1, 1, 2)), + array('tablerow_open',array()), + array('tablecell_open',array(1,'left',1)), + array('cdata',array(' Row 0 Col 1 ')), + array('tablecell_close',array()), + array('tablerow_close',array()), + array('table_close',array(strlen($syntax))), + array('document_end',array()), + ); + $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + } + } diff --git a/_test/tests/test/basic.test.php b/_test/tests/test/basic.test.php index 05778ccf9..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,18 +116,18 @@ 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() { $request = new TestRequest(); // doku - $response = $request->get();
- $this->assertEquals('doku.php',$request->getScript());
+ $response = $request->get(); + $this->assertEquals('doku.php',$request->getScript()); - $response = $request->get(array(),'/doku.php?id=wiki:dokuwiki&test=foo');
- $this->assertEquals('doku.php',$request->getScript());
+ $response = $request->get(array(),'/doku.php?id=wiki:dokuwiki&test=foo'); + $this->assertEquals('doku.php',$request->getScript()); // fetch $response = $request->get(array(),'/lib/exe/fetch.php?media=wiki:dokuwiki-128.png'); @@ -149,8 +149,8 @@ class InttestsBasicTest extends DokuWikiTest { $request = new TestRequest(); $response = $request->get(array(),'/lib/exe/fetch.php?media=wiki:dokuwiki-128.png'); - $headers = $response->getHeaders();
- $this->assertTrue(!empty($headers));
+ $headers = $response->getHeaders(); + $this->assertTrue(!empty($headers)); } function testGetHeader(){ @@ -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); + } } |