From 369075828e13e37a65a2f8062a74e89f98dd3fac Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Wed, 6 May 2015 18:21:17 -0400 Subject: Append to BZip2 files. Unit tests for writing files. --- _test/tests/inc/io_deletefromfile.test.php | 42 +++++++++++++++++++++++++ _test/tests/inc/io_savefile.test.php | 49 ++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 _test/tests/inc/io_deletefromfile.test.php create mode 100644 _test/tests/inc/io_savefile.test.php (limited to '_test') diff --git a/_test/tests/inc/io_deletefromfile.test.php b/_test/tests/inc/io_deletefromfile.test.php new file mode 100644 index 000000000..361c82214 --- /dev/null +++ b/_test/tests/inc/io_deletefromfile.test.php @@ -0,0 +1,42 @@ +markTestSkipped('skipping all zlib tests. Need zlib extension'); + } + } + + /* + * dependency for tests needing zlib extension to pass + */ + public function test_ext_bz2() { + if (!extension_loaded('bz2')) { + $this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension'); + } + } + + function _write($file){ + $contents = "The\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012"; + io_saveFile($file, $contents); + $this->assertTrue(io_deleteFromFile($file, "Delete\012")); + $this->assertEquals("The\012Delete01\012Delete02\012DeleteX\012Test\012", io_readFile($file)); + $this->assertTrue(io_deleteFromFile($file, "#Delete\\d+\012#", true)); + $this->assertEquals("The\012DeleteX\012Test\012", io_readFile($file)); + } + + function test_delete(){ + $this->_write(TMP_DIR.'/test.txt'); + } + +// /** +// * @depends test_ext_zlib +// */ +// function test_gzwrite(){ +// } + +} diff --git a/_test/tests/inc/io_savefile.test.php b/_test/tests/inc/io_savefile.test.php new file mode 100644 index 000000000..4a4d4671d --- /dev/null +++ b/_test/tests/inc/io_savefile.test.php @@ -0,0 +1,49 @@ +markTestSkipped('skipping all zlib tests. Need zlib extension'); + } + } + + /* + * dependency for tests needing zlib extension to pass + */ + public function test_ext_bz2() { + if (!extension_loaded('bz2')) { + $this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension'); + } + } + + function _write($file){ + $contents = "The\012Write\012Test\012"; + $this->assertTrue(io_saveFile($file, $contents)); + $this->assertEquals($contents, io_readFile($file)); + $this->assertTrue(io_saveFile($file, $contents, true)); + $this->assertEquals($contents.$contents, io_readFile($file)); + } + + function test_write(){ + $this->_write(TMP_DIR.'/test.txt'); + } + + /** + * @depends test_ext_zlib + */ + function test_gzwrite(){ + $this->_write(TMP_DIR.'/test.txt.gz'); + } + + /** + * @depends test_ext_bz2 + */ + function test_bzwrite(){ + $this->_write(TMP_DIR.'/test.txt.bz2'); + } + +} -- cgit v1.2.3 From cfb71e37ca8859c4ad9a1db73de0a293ffc7a902 Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Wed, 6 May 2015 23:31:39 -0400 Subject: Deleting lines works with BZ2 files. --- _test/tests/inc/io_deletefromfile.test.php | 18 +++++++++++++----- _test/tests/inc/io_readfile.test.php | 7 ++++++- _test/tests/inc/io_readfile/large.txt.bz2 | Bin 0 -> 47 bytes _test/tests/inc/io_readfile/long.txt.bz2 | Bin 0 -> 53 bytes 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 _test/tests/inc/io_readfile/large.txt.bz2 create mode 100644 _test/tests/inc/io_readfile/long.txt.bz2 (limited to '_test') diff --git a/_test/tests/inc/io_deletefromfile.test.php b/_test/tests/inc/io_deletefromfile.test.php index 361c82214..63951f548 100644 --- a/_test/tests/inc/io_deletefromfile.test.php +++ b/_test/tests/inc/io_deletefromfile.test.php @@ -33,10 +33,18 @@ class io_deletefromfile_test extends DokuWikiTest { $this->_write(TMP_DIR.'/test.txt'); } -// /** -// * @depends test_ext_zlib -// */ -// function test_gzwrite(){ -// } + /** + * @depends test_ext_zlib + */ + function test_gzwrite(){ + $this->_write(TMP_DIR.'/test.txt.gz'); + } + + /** + * @depends test_ext_bz2 + */ + function test_bzwrite(){ + $this->_write(TMP_DIR.'/test.txt.bz2'); + } } diff --git a/_test/tests/inc/io_readfile.test.php b/_test/tests/inc/io_readfile.test.php index e3e90cd8d..700c1902b 100644 --- a/_test/tests/inc/io_readfile.test.php +++ b/_test/tests/inc/io_readfile.test.php @@ -48,6 +48,11 @@ class io_readfile_test extends DokuWikiTest { $this->assertEquals("The\015\012Test\015\012", io_readFile(__DIR__.'/io_readfile/test.txt.bz2', false)); $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt.bz2')); $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/corrupt.txt.bz2')); + // internal bzfile function + $this->assertEquals(array("The\015\012","Test\015\012"), bzfile(__DIR__.'/io_readfile/test.txt.bz2', true)); + $this->assertEquals(array_fill(0, 120, str_repeat('a', 80)."\012"), bzfile(__DIR__.'/io_readfile/large.txt.bz2', true)); + $line = str_repeat('a', 8888)."\012"; + $this->assertEquals(array($line,"\012",$line,"!"), bzfile(__DIR__.'/io_readfile/long.txt.bz2', true)); } -} \ No newline at end of file +} diff --git a/_test/tests/inc/io_readfile/large.txt.bz2 b/_test/tests/inc/io_readfile/large.txt.bz2 new file mode 100644 index 000000000..3135435f8 Binary files /dev/null and b/_test/tests/inc/io_readfile/large.txt.bz2 differ diff --git a/_test/tests/inc/io_readfile/long.txt.bz2 b/_test/tests/inc/io_readfile/long.txt.bz2 new file mode 100644 index 000000000..fb40759e6 Binary files /dev/null and b/_test/tests/inc/io_readfile/long.txt.bz2 differ -- cgit v1.2.3 From 6c0002048504e43b399abece0668afa2b5c87a07 Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Fri, 8 May 2015 17:11:44 -0400 Subject: Limit number of lines to replace. --- _test/tests/inc/io_replaceinfile.test.php | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 _test/tests/inc/io_replaceinfile.test.php (limited to '_test') diff --git a/_test/tests/inc/io_replaceinfile.test.php b/_test/tests/inc/io_replaceinfile.test.php new file mode 100644 index 000000000..98f21868f --- /dev/null +++ b/_test/tests/inc/io_replaceinfile.test.php @@ -0,0 +1,58 @@ +markTestSkipped('skipping all zlib tests. Need zlib extension'); + } + } + + /* + * dependency for tests needing zlib extension to pass + */ + public function test_ext_bz2() { + if (!extension_loaded('bz2')) { + $this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension'); + } + } + + function _write($file){ + $contents = "The\012Delete\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012"; + io_saveFile($file, $contents); + // Replace one, no regex + $this->assertTrue(io_replaceInFile($file, "Delete\012", "Delete00\012", false, 1)); + $this->assertEquals("The\012Delete00\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012", io_readFile($file)); + // Replace all, no regex + $this->assertTrue(io_replaceInFile($file, "Delete\012", "DeleteX\012", false, -1)); + $this->assertEquals("The\012Delete00\012DeleteX\012Delete01\012Delete02\012DeleteX\012DeleteX\012Test\012", io_readFile($file)); + // Replace two, regex and backreference + $this->assertTrue(io_replaceInFile($file, "#Delete(\\d+)\012#", "\\1\012", true, 2)); + $this->assertEquals("The\01200\012DeleteX\01201\012Delete02\012DeleteX\012DeleteX\012Test\012", io_readFile($file)); + // Delete and insert, no regex + $this->assertTrue(io_replaceInFile($file, "DeleteX\012", "Replace\012", false, 0)); + $this->assertEquals("The\01200\01201\012Delete02\012Test\012Replace\012", io_readFile($file)); + } + + function test_replace(){ + $this->_write(TMP_DIR.'/test.txt'); + } + + /** + * @depends test_ext_zlib + */ + function test_gzwrite(){ + $this->_write(TMP_DIR.'/test.txt.gz'); + } + + /** + * @depends test_ext_bz2 + */ + function test_bzwrite(){ + $this->_write(TMP_DIR.'/test.txt.bz2'); + } + +} -- cgit v1.2.3 From 0c26fb18171bc6264c1b0b2dbdfddc34de5d579e Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Fri, 8 May 2015 17:13:32 -0400 Subject: Don't run redundant tests io_deleteFromFile is a special case of io_replaceInFile. Since the io_replace tests check compressed files, it doesn't have to be done in the io_delete test. --- _test/tests/inc/io_deletefromfile.test.php | 39 ++---------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/io_deletefromfile.test.php b/_test/tests/inc/io_deletefromfile.test.php index 63951f548..e86150aac 100644 --- a/_test/tests/inc/io_deletefromfile.test.php +++ b/_test/tests/inc/io_deletefromfile.test.php @@ -2,25 +2,8 @@ class io_deletefromfile_test extends DokuWikiTest { - /* - * dependency for tests needing zlib extension to pass - */ - public function test_ext_zlib() { - if (!extension_loaded('zlib')) { - $this->markTestSkipped('skipping all zlib tests. Need zlib extension'); - } - } - - /* - * dependency for tests needing zlib extension to pass - */ - public function test_ext_bz2() { - if (!extension_loaded('bz2')) { - $this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension'); - } - } - - function _write($file){ + function test_delete(){ + $file = TMP_DIR.'/test.txt'; $contents = "The\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012"; io_saveFile($file, $contents); $this->assertTrue(io_deleteFromFile($file, "Delete\012")); @@ -29,22 +12,4 @@ class io_deletefromfile_test extends DokuWikiTest { $this->assertEquals("The\012DeleteX\012Test\012", io_readFile($file)); } - function test_delete(){ - $this->_write(TMP_DIR.'/test.txt'); - } - - /** - * @depends test_ext_zlib - */ - function test_gzwrite(){ - $this->_write(TMP_DIR.'/test.txt.gz'); - } - - /** - * @depends test_ext_bz2 - */ - function test_bzwrite(){ - $this->_write(TMP_DIR.'/test.txt.bz2'); - } - } -- cgit v1.2.3 From 9a734b7aaba1445e06c1ccb95e59f54e01688d45 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 28 May 2015 16:37:32 +0100 Subject: Refactor code to make it simpler. The changes should also: - fix unlikely edge case when replacement line is the same as the old line (would have resulted in timeout) - reduce memory footprint - avoid applying string search beyond maxlines replacement limit --- _test/tests/inc/io_replaceinfile.test.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/io_replaceinfile.test.php b/_test/tests/inc/io_replaceinfile.test.php index 98f21868f..c2dbc0dd4 100644 --- a/_test/tests/inc/io_replaceinfile.test.php +++ b/_test/tests/inc/io_replaceinfile.test.php @@ -2,6 +2,8 @@ class io_replaceinfile_test extends DokuWikiTest { + protected $contents = "The\012Delete\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012"; + /* * dependency for tests needing zlib extension to pass */ @@ -21,8 +23,8 @@ class io_replaceinfile_test extends DokuWikiTest { } function _write($file){ - $contents = "The\012Delete\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012"; - io_saveFile($file, $contents); + + io_saveFile($file, $this->contents); // Replace one, no regex $this->assertTrue(io_replaceInFile($file, "Delete\012", "Delete00\012", false, 1)); $this->assertEquals("The\012Delete00\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012", io_readFile($file)); @@ -41,6 +43,7 @@ class io_replaceinfile_test extends DokuWikiTest { $this->_write(TMP_DIR.'/test.txt'); } + /** * @depends test_ext_zlib */ @@ -55,4 +58,25 @@ class io_replaceinfile_test extends DokuWikiTest { $this->_write(TMP_DIR.'/test.txt.bz2'); } + /** + * + */ + function test_edgecase1() + { + $file = TMP_DIR . '/test.txt'; + // Replace all, no regex, backreference like construct in replacement line + io_saveFile($file, $this->contents); + $this->assertTrue(io_replaceInFile($file, "Delete\012", "Delete\\00\012", false, -1)); + $this->assertEquals("The\012Delete\\00\012Delete\\00\012Delete01\012Delete02\012Delete\\00\012DeleteX\012Test\012", io_readFile($file), "Edge case: backreference like construct in replacement line"); + } + /** + * @small + */ + function test_edgecase2() { + $file = TMP_DIR.'/test.txt'; + // Replace all, no regex, replacement line == search line + io_saveFile($file, $this->contents); + $this->assertTrue(io_replaceInFile($file, "Delete\012", "Delete\012", false, -1)); + $this->assertEquals("The\012Delete\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012", io_readFile($file), "Edge case: new line the same as old line"); + } } -- cgit v1.2.3 From 3dfe7d64760baa568018c1d6d311c26d1a2da098 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 29 May 2015 16:52:05 +0100 Subject: add anchors when constructing pattern from a non-regex oldline --- _test/tests/inc/io_replaceinfile.test.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/io_replaceinfile.test.php b/_test/tests/inc/io_replaceinfile.test.php index c2dbc0dd4..de7301fa1 100644 --- a/_test/tests/inc/io_replaceinfile.test.php +++ b/_test/tests/inc/io_replaceinfile.test.php @@ -79,4 +79,17 @@ class io_replaceinfile_test extends DokuWikiTest { $this->assertTrue(io_replaceInFile($file, "Delete\012", "Delete\012", false, -1)); $this->assertEquals("The\012Delete\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012", io_readFile($file), "Edge case: new line the same as old line"); } + + /** + * + */ + function test_edgecase3() + { + $file = TMP_DIR . '/test.txt'; + $contents = "The\012Delete\01201Delete\01202Delete\012Test\012"; + // Replace all, no regex, oldline exactly matches one line; matches part of other lines - only the exact match should be replaced + io_saveFile($file, $contents); + $this->assertTrue(io_replaceInFile($file, "Delete\012", "Replace\012", false, -1)); + $this->assertEquals("The\012Replace\01201Delete\01202Delete\012Test\012", io_readFile($file), "Edge case: old line is a match for parts of other lines"); + } } -- cgit v1.2.3 From e12c5ac781d560502d478775502df70cd80472de Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 29 May 2015 16:55:23 +0100 Subject: Minor Refactoring - put test comments in more appropriate spot - move appending replacement line alongside its search/delete code --- _test/tests/inc/io_replaceinfile.test.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/io_replaceinfile.test.php b/_test/tests/inc/io_replaceinfile.test.php index de7301fa1..597138a20 100644 --- a/_test/tests/inc/io_replaceinfile.test.php +++ b/_test/tests/inc/io_replaceinfile.test.php @@ -59,35 +59,37 @@ class io_replaceinfile_test extends DokuWikiTest { } /** - * + * Test for a non-regex replacement where $newline contains a backreference like construct - it shouldn't affect the replacement */ function test_edgecase1() { $file = TMP_DIR . '/test.txt'; - // Replace all, no regex, backreference like construct in replacement line + io_saveFile($file, $this->contents); $this->assertTrue(io_replaceInFile($file, "Delete\012", "Delete\\00\012", false, -1)); $this->assertEquals("The\012Delete\\00\012Delete\\00\012Delete01\012Delete02\012Delete\\00\012DeleteX\012Test\012", io_readFile($file), "Edge case: backreference like construct in replacement line"); } /** + * Test with replace all where replacement line == search line - must not timeout + * * @small */ function test_edgecase2() { $file = TMP_DIR.'/test.txt'; - // Replace all, no regex, replacement line == search line + io_saveFile($file, $this->contents); $this->assertTrue(io_replaceInFile($file, "Delete\012", "Delete\012", false, -1)); $this->assertEquals("The\012Delete\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012", io_readFile($file), "Edge case: new line the same as old line"); } /** - * + * Test where $oldline exactly matches one line and also matches part of other lines - only the exact match should be replaced */ function test_edgecase3() { $file = TMP_DIR . '/test.txt'; $contents = "The\012Delete\01201Delete\01202Delete\012Test\012"; - // Replace all, no regex, oldline exactly matches one line; matches part of other lines - only the exact match should be replaced + io_saveFile($file, $contents); $this->assertTrue(io_replaceInFile($file, "Delete\012", "Replace\012", false, -1)); $this->assertEquals("The\012Replace\01201Delete\01202Delete\012Test\012", io_readFile($file), "Edge case: old line is a match for parts of other lines"); -- cgit v1.2.3 From dc4a4eb00d67d7d28fae137437900220920577d4 Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Fri, 29 May 2015 15:38:43 -0400 Subject: Abort io_replaceInLine when the search parameter is empty --- _test/tests/inc/io_replaceinfile.test.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/io_replaceinfile.test.php b/_test/tests/inc/io_replaceinfile.test.php index 597138a20..452ed7401 100644 --- a/_test/tests/inc/io_replaceinfile.test.php +++ b/_test/tests/inc/io_replaceinfile.test.php @@ -94,4 +94,15 @@ class io_replaceinfile_test extends DokuWikiTest { $this->assertTrue(io_replaceInFile($file, "Delete\012", "Replace\012", false, -1)); $this->assertEquals("The\012Replace\01201Delete\01202Delete\012Test\012", io_readFile($file), "Edge case: old line is a match for parts of other lines"); } + + /** + * Test passing an invalid parameter. + * + * @expectedException PHPUnit_Framework_Error_Warning + */ + function test_badparam() + { + /* The empty $oldline parameter should be caught before the file doesn't exist test. */ + $this->assertFalse(io_replaceInFile(TMP_DIR.'/not_existing_file.txt', '', '', false, 0)); + } } -- cgit v1.2.3 From 4d1366e45cecd27c337b0a8d606cfcde58f9ac8c Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Tue, 30 Jun 2015 23:55:08 +0200 Subject: Use a DateTime object in the IXR_Date --- _test/tests/inc/ixr_library_date.test.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/ixr_library_date.test.php b/_test/tests/inc/ixr_library_date.test.php index f38486925..fd5711212 100644 --- a/_test/tests/inc/ixr_library_date.test.php +++ b/_test/tests/inc/ixr_library_date.test.php @@ -16,12 +16,18 @@ class ixr_library_date_test extends DokuWikiTest { array('2010-08-17T09:23:14Z', 1282036994), array('20100817T09:23:14Z', 1282036994), + // with timezone + array('2010-08-17 09:23:14+0000', 1282036994), + array('2010-08-17 09:23:14+00:00', 1282036994), + array('2010-08-17 09:23:14+03:00', 1282036994), + // no seconds array('2010-08-17T09:23', 1282036980), array('20100817T09:23', 1282036980), // no time array('2010-08-17', 1282003200), + array(1282036980, 1282036980), //array('20100817', 1282003200), #this will NOT be parsed, but is assumed to be timestamp ); -- cgit v1.2.3 From ec3b241dc4541d05f30c9ee696bc5117fbe88007 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Jul 2015 00:04:34 +0200 Subject: improve IXR_Date unittests --- _test/tests/inc/ixr_library_date.test.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/ixr_library_date.test.php b/_test/tests/inc/ixr_library_date.test.php index fd5711212..0c81e6741 100644 --- a/_test/tests/inc/ixr_library_date.test.php +++ b/_test/tests/inc/ixr_library_date.test.php @@ -2,6 +2,9 @@ require_once DOKU_INC.'inc/IXR_Library.php'; +/** + * Class ixr_library_date_test + */ class ixr_library_date_test extends DokuWikiTest { @@ -19,7 +22,7 @@ class ixr_library_date_test extends DokuWikiTest { // with timezone array('2010-08-17 09:23:14+0000', 1282036994), array('2010-08-17 09:23:14+00:00', 1282036994), - array('2010-08-17 09:23:14+03:00', 1282036994), + array('2010-08-17 12:23:14+03:00', 1282036994), // no seconds array('2010-08-17T09:23', 1282036980), @@ -28,12 +31,12 @@ class ixr_library_date_test extends DokuWikiTest { // no time array('2010-08-17', 1282003200), array(1282036980, 1282036980), - //array('20100817', 1282003200), #this will NOT be parsed, but is assumed to be timestamp +// array('20100817', 1282003200), #this will NOT be parsed, but is assumed to be timestamp ); foreach($tests as $test){ $dt = new IXR_Date($test[0]); - $this->assertEquals($dt->getTimeStamp(),$test[1]); + $this->assertEquals($test[1], $dt->getTimeStamp()); } } -- cgit v1.2.3 From ae614416a5d7f5cab6c5b82a0c45f587d7fa9c01 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sun, 12 Jul 2015 19:05:43 +0100 Subject: changed all input type=submit buttons to button type=submit button for better stylability --- _test/tests/inc/form_form.test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/form_form.test.php b/_test/tests/inc/form_form.test.php index 02242a807..7f168b895 100644 --- a/_test/tests/inc/form_form.test.php +++ b/_test/tests/inc/form_form.test.php @@ -30,9 +30,9 @@ class form_test extends DokuWikiTest { $realoutput .= ' '; $realoutput .= 'Check'; $realoutput .= "\n"; - $realoutput .= ''; + $realoutput .= ''; $realoutput .= "\n"; - $realoutput .= ''; + $realoutput .= ''; $realoutput .= "\n"; $realoutput .= "\n\n"; return $realoutput; -- cgit v1.2.3 From ccee93d9d1aa20ccc91f9277983d7fa2ee34f7f9 Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Thu, 16 Jul 2015 02:50:41 -0400 Subject: Unit test for interwiki URL encoding bug --- .../inc/parser/renderer_resolveinterwiki.test.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php index dd1ed1d3f..9cc3443eb 100644 --- a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php +++ b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php @@ -17,18 +17,18 @@ class Test_resolveInterwiki extends DokuWikiTest { $tests = array( // shortcut, reference and expected - array('wp', 'foo @+%/#txt', 'http://en.wikipedia.org/wiki/foo @+%/#txt'), - array('amazon', 'foo @+%/#txt', 'http://www.amazon.com/exec/obidos/ASIN/foo%20%40%2B%25%2F/splitbrain-20/#txt'), - array('doku', 'foo @+%/#txt', 'http://www.dokuwiki.org/foo%20%40%2B%25%2F#txt'), - array('coral', 'http://example.com:83/path/naar/?query=foo%20%40%2B%25%2F', 'http://example.com.83.nyud.net:8090/path/naar/?query=foo%20%40%2B%25%2F'), + array('wp', 'foo [\\]^`{|}~@+#%?/#txt', 'https://en.wikipedia.org/wiki/foo %7E%5B%5C%5D%5E%60%7B%7C%7D%7E@+%23%25%3F/#txt'), + array('amazon', 'foo [\\]^`{|}~@+#%?/#txt', 'https://www.amazon.com/exec/obidos/ASIN/foo%20%7E%5B%5C%5D%5E%60%7B%7C%7D%7E%40%2B%23%25%3F%2F/splitbrain-20/#txt'), + array('doku', 'foo [\\]^`{|}~@+#%?/#txt', 'https://www.dokuwiki.org/foo%20%7E%5B%5C%5D%5E%60%7B%7C%7D%7E%40%2B%23%25%3F%2F#txt'), + array('coral', 'http://example.com:83/path/naar/?query=foo%20%40%2B%25%3F%2F', 'http://example.com.83.nyud.net:8090/path/naar/?query=foo%20%40%2B%25%3F%2F'), array('scheme', 'ftp://foo @+%/#txt', 'ftp://example.com#txt'), //relative url - array('withslash', 'foo @+%/#txt', '/testfoo%20%40%2B%25%2F#txt'), - array('skype', 'foo @+%/#txt', 'skype:foo @+%/#txt'), + array('withslash', 'foo [\\]^`{|}~@+#%?/#txt', '/testfoo%20%7E%5B%5C%5D%5E%60%7B%7C%7D%7E%40%2B%23%25%3F%2F#txt'), + array('skype', 'foo [\\]^`{|}~@+#%?/#txt', 'skype:foo %7E%5B%5C%5D%5E%60%7B%7C%7D%7E@+%23%25?/#txt'), //dokuwiki id's - array('onlytext', 'foo @+%#txt', DOKU_BASE.'doku.php?id=onlytextfoo#txt'), - array('user', 'foo @+%#txt', DOKU_BASE.'doku.php?id=user:foo#txt'), - array('withquery', 'foo @+%#txt', DOKU_BASE.'doku.php?id=anyns:foo&do=edit#txt') + array('onlytext', 'foo [\\]^`{|}~@+#%?/#txt', DOKU_BASE.'doku.php?id=onlytextfoo#txt'), + array('user', 'foo [\\]^`{|}~@+#%?/#txt', DOKU_BASE.'doku.php?id=user:foo#txt'), + array('withquery', 'foo [\\]^`{|}~@+#%?/#txt', DOKU_BASE.'doku.php?id=anyns:foo&do=edit#txt') ); foreach($tests as $test) { @@ -45,7 +45,7 @@ class Test_resolveInterwiki extends DokuWikiTest { $shortcut = 'nonexisting'; $reference = 'foo @+%/'; $url = $Renderer->_resolveInterWiki($shortcut, $reference); - $expected = 'http://www.google.com/search?q=foo%20%40%2B%25%2F&btnI=lucky'; + $expected = 'https://www.google.com/search?q=foo%20%40%2B%25%2F&btnI=lucky'; $this->assertEquals($expected, $url); } -- cgit v1.2.3 From 17e17ae257649aef67c693d01e8992ece86eabd2 Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Thu, 16 Jul 2015 12:35:56 -0400 Subject: Encode unsafe characters in interwiki links. closes #1220 --- .../tests/inc/parser/renderer_resolveinterwiki.test.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php index 9cc3443eb..8379bc065 100644 --- a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php +++ b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php @@ -17,18 +17,18 @@ class Test_resolveInterwiki extends DokuWikiTest { $tests = array( // shortcut, reference and expected - array('wp', 'foo [\\]^`{|}~@+#%?/#txt', 'https://en.wikipedia.org/wiki/foo %7E%5B%5C%5D%5E%60%7B%7C%7D%7E@+%23%25%3F/#txt'), - array('amazon', 'foo [\\]^`{|}~@+#%?/#txt', 'https://www.amazon.com/exec/obidos/ASIN/foo%20%7E%5B%5C%5D%5E%60%7B%7C%7D%7E%40%2B%23%25%3F%2F/splitbrain-20/#txt'), - array('doku', 'foo [\\]^`{|}~@+#%?/#txt', 'https://www.dokuwiki.org/foo%20%7E%5B%5C%5D%5E%60%7B%7C%7D%7E%40%2B%23%25%3F%2F#txt'), + array('wp', 'foo [\\]^`{|}~@+#%?/#txt', 'https://en.wikipedia.org/wiki/foo %5B%5C%5D%5E%60%7B%7C%7D~@+%23%25?/#txt'), + array('amazon', 'foo [\\]^`{|}~@+#%?/#txt', 'https://www.amazon.com/exec/obidos/ASIN/foo%20%5B%5C%5D%5E%60%7B%7C%7D~%40%2B%23%25%3F%2F/splitbrain-20/#txt'), + array('doku', 'foo [\\]^`{|}~@+#%?/#txt', 'https://www.dokuwiki.org/foo%20%5B%5C%5D%5E%60%7B%7C%7D~%40%2B%23%25%3F%2F#txt'), array('coral', 'http://example.com:83/path/naar/?query=foo%20%40%2B%25%3F%2F', 'http://example.com.83.nyud.net:8090/path/naar/?query=foo%20%40%2B%25%3F%2F'), array('scheme', 'ftp://foo @+%/#txt', 'ftp://example.com#txt'), //relative url - array('withslash', 'foo [\\]^`{|}~@+#%?/#txt', '/testfoo%20%7E%5B%5C%5D%5E%60%7B%7C%7D%7E%40%2B%23%25%3F%2F#txt'), - array('skype', 'foo [\\]^`{|}~@+#%?/#txt', 'skype:foo %7E%5B%5C%5D%5E%60%7B%7C%7D%7E@+%23%25?/#txt'), + array('withslash', 'foo [\\]^`{|}~@+#%?/#txt', '/testfoo%20%5B%5C%5D%5E%60%7B%7C%7D~%40%2B%23%25%3F%2F#txt'), + array('skype', 'foo [\\]^`{|}~@+#%?/#txt', 'skype:foo %5B%5C%5D%5E%60%7B%7C%7D~@+%23%25?/#txt'), //dokuwiki id's - array('onlytext', 'foo [\\]^`{|}~@+#%?/#txt', DOKU_BASE.'doku.php?id=onlytextfoo#txt'), - array('user', 'foo [\\]^`{|}~@+#%?/#txt', DOKU_BASE.'doku.php?id=user:foo#txt'), - array('withquery', 'foo [\\]^`{|}~@+#%?/#txt', DOKU_BASE.'doku.php?id=anyns:foo&do=edit#txt') + array('onlytext', 'foo [\\]^`{|}~@+#%/#txt', DOKU_BASE.'doku.php?id=onlytextfoo#txt'), + array('user', 'foo [\\]^`{|}~@+#%/#txt', DOKU_BASE.'doku.php?id=user:foo#txt'), + array('withquery', 'foo [\\]^`{|}~@+#%/#txt', DOKU_BASE.'doku.php?id=anyns:foo&do=edit#txt') ); foreach($tests as $test) { -- cgit v1.2.3 From b86bc28af9b961266a2caeeb86c8f6f125adc412 Mon Sep 17 00:00:00 2001 From: iamchenxin Date: Mon, 1 Jun 2015 20:02:52 +0800 Subject: remote.test --- _test/tests/inc/remote.test.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to '_test') diff --git a/_test/tests/inc/remote.test.php b/_test/tests/inc/remote.test.php index d0d4eb7ce..037b1dc0b 100644 --- a/_test/tests/inc/remote.test.php +++ b/_test/tests/inc/remote.test.php @@ -160,10 +160,16 @@ class remote_test extends DokuWikiTest { $this->assertTrue($this->remote->hasAccess()); } + /** + * @expectedException RemoteAccessDeniedException + */ function test_hasAccessFail() { global $conf; $conf['remote'] = 0; - $this->assertFalse($this->remote->hasAccess()); + // the hasAccess() should throw a Exception to keep the same semantics with xmlrpc.php. + // because the user(xmlrpc) check remote before .--> (!$conf['remote']) die('XML-RPC server not enabled.'); + // so it must be a Exception when get here. + $this->remote->hasAccess(); } function test_hasAccessFailAcl() { -- cgit v1.2.3 From 0cfb5a3076f8591bdbe10f9915199b3b3863dec8 Mon Sep 17 00:00:00 2001 From: Patrick Brown Date: Wed, 22 Jul 2015 22:04:09 -0400 Subject: Remove non-functioning interwiki links --- _test/tests/inc/parser/renderer_resolveinterwiki.test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php index 8379bc065..772001b99 100644 --- a/_test/tests/inc/parser/renderer_resolveinterwiki.test.php +++ b/_test/tests/inc/parser/renderer_resolveinterwiki.test.php @@ -14,6 +14,8 @@ class Test_resolveInterwiki extends DokuWikiTest { $Renderer->interwiki['withslash'] = '/test'; $Renderer->interwiki['onlytext'] = ':onlytext{NAME}'; //with {URL} double urlencoded $Renderer->interwiki['withquery'] = ':anyns:{NAME}?do=edit'; + //this was the only link with host/port/path/query. Keep it here for regression + $Renderer->interwiki['coral'] = 'http://{HOST}.{PORT}.nyud.net:8090{PATH}?{QUERY}'; $tests = array( // shortcut, reference and expected -- cgit v1.2.3 From 32c7ba22db35fd22aed87fb31984069873cefc4f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 24 Jul 2015 15:18:42 +0200 Subject: skip sha512 tests when it's not available This makes the entire testsuite run through on HHVM 3.8.0 on phpunit beta-2015-06-18 :-) Note: this does not mean that DokuWiki is fully compatible with HHVM, but it's a good step! --- _test/tests/inc/auth_password.test.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to '_test') diff --git a/_test/tests/inc/auth_password.test.php b/_test/tests/inc/auth_password.test.php index 07b9f5bb2..5067e2ca1 100644 --- a/_test/tests/inc/auth_password.test.php +++ b/_test/tests/inc/auth_password.test.php @@ -16,9 +16,16 @@ class auth_password_test extends DokuWikiTest { 'kmd5' => 'a579299436d7969791189acadd86fcb716', 'djangomd5' => 'md5$abcde$d0fdddeda8cd92725d2b54148ac09158', 'djangosha1' => 'sha1$abcde$c8e65a7f0acc9158843048a53dcc5a6bc4d17678', - 'sha512' => '$6$abcdefgh12345678$J9.zOcgx0lotwZdcz0uulA3IVQMinZvFZVjA5vapRLVAAqtay23XD4xeeUxQ3B4JvDWYFBIxVWW1tOYlHX13k1' + ); + function __construct() { + if(defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) { + // Check SHA512 only if available in this PHP + $this->passes['sha512'] = '$6$abcdefgh12345678$J9.zOcgx0lotwZdcz0uulA3IVQMinZvFZVjA5vapRLVAAqtay23XD4xeeUxQ3B4JvDWYFBIxVWW1tOYlHX13k1'; + } + } + function test_cryptPassword(){ foreach($this->passes as $method => $hash){ -- cgit v1.2.3