From 74ed54d4f9a7c9796916f33f649ef94619a31704 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 16 Oct 2013 11:29:27 +0200 Subject: fix signature mail unittest, and improve some signatures info plugin --- _test/tests/inc/subscription.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test/tests') diff --git a/_test/tests/inc/subscription.test.php b/_test/tests/inc/subscription.test.php index 333400576..34a7b9e4b 100644 --- a/_test/tests/inc/subscription.test.php +++ b/_test/tests/inc/subscription.test.php @@ -237,7 +237,7 @@ class MockupSubscription extends Subscription { return parent::buildregex($user, $style, $data); } - protected function send($subscriber_mail, $subject, $id, $template, $trep, $hrep = null) { + protected function send($subscriber_mail, $subject, $id, $template, $trep, $hrep = null, $headers = array()) { $this->mails[] = $subscriber_mail; return true; } -- cgit v1.2.3 From c8d2e830e238503225cac35736b815864d334b1d Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Wed, 16 Oct 2013 21:50:25 +0100 Subject: escape '$' in mailer test strings --- _test/tests/inc/mailer.test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to '_test/tests') diff --git a/_test/tests/inc/mailer.test.php b/_test/tests/inc/mailer.test.php index 3a89413b4..dc234232f 100644 --- a/_test/tests/inc/mailer.test.php +++ b/_test/tests/inc/mailer.test.php @@ -50,8 +50,8 @@ class mailer_test extends DokuWikiTest { // set a bunch of test headers $mail->setHeader('test-header','bla'); $mail->setHeader('to','A valid ASCII name '); - $mail->setHeader('from',"Thös ne\needs\x00serious cleaning$§%."); - $mail->setHeader('bad',"Thös ne\needs\x00serious cleaning$§%.",false); + $mail->setHeader('from',"Thös ne\needs\x00serious cleaning\$§%."); + $mail->setHeader('bad',"Thös ne\needs\x00serious cleaning\$§%.",false); $mail->setHeader("weird\n*+\x00foo.-_@bar?",'now clean'); // are they set? -- cgit v1.2.3 From 4d8acaacee33f49d51c06f6dae1dbe245018a020 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Wed, 16 Oct 2013 21:52:02 +0100 Subject: remove '&' reference operator from metadata test, not required in php5 --- _test/tests/inc/parserutils_set_metadata_during_rendering.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test/tests') diff --git a/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php b/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php index f08785ca2..18660553d 100644 --- a/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php +++ b/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php @@ -80,7 +80,7 @@ class parserutils_set_metadata_during_rendering_test extends DokuWikiTest { } // wrapper function for the fake plugin controller, return $this for the fake syntax of this test - function &load($type,$name,$new=false,$disabled=false){ + function load($type,$name,$new=false,$disabled=false){ if ($name == 'parserutils_test') { return $this; } else { -- cgit v1.2.3 From d301130ed39d5dad319c60cdb3879c6751611831 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sat, 19 Oct 2013 14:35:22 +0100 Subject: additional auth_nameencode tests (apostrophe & backslash) --- _test/tests/inc/auth_nameencode.test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/inc/auth_nameencode.test.php b/_test/tests/inc/auth_nameencode.test.php index da9f31f90..074155486 100644 --- a/_test/tests/inc/auth_nameencode.test.php +++ b/_test/tests/inc/auth_nameencode.test.php @@ -19,6 +19,18 @@ class auth_nameencode_test extends DokuWikiTest { $this->assertEquals(auth_nameencode($in),$out); } + function test_apostrophe(){ + $in = 'hey\'you'; + $out = 'hey%27you'; + $this->assertEquals(auth_nameencode($in),$out); + } + + function test_backslash(){ + $in = 'hey\\you'; + $out = 'hey%5cyou'; + $this->assertEquals(auth_nameencode($in),$out); + } + function test_complex(){ $in = 'hey $ you !$%! foo '; $out = 'hey%20%24%20you%20%21%24%25%21%20foo%20'; -- cgit v1.2.3 From a8dba4523d2ecd09dd69a68a36673eaf5c009c57 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sat, 19 Oct 2013 16:09:15 +0200 Subject: Fix FS#2854: Treat numerically different keys as different --- _test/tests/inc/indexer_indexing.test.php | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 _test/tests/inc/indexer_indexing.test.php (limited to '_test/tests') diff --git a/_test/tests/inc/indexer_indexing.test.php b/_test/tests/inc/indexer_indexing.test.php new file mode 100644 index 000000000..8600cf156 --- /dev/null +++ b/_test/tests/inc/indexer_indexing.test.php @@ -0,0 +1,45 @@ + + */ +class indexer_indexing_test extends DokuWikiTest { + public function setUp() { + parent::setUp(); + saveWikiText('testpage', 'Foo bar baz.', 'Test initialization'); + saveWikiText('notfound', 'Foon barn bazn.', 'Test initialization'); + idx_addPage('testpage'); + idx_addPage('notfound'); + } + + public function test_words() { + $indexer = idx_get_indexer(); + $query = array('baz', 'foo'); + $this->assertEquals(array('baz' => array('testpage' => 1), 'foo' => array('testpage' => 1)), $indexer->lookup($query)); + } + + public function test_numerically_identical_words() { + $indexer = idx_get_indexer(); + $indexer->addPageWords('testpage', '0x1 002'); + $indexer->addPageWords('notfound', '0x2'); + $query = array('001', '002'); + $this->assertEquals(array('001' => array('notfound' => 1), '002' => array('testpage' => 1)), $indexer->lookup($query)); + } + + public function test_meta() { + $indexer = idx_get_indexer(); + $indexer->addMetaKeys('testpage', 'testkey', 'testvalue'); + $indexer->addMetaKeys('notfound', 'testkey', 'notvalue'); + $query = 'testvalue'; + $this->assertEquals(array('testpage'), $indexer->lookupKey('testkey', $query)); + } + + public function test_numerically_identical_meta_values() { + $indexer = idx_get_indexer(); + $indexer->addMetaKeys('testpage', 'numkey', array('0001', '01')); + $indexer->addMetaKeys('notfound', 'numkey', array('00001', '000001')); + $query = array('001', '01'); + $this->assertEquals(array('001' => array(), '01' => array('testpage')), $indexer->lookupKey('numkey', $query)); + } +} \ No newline at end of file -- cgit v1.2.3 From 9f5b9cf15569babaa90f0d6f3dd58cefd5439bc5 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sat, 19 Oct 2013 17:10:43 +0200 Subject: Fix the indexer indexing test case (changed the data but not the result) --- _test/tests/inc/indexer_indexing.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test/tests') diff --git a/_test/tests/inc/indexer_indexing.test.php b/_test/tests/inc/indexer_indexing.test.php index 8600cf156..628e82e00 100644 --- a/_test/tests/inc/indexer_indexing.test.php +++ b/_test/tests/inc/indexer_indexing.test.php @@ -24,7 +24,7 @@ class indexer_indexing_test extends DokuWikiTest { $indexer->addPageWords('testpage', '0x1 002'); $indexer->addPageWords('notfound', '0x2'); $query = array('001', '002'); - $this->assertEquals(array('001' => array('notfound' => 1), '002' => array('testpage' => 1)), $indexer->lookup($query)); + $this->assertEquals(array('001' => array(), '002' => array('testpage' => 1)), $indexer->lookup($query)); } public function test_meta() { -- cgit v1.2.3 From 698e7df8c9d5c43a93ed6822efa537158682a700 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sat, 19 Oct 2013 18:24:20 +0100 Subject: add tests for usernames with 2 & 3 byte utf8 characters --- _test/tests/inc/auth_nameencode.test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/inc/auth_nameencode.test.php b/_test/tests/inc/auth_nameencode.test.php index da9f31f90..64e437004 100644 --- a/_test/tests/inc/auth_nameencode.test.php +++ b/_test/tests/inc/auth_nameencode.test.php @@ -42,6 +42,22 @@ class auth_nameencode_test extends DokuWikiTest { $out = '%40hey%24you'; $this->assertEquals(auth_nameencode($in),$out); } + + // include a two byte utf8 character which shouldn't be encoded + function test_hebrew(){ + $in = 'nun-נ8'; + $expect = 'nun%2dנ8'; + + $this->assertEquals($expect, auth_nameencode($in)); + } + + // include a three byte utf8 character which shouldn't be encoded + function test_devanagiri(){ + $in = 'ut-fठ8'; + $expect = 'ut%2dfठ8'; + + $this->assertEquals($expect, auth_nameencode($in)); + } } //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From d1612d99b95fed9b053ebdb5e4c12f30aeb69203 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 20 Oct 2013 21:05:09 +0200 Subject: escaped another $ in mailer test --- _test/tests/inc/mailer.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test/tests') diff --git a/_test/tests/inc/mailer.test.php b/_test/tests/inc/mailer.test.php index dc234232f..bac0c39ba 100644 --- a/_test/tests/inc/mailer.test.php +++ b/_test/tests/inc/mailer.test.php @@ -63,7 +63,7 @@ class mailer_test extends DokuWikiTest { $this->assertArrayHasKey('From',$headers); $this->assertEquals('Ths neeedsserious cleaning.',$headers['From']); $this->assertArrayHasKey('Bad',$headers); - $this->assertEquals("Thös ne\needs\x00serious cleaning$§%.",$headers['Bad']); + $this->assertEquals("Thös ne\needs\x00serious cleaning\$§%.",$headers['Bad']); $this->assertArrayHasKey('Weird+foo.-_@bar',$headers); // unset a header again -- cgit v1.2.3 From 712c66312b26ec08723b47583b7be846451ed712 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 20 Oct 2013 21:28:32 +0200 Subject: more verbosity in test case --- _test/tests/inc/httpclient_http_proxy.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test/tests') diff --git a/_test/tests/inc/httpclient_http_proxy.test.php b/_test/tests/inc/httpclient_http_proxy.test.php index faa7a4280..c53e3579c 100644 --- a/_test/tests/inc/httpclient_http_proxy.test.php +++ b/_test/tests/inc/httpclient_http_proxy.test.php @@ -13,7 +13,7 @@ class httpclient_http_proxy_test extends DokuWikiTest { $http->proxy_port = 8080; $data = $http->get($this->url); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $this->assertTrue(strpos($data,'DokuWiki') !== false, 'response content'); } -- cgit v1.2.3 From b7cfeab63d3666a24fad96ae42669a2f55e9da03 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 20 Oct 2013 21:37:54 +0200 Subject: make sure HTTP test uses HTTP only and doesn't get redirected --- _test/tests/inc/httpclient_http_proxy.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test/tests') diff --git a/_test/tests/inc/httpclient_http_proxy.test.php b/_test/tests/inc/httpclient_http_proxy.test.php index c53e3579c..4aa039fcc 100644 --- a/_test/tests/inc/httpclient_http_proxy.test.php +++ b/_test/tests/inc/httpclient_http_proxy.test.php @@ -1,7 +1,7 @@ Date: Fri, 25 Oct 2013 13:30:27 +0100 Subject: unittests for auth_loadACL --- _test/tests/inc/auth_loadacl.test.php | 121 ++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 _test/tests/inc/auth_loadacl.test.php (limited to '_test/tests') diff --git a/_test/tests/inc/auth_loadacl.test.php b/_test/tests/inc/auth_loadacl.test.php new file mode 100644 index 000000000..5e7ac3acf --- /dev/null +++ b/_test/tests/inc/auth_loadacl.test.php @@ -0,0 +1,121 @@ +assertEquals($expect, $this->auth_loadACL_testwrapper($acls)); + } + + function test_user_substitution() { + $acls = <<assertEquals($expect, $this->auth_loadACL_testwrapper($acls)); + } + + function test_group_substitution() { + $acls = <<assertEquals($expect, $this->auth_loadACL_testwrapper($acls)); + } + + function test_both_substitution() { + $acls = <<assertEquals($expect, $this->auth_loadACL_testwrapper($acls)); + } + + // put it all together - read the standard acl provided with the test suite + function test_standardtestacls(){ + $expect = array( + "*\t@ALL 8", + "private:*\t@ALL 0", + "users:*\t@ALL 1", + "users:testuser:*\ttestuser 16", + "groups:*\t@ALL 1", + "groups:foo:*\t@foo 16", + "groups:bar:*\t@bar 16", + ); + $this->assertEquals($expect, auth_loadACL()); + } + + // FS#2867, '\s' in php regular expressions may match non-space characters utf8 strings + // this is due to locale setting on the server, which may match bytes '\xA0' and '\x85' + // these two bytes are present in valid multi-byte UTF-8 characters. + // this test will use one, 'ठ' (DEVANAGARI LETTER TTHA, e0 a4 a0). There are many others. + function test_FS2867() { + global $USERINFO; + + setlocale(LC_ALL, "English_United States.1252"); // should only succeed on windows systems + setlocale(LC_ALL, "en_US.UTF-8"); // should succeed on other systems + + $_SERVER['REMOTE_USER'] = 'utfठ8'; + $USERINFO['grps'] = array('utfठ16','utfठa'); + + $acls = <<assertEquals($expect, $this->auth_loadACL_testwrapper($acls)); + } +} + +//Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 0113757259202e06f0316ef4be0f938b134e6e9c Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 25 Oct 2013 14:42:48 +0100 Subject: skip FS#2867 test if \s doesn't match \xA0 after attempting to change the locale --- _test/tests/inc/auth_loadacl.test.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/inc/auth_loadacl.test.php b/_test/tests/inc/auth_loadacl.test.php index 5e7ac3acf..64ab1b9cf 100644 --- a/_test/tests/inc/auth_loadacl.test.php +++ b/_test/tests/inc/auth_loadacl.test.php @@ -2,6 +2,7 @@ /** * auth_loadACL carries out the user & group substitutions * + * @author Chris Smith */ class auth_loadacl_test extends DokuWikiTest { @@ -99,6 +100,11 @@ ACL; setlocale(LC_ALL, "English_United States.1252"); // should only succeed on windows systems setlocale(LC_ALL, "en_US.UTF-8"); // should succeed on other systems + // no point continuing with this test if \s doesn't match A0 + if (!preg_match('/\s/',"\xa0")) { + $this->markTestSkipped('Unable to change locale.'); + } + $_SERVER['REMOTE_USER'] = 'utfठ8'; $USERINFO['grps'] = array('utfठ16','utfठa'); -- cgit v1.2.3 From 30eae85545994c10dcacb2d7becceaf569c99f65 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 25 Oct 2013 15:15:58 +0100 Subject: ensure locale is set back to the original value --- _test/tests/inc/auth_loadacl.test.php | 3 +++ 1 file changed, 3 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/inc/auth_loadacl.test.php b/_test/tests/inc/auth_loadacl.test.php index 64ab1b9cf..e8d9f6696 100644 --- a/_test/tests/inc/auth_loadacl.test.php +++ b/_test/tests/inc/auth_loadacl.test.php @@ -97,11 +97,13 @@ ACL; function test_FS2867() { global $USERINFO; + $old_locale = setlocale(LC_ALL, '0'); setlocale(LC_ALL, "English_United States.1252"); // should only succeed on windows systems setlocale(LC_ALL, "en_US.UTF-8"); // should succeed on other systems // no point continuing with this test if \s doesn't match A0 if (!preg_match('/\s/',"\xa0")) { + setlocale(LC_ALL, $old_locale); $this->markTestSkipped('Unable to change locale.'); } @@ -121,6 +123,7 @@ ACL; "devangariठttha\t@ALL 2", ); $this->assertEquals($expect, $this->auth_loadACL_testwrapper($acls)); + setlocale(LC_ALL, $old_locale); } } -- cgit v1.2.3 From 9269d0b1fb78c217069efd497734c183df9937be Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 29 Oct 2013 20:52:27 +0100 Subject: Fix the media usage index to include local links --- _test/tests/inc/fulltext_mediause.test.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/inc/fulltext_mediause.test.php b/_test/tests/inc/fulltext_mediause.test.php index 9d5b2dc84..503b8bc84 100644 --- a/_test/tests/inc/fulltext_mediause.test.php +++ b/_test/tests/inc/fulltext_mediause.test.php @@ -26,6 +26,13 @@ class fultext_mediause_test extends DokuWikiTest { $this->assertEquals(array('test:medialinks'), ft_mediause('test:example.png')); } + public function test_media_in_local_links() { + saveWikiText('test:locallinks', '[[#test|{{wiki:logolocal.png}}]]', 'Test init'); + idx_addPage('test:locallinks'); + + $this->assertEquals(array('test:locallinks'), ft_mediause('wiki:logolocal.png')); + } + public function test_media_in_footnotes() { saveWikiText('test:media_footnotes', '(({{footnote.png?20x50}} [[foonote|{{:footlink.png}}]]))', 'Test initialization'); idx_addPage('test:media_footnotes'); -- cgit v1.2.3 From 5f5982130c1a9b9adb0e294b811327ddcfbd4fef Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Tue, 5 Nov 2013 20:09:45 +0000 Subject: Improve css_loadfile() tests - use TMP_DIR constant rather than /tmp - swap order of parameters in csstest() to match reported 'expected' & 'actual' - add tests for use of 'url()' in @import - add tests for @import of '.less' files (these test will fail per FS#2875) --- _test/tests/lib/exe/css_css_loadfile.test.php | 33 +++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to '_test/tests') diff --git a/_test/tests/lib/exe/css_css_loadfile.test.php b/_test/tests/lib/exe/css_css_loadfile.test.php index c89b69b2c..0aa27b0af 100644 --- a/_test/tests/lib/exe/css_css_loadfile.test.php +++ b/_test/tests/lib/exe/css_css_loadfile.test.php @@ -3,13 +3,16 @@ require_once DOKU_INC.'lib/exe/css.php'; class css_css_loadfile_test extends DokuWikiTest { + + protected $file = ''; + public function setUp() { - $this->file = tempnam('/tmp', 'css'); + $this->file = tempnam(TMP_DIR, 'css'); } private function csstest($input, $output = null, $location = 'http://www.example.com/') { io_saveFile($this->file, $input); - $this->assertEquals(css_loadfile($this->file, $location), (is_null($output) ? $input : $output)); + $this->assertEquals((is_null($output) ? $input : $output), css_loadfile($this->file, $location)); } public function test_url_relative() { @@ -32,11 +35,15 @@ class css_css_loadfile_test extends DokuWikiTest { public function test_import_relative() { $this->csstest('@import "test/test.png";', '@import "http://www.example.com/test/test.png";'); $this->csstest('@import \'test/test.png\';', '@import \'http://www.example.com/test/test.png\';'); + $this->csstest('@import url(test/test.png);', '@import url(http://www.example.com/test/test.png);'); + $this->csstest('@import url("test/test.png");', '@import url("http://www.example.com/test/test.png");'); } public function test_import_absolute() { $this->csstest('@import "/test/test.png";'); $this->csstest('@import \'/test/test.png\';'); + $this->csstest('@import url(/test/test.png);'); + $this->csstest('@import url("/test/test.png");'); } public function test_import_with_protocol() { @@ -44,6 +51,28 @@ class css_css_loadfile_test extends DokuWikiTest { $this->csstest('@import "https://www.test.com/test/test.png";'); $this->csstest('@import \'http://www.test.com/test/test.png\';'); $this->csstest('@import \'https://www.test.com/test/test.png\';'); + $this->csstest('@import url(http://www.test.com/test/test.png);'); + $this->csstest('@import url("http://www.test.com/test/test.png");'); + } + + public function test_less_basic() { + $this->csstest('@import "test.less"', '@import "/test.less"'); + $this->csstest('@import "/test.less"', '@import "/test.less"'); + $this->csstest('@import url(http://test.less)'); + } + + // more expected use, where less @import(ed) from e.g. lib/plugins/plugin_name + public function test_less_subdirectories() { + + unlink($this->file); + + $dir = TMP_DIR.'/foo/bar'; + mkdir($dir,0777,true); + $this->file = tempnam($dir, 'css'); + + $this->csstest('@import "test.less"', '@import "/foo/bar/test.less"'); + $this->csstest('@import \'test.less\'', '@import \'/foo/bar/test.less\''); + $this->csstest('@import url(test.less)', '@import url(/foo/bar/test.less)'); } public function tearDown() { -- cgit v1.2.3 From 6d7e4640bed01599dac4bbf5c00b0aff8d3dd4ba Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Tue, 5 Nov 2013 20:49:53 +0000 Subject: additional tests where for relative path to @import less file --- _test/tests/lib/exe/css_css_loadfile.test.php | 3 +++ 1 file changed, 3 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/lib/exe/css_css_loadfile.test.php b/_test/tests/lib/exe/css_css_loadfile.test.php index 0aa27b0af..c336702f8 100644 --- a/_test/tests/lib/exe/css_css_loadfile.test.php +++ b/_test/tests/lib/exe/css_css_loadfile.test.php @@ -58,6 +58,7 @@ class css_css_loadfile_test extends DokuWikiTest { public function test_less_basic() { $this->csstest('@import "test.less"', '@import "/test.less"'); $this->csstest('@import "/test.less"', '@import "/test.less"'); + $this->csstest('@import "foo/test.less"', '@import "/foo/test.less"'); $this->csstest('@import url(http://test.less)'); } @@ -73,6 +74,8 @@ class css_css_loadfile_test extends DokuWikiTest { $this->csstest('@import "test.less"', '@import "/foo/bar/test.less"'); $this->csstest('@import \'test.less\'', '@import \'/foo/bar/test.less\''); $this->csstest('@import url(test.less)', '@import url(/foo/bar/test.less)'); + + $this->csstest('@import "abc/test.less"', '@import "/foo/bar/abc/test.less"'); } public function tearDown() { -- cgit v1.2.3 From ab1fef6644927b857c64c9c153915d50ef2607f1 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Tue, 5 Nov 2013 20:51:07 +0000 Subject: Test to ensure less can parse the @import rewritten by css_loadfile() This test is horrible, but I believe necessary to ensure that the @import of less files actually works. It is horrible as its not a unit test and its not a true functional test. It probably implies the code in css_out() should be refactored to make it easier to test intermediate results. --- _test/tests/lib/exe/css_at_import_less.test.php | 78 +++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 _test/tests/lib/exe/css_at_import_less.test.php (limited to '_test/tests') diff --git a/_test/tests/lib/exe/css_at_import_less.test.php b/_test/tests/lib/exe/css_at_import_less.test.php new file mode 100644 index 000000000..4a6efcf44 --- /dev/null +++ b/_test/tests/lib/exe/css_at_import_less.test.php @@ -0,0 +1,78 @@ +markTestSkipped('Could not create directory.'); + } + + $this->file = tempnam($dir, 'css'); + + $import = ''; + do { + if ($import) unlink($import); + $import = tempnam($dir, 'less'); + $ok = rename($import, $import.'.less'); + } while (!$ok); + + $this->import = $import.'.less'; + } + + private function csstest($input, $expected_css, $expected_less) { + $location = "http://test.com/"; + io_saveFile($this->file, $input); + $css = css_loadfile($this->file, $location); + $less = css_parseless($css); + $this->assertEquals($expected_css, $css); + $this->assertEquals($expected_less, $less); + } + + public function test_basic() { + $this->setUpFiles(); + + $import = preg_replace('#(^.*[/])#','',$this->import); + $in_css = '@import "'.$import.'";'; + $in_less = '@foo: "bar"; +content: @foo;'; + + $expected_css = '@import "/'.$import.'";'; + $expected_less = 'content: "bar";'; + + io_saveFile($this->import, $in_less); + $this->csstest($in_css, $expected_css, $expected_less); + } + + public function test_subdirectory() { + $this->setUpFiles('/foo/bar'); + + $import = preg_replace('#(^.*[/])#','',$this->import); + $in_css = '@import "'.$import.'";'; + $in_less = '@foo: "bar"; +content: @foo;'; + + $expected_css = '@import "/foo/bar/'.$import.'";'; + $expected_less = 'content: "bar";'; + + io_saveFile($this->import, $in_less); + $this->csstest($in_css, $expected_css, $expected_less); + } + + public function tearDown() { + unlink($this->file); + unlink($this->import); + unset($this->file, $this->import); + } +} + +//Setup VIM: ex: et ts=4 sw=4 : -- cgit v1.2.3 From 28ad2ce3c7b348afcc1efbae4fc64a7ea31585ee Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 17 Nov 2013 21:18:25 +0000 Subject: ensure css loadfile test doesn't try to create a directory (and fail) if the directory already exists --- _test/tests/lib/exe/css_css_loadfile.test.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to '_test/tests') diff --git a/_test/tests/lib/exe/css_css_loadfile.test.php b/_test/tests/lib/exe/css_css_loadfile.test.php index c336702f8..624becd29 100644 --- a/_test/tests/lib/exe/css_css_loadfile.test.php +++ b/_test/tests/lib/exe/css_css_loadfile.test.php @@ -68,7 +68,13 @@ class css_css_loadfile_test extends DokuWikiTest { unlink($this->file); $dir = TMP_DIR.'/foo/bar'; - mkdir($dir,0777,true); + if (!is_dir($dir)) { + mkdir($dir, 0777, true); + } + if (!is_dir($dir)) { + $this->markTestSkipped('Could not create directory.'); + } + $this->file = tempnam($dir, 'css'); $this->csstest('@import "test.less"', '@import "/foo/bar/test.less"'); -- cgit v1.2.3 From 5a41afe6e3b958291893a0a10105cd41971fb141 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 1 Dec 2013 17:57:03 +0000 Subject: FS#1833 (b) Prevent table entry syntax swallowing multiple preceeding blank lines (a) this shouldn't be necessary, blank lines are handled by paragraph processing (b) avoids issues with greedy table syntax competing with plugins --- _test/tests/inc/parser/parser_table.test.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to '_test/tests') 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); + } + } -- cgit v1.2.3 From 6be717dbb579e1cc7e2fbb82d7ddade3e5892c47 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sun, 1 Dec 2013 21:25:29 +0100 Subject: Fix sending empty and duplicated headers, FS#2887 This fixes sending empty and duplicated To/Cc/Bcc, Subject and From headers in the additional headers. The To-header in the additional headers prevented mail sending on some systems. --- _test/tests/inc/mailer.test.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to '_test/tests') diff --git a/_test/tests/inc/mailer.test.php b/_test/tests/inc/mailer.test.php index bac0c39ba..4541d9906 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.'); } /** -- cgit v1.2.3 From ccfec5606dae81e6524f6cfcdaca09d4cde7f111 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sat, 7 Dec 2013 23:10:05 +0000 Subject: crlf 2 lf whitespace fixes --- _test/tests/inc/common_basicinfo.test.php | 10 ++--- _test/tests/inc/common_mediainfo.test.php | 10 ++--- _test/tests/inc/common_pageinfo.test.php | 66 +++++++++++++++---------------- _test/tests/test/basic.test.php | 12 +++--- 4 files changed, 49 insertions(+), 49 deletions(-) (limited to '_test/tests') 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/test/basic.test.php b/_test/tests/test/basic.test.php index 05778ccf9..86acef935 100644 --- a/_test/tests/test/basic.test.php +++ b/_test/tests/test/basic.test.php @@ -123,11 +123,11 @@ class InttestsBasicTest extends DokuWikiTest { $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(){ -- cgit v1.2.3 From 5a1d05488ca6e176af4d195accbdca8010cf3416 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Wed, 11 Dec 2013 23:02:17 +0100 Subject: Fix indexing numeric words in page contents Since a8dba4523d2ecd09dd69a68a36673eaf5c009c57 the search index didn't properly index numeric words anymore, instead they were added as new words to the word list each time they were indexed, leading to an ever-increasing index size. --- _test/tests/inc/indexer_indexing.test.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to '_test/tests') 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 -- cgit v1.2.3 From ebec603febbe7426fbb12cbb4fd3cb42128fcbf8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 6 Jan 2014 20:58:38 +0100 Subject: added tests for io_rmdir --- _test/tests/inc/io_rmdir.test.php | 159 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 _test/tests/inc/io_rmdir.test.php (limited to '_test/tests') diff --git a/_test/tests/inc/io_rmdir.test.php b/_test/tests/inc/io_rmdir.test.php new file mode 100644 index 000000000..9a122d111 --- /dev/null +++ b/_test/tests/inc/io_rmdir.test.php @@ -0,0 +1,159 @@ +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 -- cgit v1.2.3 From d8cf4dd43ecd37c371acf9bc6c17998b65d42ba4 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 6 Jan 2014 21:15:50 +0100 Subject: treat non-existing files as success on delete --- _test/tests/inc/io_rmdir.test.php | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to '_test/tests') diff --git a/_test/tests/inc/io_rmdir.test.php b/_test/tests/inc/io_rmdir.test.php index 9a122d111..3de57fa86 100644 --- a/_test/tests/inc/io_rmdir.test.php +++ b/_test/tests/inc/io_rmdir.test.php @@ -2,6 +2,66 @@ 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 -- cgit v1.2.3 From 05f1af55e0303f33fa6f046eeaa221f1b2a32066 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 24 Jan 2014 17:50:40 +0100 Subject: add unit test to check language files for validity this should help with applying pull requests that do come not from the translation interface as it makes sure the files will be at least syntactically correct. --- _test/tests/general/general_languagelint.php | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 _test/tests/general/general_languagelint.php (limited to '_test/tests') 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 @@ +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) != '') + throw new Exception("$file ends with '?>' - remove it!"); + } + +} -- cgit v1.2.3 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/tests/test/basic.test.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to '_test/tests') 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/tests') 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/tests') 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/tests') 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/tests') 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/tests') 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/tests') 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/tests') 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/tests') 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