From 912be8f66fc77a0999250f2f494ddaeed4b3fa08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gro=C3=9Fe?= Date: Thu, 27 Nov 2014 18:12:02 +0100 Subject: Add tests: known and unknown external video files --- _test/tests/inc/parser/parser_media.test.php | 78 ++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 _test/tests/inc/parser/parser_media.test.php (limited to '_test/tests/inc') diff --git a/_test/tests/inc/parser/parser_media.test.php b/_test/tests/inc/parser/parser_media.test.php new file mode 100644 index 000000000..0b62473f8 --- /dev/null +++ b/_test/tests/inc/parser/parser_media.test.php @@ -0,0 +1,78 @@ + +*/ +class TestOfDoku_Parser_Media extends TestOfDoku_Parser { + + function testVideoOGVExternal() { + $file = 'http://some.where.far/away.ogv'; + $parser_response = p_get_instructions('{{' . $file . '}}'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('externalmedia',array($file,null,null,null,null,'cache','details')), + array('cdata',array(null)), + array('p_close',array()), + array('document_end',array()), + ); + $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls); + + $Renderer = new Doku_Renderer_xhtml(); + $url = $Renderer->externalmedia($file,null,null,null,null,'cache','details',true); + //print_r("url: " . $url); + $video = ''."\n"; + $this->assertEquals(substr($url,304),$rest); + } + + /** + * unknown extension of external media file + */ + function testVideoVIDExternal() { + $file = 'http://some.where.far/away.vid'; + $parser_response = p_get_instructions('{{' . $file . '}}'); + + $calls = array( + array('document_start', array()), + array('p_open', array()), + array('externalmedia', array($file, null, null, null, null, 'cache', 'details')), + array('cdata', array(null)), + array('p_close', array()), + array('document_end', array()), + ); + $this->assertEquals(array_map('stripbyteindex', $parser_response), $calls); + + $Renderer = new Doku_Renderer_xhtml(); + $url = $Renderer->externalmedia($file, null, null, null, null, 'cache', 'details', true); + // work around random token + $a_first_part = ''; + $this->assertEquals(substr($url,0,34),$a_first_part); + $this->assertEquals(substr($url,40,121),$a_second_part); + $rest = 'away.vid'; + $this->assertEquals(substr($url,161),$rest); + } +} + +/** + * .oga: + * http://upload.wikimedia.org/wikipedia/commons/6/6b/Meow_of_a_pleading_cat.oga + * + * .wav: + * http://upload.wikimedia.org/wikipedia/commons/8/81/Meow_of_a_Siamese_cat_-_freemaster2.wav + * + * + */ -- cgit v1.2.3 From d47f74a0328452bed21867aa4e20557b7d4564e4 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Mon, 1 Dec 2014 17:05:26 +0000 Subject: update parser tests for change in listitem_open instruction --- _test/tests/inc/parser/parser_footnote.test.php | 2 +- _test/tests/inc/parser/parser_lists.test.php | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/parser/parser_footnote.test.php b/_test/tests/inc/parser/parser_footnote.test.php index b47a575de..2457fb031 100644 --- a/_test/tests/inc/parser/parser_footnote.test.php +++ b/_test/tests/inc/parser/parser_footnote.test.php @@ -303,7 +303,7 @@ class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { array('nest', array ( array ( array('footnote_open',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), diff --git a/_test/tests/inc/parser/parser_lists.test.php b/_test/tests/inc/parser/parser_lists.test.php index e4ef1f83e..6acaff637 100644 --- a/_test/tests/inc/parser/parser_lists.test.php +++ b/_test/tests/inc/parser/parser_lists.test.php @@ -13,7 +13,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -46,7 +46,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { $calls = array ( array('document_start',array()), array('listo_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -80,7 +80,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { $calls = array ( array('document_start',array()), array('listo_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -109,7 +109,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -138,7 +138,7 @@ class TestOfDoku_Parser_Lists extends TestOfDoku_Parser { $calls = array ( array('document_start',array()), array('listo_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -188,7 +188,7 @@ Bar'); array('cdata',array("Foo")), array('p_close',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('listcontent_close',array()), @@ -227,7 +227,7 @@ Bar'); $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('strong_open',array()), array('cdata',array("A")), @@ -262,7 +262,7 @@ Bar'); $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('unformatted',array("A")), array('listcontent_close',array()), @@ -291,7 +291,7 @@ Bar'); $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('cdata',array("A")), array('linebreak',array()), @@ -355,7 +355,7 @@ Bar'); $calls = array ( array('document_start',array()), array('listu_open',array()), - array('listitem_open',array(1)), + array('listitem_open',array(1,Doku_Handler_List::NODE)), array('listcontent_open',array()), array('nest', array( array( array('footnote_open',array()), -- cgit v1.2.3 From db42b6f8860359481248e9bc847b111497511d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gro=C3=9Fe?= Date: Thu, 18 Dec 2014 10:50:08 +0100 Subject: Add test for internal video files --- _test/tests/inc/parser/parser_media.test.php | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/parser/parser_media.test.php b/_test/tests/inc/parser/parser_media.test.php index 0b62473f8..195b95991 100644 --- a/_test/tests/inc/parser/parser_media.test.php +++ b/_test/tests/inc/parser/parser_media.test.php @@ -65,6 +65,41 @@ class TestOfDoku_Parser_Media extends TestOfDoku_Parser { $rest = 'away.vid'; $this->assertEquals(substr($url,161),$rest); } + + + function testVideoOGVInternal() { + $file = 'wiki:kind_zu_katze.ogv'; + $parser_response = p_get_instructions('{{' . $file . '}}'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('internalmedia',array($file,null,null,null,null,'cache','details')), + array('cdata',array(null)), + array('p_close',array()), + array('document_end',array()), + ); + $this->assertEquals(array_map('stripbyteindex',$parser_response),$calls); + + $Renderer = new Doku_Renderer_xhtml(); + $url = $Renderer->externalmedia($file,null,null,null,null,'cache','details',true); + + $video = ''."\n"; + $this->assertEquals(substr($url,644),$rest); + } } /** -- cgit v1.2.3 From 50e07413f6c62d6593a89dcf070dffd413170aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gro=C3=9Fe?= Date: Thu, 18 Dec 2014 11:02:40 +0100 Subject: Fix file size --- _test/tests/inc/parser/parser_media.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/parser/parser_media.test.php b/_test/tests/inc/parser/parser_media.test.php index 195b95991..e124b85e2 100644 --- a/_test/tests/inc/parser/parser_media.test.php +++ b/_test/tests/inc/parser/parser_media.test.php @@ -92,7 +92,7 @@ class TestOfDoku_Parser_Media extends TestOfDoku_Parser { $source_ogv = ''; $this->assertEquals(substr($url,212,83),$source_ogv); - $a_webm = 'kind_zu_katze.webm'; + $a_webm = 'kind_zu_katze.webm'; $a_ogv = 'kind_zu_katze.ogv'; $this->assertEquals(substr($url,296,176),$a_webm); $this->assertEquals(substr($url,472,172),$a_ogv); -- cgit v1.2.3 From 7268f44f1b278bafced8e85930ba3dd0c92b8900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gro=C3=9Fe?= Date: Thu, 18 Dec 2014 11:39:15 +0100 Subject: Remove stray comment block --- _test/tests/inc/parser/parser_media.test.php | 10 ---------- 1 file changed, 10 deletions(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/parser/parser_media.test.php b/_test/tests/inc/parser/parser_media.test.php index e124b85e2..d9a0626f5 100644 --- a/_test/tests/inc/parser/parser_media.test.php +++ b/_test/tests/inc/parser/parser_media.test.php @@ -101,13 +101,3 @@ class TestOfDoku_Parser_Media extends TestOfDoku_Parser { $this->assertEquals(substr($url,644),$rest); } } - -/** - * .oga: - * http://upload.wikimedia.org/wikipedia/commons/6/6b/Meow_of_a_pleading_cat.oga - * - * .wav: - * http://upload.wikimedia.org/wikipedia/commons/8/81/Meow_of_a_Siamese_cat_-_freemaster2.wav - * - * - */ -- cgit v1.2.3 From 2f505bf9a889ddaf530fe975967589f6c6993e39 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 16 Mar 2015 22:49:47 +0100 Subject: use correct host in proxy tests --- _test/tests/inc/httpclient_https_proxy.test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/httpclient_https_proxy.test.php b/_test/tests/inc/httpclient_https_proxy.test.php index 9402e91af..7a54bb92e 100644 --- a/_test/tests/inc/httpclient_https_proxy.test.php +++ b/_test/tests/inc/httpclient_https_proxy.test.php @@ -2,7 +2,7 @@ require_once dirname(__FILE__).'/httpclient_http_proxy.test.php'; class httpclient_https_proxy_test extends httpclient_http_proxy_test { - protected $url = 'https://www.dokuwiki.org/README'; + protected $url = 'https://test.dokuwiki.org/README'; public function setUp(){ // skip tests when this PHP has no SSL support @@ -27,4 +27,4 @@ class httpclient_https_proxy_test extends httpclient_http_proxy_test { $this->assertFalse($data); $this->assertEquals(-150, $http->status); } -} \ No newline at end of file +} -- cgit v1.2.3 From 09513545a4776e31b5fb113bd8741df1df878816 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 18 Mar 2015 11:19:04 +0100 Subject: give better error message in HTTPClient for failed crypto setup --- _test/tests/inc/httpclient_http_proxy.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/httpclient_http_proxy.test.php b/_test/tests/inc/httpclient_http_proxy.test.php index c44dc7ed7..79b8f8e5e 100644 --- a/_test/tests/inc/httpclient_http_proxy.test.php +++ b/_test/tests/inc/httpclient_http_proxy.test.php @@ -15,7 +15,7 @@ class httpclient_http_proxy_test extends DokuWikiTest { $http->proxy_port = 8080; $data = $http->get($this->url); - $this->assertFalse($data === false, 'HTTP response '.$http->error); + $this->assertFalse($data === false, 'HTTP response: '.$http->error.' ['.$this->url.']'); $this->assertTrue(strpos($data,'DokuWiki') !== false, 'response content'); } } \ No newline at end of file -- cgit v1.2.3 From d387bf5e958e9d25a7192d1f5e5280ac0eb82da7 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 18 Mar 2015 20:27:10 +0100 Subject: correct error checking for bz2 file reading The code reading .bz2 compressed files did not correctly check for possible read errors. In case of a corrupted file this could have led to an infinite loop. Thanks to Filippo Cavallarin from www.segment.technology for dicovering this bug. --- _test/tests/inc/io_readfile.test.php | 53 ++++++++++++++++++++++++++++ _test/tests/inc/io_readfile/corrupt.txt.bz2 | 1 + _test/tests/inc/io_readfile/corrupt.txt.gz | Bin 0 -> 31 bytes _test/tests/inc/io_readfile/test.txt.bz2 | Bin 0 -> 49 bytes _test/tests/inc/io_readfile/test.txt.gz | Bin 0 -> 31 bytes 5 files changed, 54 insertions(+) create mode 100644 _test/tests/inc/io_readfile.test.php create mode 100644 _test/tests/inc/io_readfile/corrupt.txt.bz2 create mode 100644 _test/tests/inc/io_readfile/corrupt.txt.gz create mode 100644 _test/tests/inc/io_readfile/test.txt.bz2 create mode 100644 _test/tests/inc/io_readfile/test.txt.gz (limited to '_test/tests/inc') diff --git a/_test/tests/inc/io_readfile.test.php b/_test/tests/inc/io_readfile.test.php new file mode 100644 index 000000000..e3e90cd8d --- /dev/null +++ b/_test/tests/inc/io_readfile.test.php @@ -0,0 +1,53 @@ +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 test_plain(){ + // since git converts line endings, we can't check in this test file but have to create it ourselves + $plain = TMP_DIR.'/test.txt'; + file_put_contents($plain, "The\015\012Test\015\012"); + + $this->assertEquals("The\012Test\012", io_readFile($plain)); + $this->assertEquals("The\015\012Test\015\012", io_readFile($plain, false)); + $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt')); + } + + /** + * @depends test_ext_zlib + */ + function test_gzfiles(){ + $this->assertEquals("The\012Test\012", io_readFile(__DIR__.'/io_readfile/test.txt.gz')); + $this->assertEquals("The\015\012Test\015\012", io_readFile(__DIR__.'/io_readfile/test.txt.gz', false)); + $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt.gz')); + $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/corrupt.txt.gz')); + } + + /** + * @depends test_ext_bz2 + */ + function test_bzfiles(){ + $this->assertEquals("The\012Test\012", io_readFile(__DIR__.'/io_readfile/test.txt.bz2')); + $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')); + } + +} \ No newline at end of file diff --git a/_test/tests/inc/io_readfile/corrupt.txt.bz2 b/_test/tests/inc/io_readfile/corrupt.txt.bz2 new file mode 100644 index 000000000..97f742919 --- /dev/null +++ b/_test/tests/inc/io_readfile/corrupt.txt.bz2 @@ -0,0 +1 @@ +BZh91AY&SYXHd¬ \ No newline at end of file diff --git a/_test/tests/inc/io_readfile/corrupt.txt.gz b/_test/tests/inc/io_readfile/corrupt.txt.gz new file mode 100644 index 000000000..f7f5d3397 Binary files /dev/null and b/_test/tests/inc/io_readfile/corrupt.txt.gz differ diff --git a/_test/tests/inc/io_readfile/test.txt.bz2 b/_test/tests/inc/io_readfile/test.txt.bz2 new file mode 100644 index 000000000..3d4e1b226 Binary files /dev/null and b/_test/tests/inc/io_readfile/test.txt.bz2 differ diff --git a/_test/tests/inc/io_readfile/test.txt.gz b/_test/tests/inc/io_readfile/test.txt.gz new file mode 100644 index 000000000..8ac8f7d40 Binary files /dev/null and b/_test/tests/inc/io_readfile/test.txt.gz differ -- cgit v1.2.3 From 6abea1c0be56a2cb5575c8921c3e6661ed565697 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 18 Mar 2015 21:55:59 +0100 Subject: fixed HTTPS proxy tests, our tests now run on httpbin.org This also reverses the order of crypto protocols tried again. Using TLS first again. related to #915 --- _test/tests/inc/httpclient_http_proxy.test.php | 2 +- _test/tests/inc/httpclient_https_proxy.test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/httpclient_http_proxy.test.php b/_test/tests/inc/httpclient_http_proxy.test.php index 79b8f8e5e..dae801dbd 100644 --- a/_test/tests/inc/httpclient_http_proxy.test.php +++ b/_test/tests/inc/httpclient_http_proxy.test.php @@ -3,7 +3,7 @@ require_once (__DIR__ . '/httpclient_mock.php'); class httpclient_http_proxy_test extends DokuWikiTest { - protected $url = 'http://test.dokuwiki.org/README'; + protected $url = 'http://httpbin.org/user-agent'; /** * @group internet diff --git a/_test/tests/inc/httpclient_https_proxy.test.php b/_test/tests/inc/httpclient_https_proxy.test.php index 7a54bb92e..cf5b9a8b9 100644 --- a/_test/tests/inc/httpclient_https_proxy.test.php +++ b/_test/tests/inc/httpclient_https_proxy.test.php @@ -2,7 +2,7 @@ require_once dirname(__FILE__).'/httpclient_http_proxy.test.php'; class httpclient_https_proxy_test extends httpclient_http_proxy_test { - protected $url = 'https://test.dokuwiki.org/README'; + protected $url = 'https://httpbin.org/user-agent'; public function setUp(){ // skip tests when this PHP has no SSL support -- cgit v1.2.3 From 8599a179b08d4cdcf1c8895bacde82aad9df101f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 18 Mar 2015 22:43:45 +0100 Subject: corrupted the gz test file more it seems that different zlib versions behave different with corrupted files. Some return false, some return whatever they still can read from the file. the file now should no longer be readable by any version. --- _test/tests/inc/io_readfile/corrupt.txt.gz | Bin 31 -> 31 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/io_readfile/corrupt.txt.gz b/_test/tests/inc/io_readfile/corrupt.txt.gz index f7f5d3397..9d7666f47 100644 Binary files a/_test/tests/inc/io_readfile/corrupt.txt.gz and b/_test/tests/inc/io_readfile/corrupt.txt.gz differ -- cgit v1.2.3 From bd8c2ebfb888520b80db00d3c1c6288be289862c Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 25 Apr 2015 10:20:14 +0200 Subject: introduce new "flaky" test group this group is skipped by default --- _test/tests/inc/cache_use.test.php | 19 +++++++------------ _test/tests/inc/httpclient_http.test.php | 1 + 2 files changed, 8 insertions(+), 12 deletions(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/cache_use.test.php b/_test/tests/inc/cache_use.test.php index 3ea212d50..c0c12580a 100644 --- a/_test/tests/inc/cache_use.test.php +++ b/_test/tests/inc/cache_use.test.php @@ -4,6 +4,8 @@ * Class cache_use_test * * Tests if caching can actually be used + * + * @todo tests marked as flaky until Ticket #694 has been fixed */ class cache_use_test extends DokuWikiTest { /** @var cache_renderer $cache */ @@ -28,18 +30,11 @@ class cache_use_test extends DokuWikiTest { touch($this->cache->cache, $time); } - function test_use() { - $this->markTestSkipped('Disabled until Ticket #694 has been fixed'); - return; - - $this->assertTrue($this->cache->useCache()); - } - /** * In all the following tests the cache should not be usable * as such, they are meaningless if test_use didn't pass. * - * @depends test_use + * @group flaky */ function test_purge() { /* @var Input $INPUT */ @@ -51,7 +46,7 @@ class cache_use_test extends DokuWikiTest { } /** - * @depends test_use + * @group flaky */ function test_filedependency() { // give the dependent src file the same mtime as the cache @@ -60,7 +55,7 @@ class cache_use_test extends DokuWikiTest { } /** - * @depends test_use + * @group flaky */ function test_age() { // need to age both our source file & the cache @@ -74,7 +69,7 @@ class cache_use_test extends DokuWikiTest { } /** - * @depends test_use + * @group flaky */ function test_confnocaching() { global $conf; @@ -83,4 +78,4 @@ class cache_use_test extends DokuWikiTest { $this->assertFalse($this->cache->useCache()); $this->assertNotEmpty($this->cache->_nocache); } -} \ No newline at end of file +} diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index 3446e1184..94b8e1bc1 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -289,6 +289,7 @@ class httpclient_http_test extends DokuWikiTest { * This address caused trouble with stream_select() * * @group internet + * @group flaky */ function test_wikimatrix(){ $http = new HTTPMockClient(); -- cgit v1.2.3 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/tests/inc') 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/tests/inc') 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 e7a32b176701c088bab045437819448bb9adad41 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 8 May 2015 16:27:17 +0200 Subject: added autoloading for namespaced classes --- _test/tests/inc/form/form.test.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 _test/tests/inc/form/form.test.php (limited to '_test/tests/inc') diff --git a/_test/tests/inc/form/form.test.php b/_test/tests/inc/form/form.test.php new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From 6d0ceaf93ca31dfb83fd4325ef2eecd9cef733c0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 8 May 2015 17:26:11 +0200 Subject: added a first few tests. this is far from comprehensible, but should give an idea how the new library works and how to write tests --- _test/tests/inc/form/checkableelement.test.php | 49 ++++++++++++++++++++++++++ _test/tests/inc/form/form.test.php | 28 +++++++++++++++ _test/tests/inc/form/inputelement.test.php | 41 +++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 _test/tests/inc/form/checkableelement.test.php create mode 100644 _test/tests/inc/form/inputelement.test.php (limited to '_test/tests/inc') diff --git a/_test/tests/inc/form/checkableelement.test.php b/_test/tests/inc/form/checkableelement.test.php new file mode 100644 index 000000000..a0e4173e8 --- /dev/null +++ b/_test/tests/inc/form/checkableelement.test.php @@ -0,0 +1,49 @@ +addRadioButton('foo', 'label text first')->val('first')->attr('checked', 'checked'); + $form->addRadioButton('foo', 'label text second')->val('second'); + + $html = $form->toHTML(); + $pq = phpQuery::newDocumentXHTML($html); + + $input = $pq->find('input[name=foo]'); + $this->assertTrue($input->length == 2); + + $label = $pq->find('label'); + $this->assertTrue($label->length == 2); + + $inputs = $pq->find('input[name=foo]'); + $this->assertEquals('first', pq($inputs->elements[0])->val()); + $this->assertEquals('second', pq($inputs->elements[1])->val()); + $this->assertEquals('checked', pq($inputs->elements[0])->attr('checked')); + $this->assertEquals('', pq($inputs->elements[1])->attr('checked')); + } + + /** + * check that posted values overwrite preset default + */ + function test_prefill() { + global $INPUT; + $INPUT->post->set('foo', 'second'); + + + $form = new Form\Form(); + $form->addRadioButton('foo', 'label text first')->val('first')->attr('checked', 'checked'); + $form->addRadioButton('foo', 'label text second')->val('second'); + + $html = $form->toHTML(); + $pq = phpQuery::newDocumentXHTML($html); + + $inputs = $pq->find('input[name=foo]'); + $this->assertEquals('first', pq($inputs->elements[0])->val()); + $this->assertEquals('second', pq($inputs->elements[1])->val()); + $this->assertEquals('', pq($inputs->elements[0])->attr('checked')); + $this->assertEquals('checked', pq($inputs->elements[1])->attr('checked')); + } +} diff --git a/_test/tests/inc/form/form.test.php b/_test/tests/inc/form/form.test.php index e69de29bb..cdf3e5a3a 100644 --- a/_test/tests/inc/form/form.test.php +++ b/_test/tests/inc/form/form.test.php @@ -0,0 +1,28 @@ +get->set('id', $ID); + $INPUT->get->set('foo', 'bar'); + + $form = new Form\Form(); + $html = $form->toHTML(); + $pq = phpQuery::newDocumentXHTML($html); + + $this->assertTrue($pq->find('form')->hasClass('doku_form')); + $this->assertEquals(wl($ID, array('foo' => 'bar'), false, '&'), $pq->find('form')->attr('action')); + $this->assertEquals('post', $pq->find('form')->attr('method')); + + $this->assertTrue($pq->find('input[name=sectok]')->length == 1); + } + +} diff --git a/_test/tests/inc/form/inputelement.test.php b/_test/tests/inc/form/inputelement.test.php new file mode 100644 index 000000000..7a5e6d2ea --- /dev/null +++ b/_test/tests/inc/form/inputelement.test.php @@ -0,0 +1,41 @@ +addTextInput('foo', 'label text')->val('this is text'); + + $html = $form->toHTML(); + $pq = phpQuery::newDocumentXHTML($html); + + $input = $pq->find('input[name=foo]'); + $this->assertTrue($input->length == 1); + $this->assertEquals('this is text', $input->val()); + + $label = $pq->find('label'); + $this->assertTrue($label->length == 1); + $this->assertEquals('label text', $label->find('span')->text()); + } + + /** + * check that posted values overwrite preset default + */ + function test_prefill() { + global $INPUT; + $INPUT->post->set('foo', 'a new text'); + + $form = new Form\Form(); + $form->addTextInput('foo', 'label text')->val('this is text'); + + $html = $form->toHTML(); + $pq = phpQuery::newDocumentXHTML($html); + + $input = $pq->find('input[name=foo]'); + $this->assertTrue($input->length == 1); + $this->assertEquals('a new text', $input->val()); + } + +} -- 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/tests/inc') 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/tests/inc') 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 1f5d8b65a983fe0914971ee0bb4e5e58cbf8c8a7 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 11 May 2015 20:31:16 +0200 Subject: balance fieldsets --- _test/tests/inc/form/form.test.php | 87 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/form/form.test.php b/_test/tests/inc/form/form.test.php index cdf3e5a3a..3ae832b2c 100644 --- a/_test/tests/inc/form/form.test.php +++ b/_test/tests/inc/form/form.test.php @@ -2,6 +2,25 @@ use dokuwiki\Form; +/** + * makes form internals accessible for testing + */ +class TestForm extends Form\Form { + /** + * @return array list of element types + */ + function getElementTypeList() { + $list = array(); + foreach($this->elements as $element) $list[] = $element->getType(); + return $list; + } + + public function balanceFieldsets() { + parent::balanceFieldsets(); + } + +} + class form_form_test extends DokuWikiTest { /** @@ -25,4 +44,72 @@ class form_form_test extends DokuWikiTest { $this->assertTrue($pq->find('input[name=sectok]')->length == 1); } + + function test_fieldsetbalance() { + $form = new TestForm(); + $form->addFieldsetOpen(); + $form->addHTML('ignored'); + $form->addFieldsetClose(); + $form->balanceFieldsets(); + + $this->assertEquals( + array( + 'fieldsetopen', + 'html', + 'fieldsetclose' + ), + $form->getElementTypeList() + ); + + $form = new TestForm(); + $form->addHTML('ignored'); + $form->addFieldsetClose(); + $form->balanceFieldsets(); + + $this->assertEquals( + array( + 'fieldsetopen', + 'html', + 'fieldsetclose' + ), + $form->getElementTypeList() + ); + + + $form = new TestForm(); + $form->addFieldsetOpen(); + $form->addHTML('ignored'); + $form->balanceFieldsets(); + + $this->assertEquals( + array( + 'fieldsetopen', + 'html', + 'fieldsetclose' + ), + $form->getElementTypeList() + ); + + $form = new TestForm(); + $form->addHTML('ignored'); + $form->addFieldsetClose(); + $form->addHTML('ignored'); + $form->addFieldsetOpen(); + $form->addHTML('ignored'); + $form->balanceFieldsets(); + + $this->assertEquals( + array( + 'fieldsetopen', + 'html', + 'fieldsetclose', + 'html', + 'fieldsetopen', + 'html', + 'fieldsetclose' + ), + $form->getElementTypeList() + ); + } + } -- cgit v1.2.3 From 1bf2f04f1149da9ed13450ac33cbc6289d3d4f54 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 15 May 2015 15:45:32 +0200 Subject: remove tests that are now in upstream --- _test/tests/inc/tar.test.php | 454 ------------------------------- _test/tests/inc/tar/block.txt | 1 - _test/tests/inc/tar/foobar/testdata2.txt | 1 - _test/tests/inc/tar/longpath-gnu.tgz | Bin 413 -> 0 bytes _test/tests/inc/tar/longpath-ustar.tgz | Bin 311 -> 0 bytes _test/tests/inc/tar/tarbomb.tgz | Bin 183 -> 0 bytes _test/tests/inc/tar/test.tar | Bin 10240 -> 0 bytes _test/tests/inc/tar/test.tbz | Bin 217 -> 0 bytes _test/tests/inc/tar/test.tgz | Bin 220 -> 0 bytes _test/tests/inc/tar/testdata1.txt | 1 - _test/tests/inc/tar/zero.txt | 0 11 files changed, 457 deletions(-) delete mode 100644 _test/tests/inc/tar.test.php delete mode 100644 _test/tests/inc/tar/block.txt delete mode 100644 _test/tests/inc/tar/foobar/testdata2.txt delete mode 100644 _test/tests/inc/tar/longpath-gnu.tgz delete mode 100644 _test/tests/inc/tar/longpath-ustar.tgz delete mode 100644 _test/tests/inc/tar/tarbomb.tgz delete mode 100644 _test/tests/inc/tar/test.tar delete mode 100644 _test/tests/inc/tar/test.tbz delete mode 100644 _test/tests/inc/tar/test.tgz delete mode 100644 _test/tests/inc/tar/testdata1.txt delete mode 100644 _test/tests/inc/tar/zero.txt (limited to '_test/tests/inc') diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php deleted file mode 100644 index 15453b16d..000000000 --- a/_test/tests/inc/tar.test.php +++ /dev/null @@ -1,454 +0,0 @@ -extensions[] = 'tgz'; - } - if (extension_loaded('bz2')) { - $this->extensions[] = 'tbz'; - } - } - - /* - * 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'); - } - } - - /** - * simple test that checks that the given filenames and contents can be grepped from - * the uncompressed tar stream - * - * No check for format correctness - */ - public function test_createdynamic() { - $tar = new Tar(); - - $dir = dirname(__FILE__).'/tar'; - $tdir = ltrim($dir,'/'); - - $tar->create(); - $tar->AddFile("$dir/testdata1.txt"); - $tar->AddFile("$dir/foobar/testdata2.txt", 'noway/testdata2.txt'); - $tar->addData('another/testdata3.txt', 'testcontent3'); - - $data = $tar->getArchive(); - - $this->assertTrue(strpos($data, 'testcontent1') !== false, 'Content in TAR'); - $this->assertTrue(strpos($data, 'testcontent2') !== false, 'Content in TAR'); - $this->assertTrue(strpos($data, 'testcontent3') !== false, 'Content in TAR'); - - // fullpath might be too long to be stored as full path FS#2802 - $this->assertTrue(strpos($data, "$tdir") !== false, 'Path in TAR'); - $this->assertTrue(strpos($data, "testdata1.txt") !== false, 'File in TAR'); - - $this->assertTrue(strpos($data, 'noway/testdata2.txt') !== false, 'Path in TAR'); - $this->assertTrue(strpos($data, 'another/testdata3.txt') !== false, 'Path in TAR'); - - // fullpath might be too long to be stored as full path FS#2802 - $this->assertTrue(strpos($data, "$tdir/foobar") === false, 'Path not in TAR'); - $this->assertTrue(strpos($data, "foobar.txt") === false, 'File not in TAR'); - - $this->assertTrue(strpos($data, "foobar") === false, 'Path not in TAR'); - } - - /** - * simple test that checks that the given filenames and contents can be grepped from the - * uncompressed tar file - * - * No check for format correctness - */ - public function test_createfile() { - $tar = new Tar(); - - $dir = dirname(__FILE__).'/tar'; - $tdir = ltrim($dir,'/'); - $tmp = tempnam(sys_get_temp_dir(), 'dwtartest'); - - $tar->create($tmp, Tar::COMPRESS_NONE); - $tar->AddFile("$dir/testdata1.txt"); - $tar->AddFile("$dir/foobar/testdata2.txt", 'noway/testdata2.txt'); - $tar->addData('another/testdata3.txt', 'testcontent3'); - $tar->close(); - - $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number - $data = file_get_contents($tmp); - - $this->assertTrue(strpos($data, 'testcontent1') !== false, 'Content in TAR'); - $this->assertTrue(strpos($data, 'testcontent2') !== false, 'Content in TAR'); - $this->assertTrue(strpos($data, 'testcontent3') !== false, 'Content in TAR'); - - // fullpath might be too long to be stored as full path FS#2802 - $this->assertTrue(strpos($data, "$tdir") !== false, "Path in TAR '$tdir'"); - $this->assertTrue(strpos($data, "testdata1.txt") !== false, 'File in TAR'); - - $this->assertTrue(strpos($data, 'noway/testdata2.txt') !== false, 'Path in TAR'); - $this->assertTrue(strpos($data, 'another/testdata3.txt') !== false, 'Path in TAR'); - - // fullpath might be too long to be stored as full path FS#2802 - $this->assertTrue(strpos($data, "$tdir/foobar") === false, 'Path not in TAR'); - $this->assertTrue(strpos($data, "foobar.txt") === false, 'File not in TAR'); - - $this->assertTrue(strpos($data, "foobar") === false, 'Path not in TAR'); - - @unlink($tmp); - } - - /** - * List the contents of the prebuilt TAR files - */ - public function test_tarcontent() { - $dir = dirname(__FILE__).'/tar'; - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $content = $tar->contents(); - - $this->assertCount(4, $content, "Contents of $file"); - $this->assertEquals('tar/testdata1.txt', $content[1]['filename'], "Contents of $file"); - $this->assertEquals(13, $content[1]['size'], "Contents of $file"); - - $this->assertEquals('tar/foobar/testdata2.txt', $content[3]['filename'], "Contents of $file"); - $this->assertEquals(13, $content[1]['size'], "Contents of $file"); - } - } - - /** - * Extract the prebuilt tar files - */ - public function test_tarextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $tar->extract($out); - - clearstatcache(); - - $this->assertFileExists($out.'/tar/testdata1.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/tar/testdata1.txt'), "Extracted $file"); - - $this->assertFileExists($out.'/tar/foobar/testdata2.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/tar/foobar/testdata2.txt'), "Extracted $file"); - - TestUtils::rdelete($out); - } - } - - /** - * Extract the prebuilt tar files with component stripping - */ - public function test_compstripextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $tar->extract($out, 1); - - clearstatcache(); - - $this->assertFileExists($out.'/testdata1.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/testdata1.txt'), "Extracted $file"); - - $this->assertFileExists($out.'/foobar/testdata2.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/foobar/testdata2.txt'), "Extracted $file"); - - TestUtils::rdelete($out); - } - } - - /** - * Extract the prebuilt tar files with prefix stripping - */ - public function test_prefixstripextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $tar->extract($out, 'tar/foobar/'); - - clearstatcache(); - - $this->assertFileExists($out.'/tar/testdata1.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/tar/testdata1.txt'), "Extracted $file"); - - $this->assertFileExists($out.'/testdata2.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/testdata2.txt'), "Extracted $file"); - - TestUtils::rdelete($out); - } - } - - /** - * Extract the prebuilt tar files with include regex - */ - public function test_includeextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $tar->extract($out, '', '', '/\/foobar\//'); - - clearstatcache(); - - $this->assertFileNotExists($out.'/tar/testdata1.txt', "Extracted $file"); - - $this->assertFileExists($out.'/tar/foobar/testdata2.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/tar/foobar/testdata2.txt'), "Extracted $file"); - - TestUtils::rdelete($out); - } - } - - /** - * Extract the prebuilt tar files with exclude regex - */ - public function test_excludeextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach($this->extensions as $ext) { - $tar = new Tar(); - $file = "$dir/test.$ext"; - - $tar->open($file); - $tar->extract($out, '', '/\/foobar\//'); - - clearstatcache(); - - $this->assertFileExists($out.'/tar/testdata1.txt', "Extracted $file"); - $this->assertEquals(13, filesize($out.'/tar/testdata1.txt'), "Extracted $file"); - - $this->assertFileNotExists($out.'/tar/foobar/testdata2.txt', "Extracted $file"); - - TestUtils::rdelete($out); - } - } - - /** - * Check the extension to compression guesser - */ - public function test_filetype() { - $tar = new Tar(); - $this->assertEquals(Tar::COMPRESS_NONE, $tar->filetype('foo')); - $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tgz')); - $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tGZ')); - $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tar.GZ')); - $this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype('foo.tar.gz')); - $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tbz')); - $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tBZ')); - $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.BZ2')); - $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.bz2')); - } - - /** - * @depends test_ext_zlib - */ - public function test_longpathextract() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - foreach(array('ustar', 'gnu') as $format) { - $tar = new Tar(); - $tar->open("$dir/longpath-$format.tgz"); - $tar->extract($out); - - $this->assertFileExists($out.'/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/test.txt'); - - TestUtils::rdelete($out); - } - } - - // FS#1442 - public function test_createlongfile() { - $tar = new Tar(); - $tmp = tempnam(sys_get_temp_dir(), 'dwtartest'); - - $path = '0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.txt'; - - $tar->create($tmp, Tar::COMPRESS_NONE); - $tar->addData($path, 'testcontent1'); - $tar->close(); - - $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number - $data = file_get_contents($tmp); - - // We should find the complete path and a longlink entry - $this->assertTrue(strpos($data, 'testcontent1') !== false, 'content in TAR'); - $this->assertTrue(strpos($data, $path) !== false, 'path in TAR'); - $this->assertTrue(strpos($data, '@LongLink') !== false, '@LongLink in TAR'); - - @unlink($tmp); - } - - public function test_createlongpathustar() { - $tar = new Tar(); - $tmp = tempnam(sys_get_temp_dir(), 'dwtartest'); - - $path = ''; - for($i=0; $i<11; $i++) $path .= '1234567890/'; - $path = rtrim($path,'/'); - - $tar->create($tmp, Tar::COMPRESS_NONE); - $tar->addData("$path/test.txt", 'testcontent1'); - $tar->close(); - - $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number - $data = file_get_contents($tmp); - - // We should find the path and filename separated, no longlink entry - $this->assertTrue(strpos($data, 'testcontent1') !== false, 'content in TAR'); - $this->assertTrue(strpos($data, 'test.txt') !== false, 'filename in TAR'); - $this->assertTrue(strpos($data, $path) !== false, 'path in TAR'); - $this->assertFalse(strpos($data, "$path/test.txt") !== false, 'full filename in TAR'); - $this->assertFalse(strpos($data, '@LongLink') !== false, '@LongLink in TAR'); - - @unlink($tmp); - } - - public function test_createlongpathgnu() { - $tar = new Tar(); - $tmp = tempnam(sys_get_temp_dir(), 'dwtartest'); - - $path = ''; - for($i=0; $i<20; $i++) $path .= '1234567890/'; - $path = rtrim($path,'/'); - - $tar->create($tmp, Tar::COMPRESS_NONE); - $tar->addData("$path/test.txt", 'testcontent1'); - $tar->close(); - - $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number - $data = file_get_contents($tmp); - - // We should find the complete path/filename and a longlink entry - $this->assertTrue(strpos($data, 'testcontent1') !== false, 'content in TAR'); - $this->assertTrue(strpos($data, 'test.txt') !== false, 'filename in TAR'); - $this->assertTrue(strpos($data, $path) !== false, 'path in TAR'); - $this->assertTrue(strpos($data, "$path/test.txt") !== false, 'full filename in TAR'); - $this->assertTrue(strpos($data, '@LongLink') !== false, '@LongLink in TAR'); - - @unlink($tmp); - } - - /** - * Extract a tarbomomb - * @depends test_ext_zlib - */ - public function test_tarbomb() { - $dir = dirname(__FILE__).'/tar'; - $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - - $tar = new Tar(); - - $tar->open("$dir/tarbomb.tgz"); - $tar->extract($out); - - clearstatcache(); - - $this->assertFileExists($out.'/AAAAAAAAAAAAAAAAA/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB.txt'); - - TestUtils::rdelete($out); - } - - /** - * A single zero file should be just a header block + the footer - */ - public function test_zerofile(){ - $dir = dirname(__FILE__).'/tar'; - $tar = new Tar(); - $tar->create(); - $tar->addFile("$dir/zero.txt", 'zero.txt'); - $file = $tar->getArchive(Tar::COMPRESS_NONE); - - $this->assertEquals(512*3, strlen($file)); // 1 header block + 2 footer blocks - } - - public function test_zerodata(){ - $tar = new Tar(); - $tar->create(); - $tar->addData('zero.txt',''); - $file = $tar->getArchive(Tar::COMPRESS_NONE); - - $this->assertEquals(512*3, strlen($file)); // 1 header block + 2 footer blocks - } - - /** - * A file of exactly one block should be just a header block + data block + the footer - */ - public function test_blockfile(){ - $dir = dirname(__FILE__).'/tar'; - $tar = new Tar(); - $tar->create(); - $tar->addFile("$dir/block.txt", 'block.txt'); - $file = $tar->getArchive(Tar::COMPRESS_NONE); - - $this->assertEquals(512*4, strlen($file)); // 1 header block + data block + 2 footer blocks - } - - public function test_blockdata(){ - $tar = new Tar(); - $tar->create(); - $tar->addData('block.txt', str_pad('', 512, 'x')); - $file = $tar->getArchive(Tar::COMPRESS_NONE); - - $this->assertEquals(512*4, strlen($file)); // 1 header block + data block + 2 footer blocks - } - - - public function test_cleanPath(){ - $tar = new Tar(); - $tests = array ( - '/foo/bar' => 'foo/bar', - '/foo/bar/' => 'foo/bar', - 'foo//bar' => 'foo/bar', - 'foo/0/bar' => 'foo/0/bar', - 'foo/../bar' => 'bar', - 'foo/bang/bang/../../bar' => 'foo/bar', - 'foo/../../bar' => 'bar', - 'foo/.././../bar' => 'bar', - ); - - foreach($tests as $in => $out){ - $this->assertEquals($out, $tar->cleanPath($in), "Input: $in"); - } - } -} diff --git a/_test/tests/inc/tar/block.txt b/_test/tests/inc/tar/block.txt deleted file mode 100644 index 9b2f53080..000000000 --- a/_test/tests/inc/tar/block.txt +++ /dev/null @@ -1 +0,0 @@ -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \ No newline at end of file diff --git a/_test/tests/inc/tar/foobar/testdata2.txt b/_test/tests/inc/tar/foobar/testdata2.txt deleted file mode 100644 index a7db15771..000000000 --- a/_test/tests/inc/tar/foobar/testdata2.txt +++ /dev/null @@ -1 +0,0 @@ -testcontent2 diff --git a/_test/tests/inc/tar/longpath-gnu.tgz b/_test/tests/inc/tar/longpath-gnu.tgz deleted file mode 100644 index 6c937c8fe..000000000 Binary files a/_test/tests/inc/tar/longpath-gnu.tgz and /dev/null differ diff --git a/_test/tests/inc/tar/longpath-ustar.tgz b/_test/tests/inc/tar/longpath-ustar.tgz deleted file mode 100644 index 59efbff66..000000000 Binary files a/_test/tests/inc/tar/longpath-ustar.tgz and /dev/null differ diff --git a/_test/tests/inc/tar/tarbomb.tgz b/_test/tests/inc/tar/tarbomb.tgz deleted file mode 100644 index 8418d4073..000000000 Binary files a/_test/tests/inc/tar/tarbomb.tgz and /dev/null differ diff --git a/_test/tests/inc/tar/test.tar b/_test/tests/inc/tar/test.tar deleted file mode 100644 index 931866b0b..000000000 Binary files a/_test/tests/inc/tar/test.tar and /dev/null differ diff --git a/_test/tests/inc/tar/test.tbz b/_test/tests/inc/tar/test.tbz deleted file mode 100644 index 5a7374019..000000000 Binary files a/_test/tests/inc/tar/test.tbz and /dev/null differ diff --git a/_test/tests/inc/tar/test.tgz b/_test/tests/inc/tar/test.tgz deleted file mode 100644 index b00319649..000000000 Binary files a/_test/tests/inc/tar/test.tgz and /dev/null differ diff --git a/_test/tests/inc/tar/testdata1.txt b/_test/tests/inc/tar/testdata1.txt deleted file mode 100644 index ac65bb32e..000000000 --- a/_test/tests/inc/tar/testdata1.txt +++ /dev/null @@ -1 +0,0 @@ -testcontent1 diff --git a/_test/tests/inc/tar/zero.txt b/_test/tests/inc/tar/zero.txt deleted file mode 100644 index e69de29bb..000000000 -- cgit v1.2.3 From 26e22ab837dcabe137a0912fcd2f96d0c35f48c8 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 15 May 2015 19:03:34 +0200 Subject: Changes for PHP 7 Compatibility - replace PHP4 style class constructor function names (based on class name) with php 5 __construct() Also remove some '&' reference operators used with objects And add some object type hints --- _test/tests/inc/parser/lexer.test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/parser/lexer.test.php b/_test/tests/inc/parser/lexer.test.php index d0965a13e..c50665928 100644 --- a/_test/tests/inc/parser/lexer.test.php +++ b/_test/tests/inc/parser/lexer.test.php @@ -146,7 +146,7 @@ class TestOfLexerStateStack extends DokuWikiTest { } class TestParser { - function TestParser() { + function __construct() { } function accept() { } @@ -364,7 +364,7 @@ class TestOfLexerHandlers extends DokuWikiTest { class TestParserByteIndex { - function TestParserByteIndex() {} + function __construct() {} function ignore() {} -- cgit v1.2.3 From c248bda1dcbef2068071904057b8410aa1eb0200 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sat, 16 May 2015 17:40:33 +0200 Subject: fix missing language code parameter for admin plugin titles add unit test coverage --- _test/tests/inc/template_include_page.test.php | 77 +++++++++++++++++--------- 1 file changed, 52 insertions(+), 25 deletions(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/template_include_page.test.php b/_test/tests/inc/template_include_page.test.php index 47d4d46f1..580221979 100644 --- a/_test/tests/inc/template_include_page.test.php +++ b/_test/tests/inc/template_include_page.test.php @@ -1,40 +1,67 @@ assertEquals('', $sidebar); + function test_localID() { + global $ID,$ACT; + + + $id = 'foo:bar'; + + $ACT = 'show'; + $this->assertEquals('foo:bar', tpl_pagetitle($id, true)); } - function testExistingSidebars() { - global $ID; + function test_globalID() { + global $ID,$ACT; + - saveWikiText('sidebar', 'topsidebar-test', ''); + $ID = 'foo:bar'; - $ID = 'foo:bar:baz:test'; - $sidebar = tpl_include_page('sidebar', false, true); - $this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0); + $ACT = 'show'; + $this->assertEquals('foo:bar', tpl_pagetitle(null, true)); + } + + function test_adminTitle() { + global $ID,$ACT; - $ID = 'foo'; - $sidebar = tpl_include_page('sidebar', false, true); - $this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0); + $ID = 'foo:bar'; + + $ACT = 'admin'; + $this->assertEquals('Admin', tpl_pagetitle(null, true)); + } - saveWikiText('foo:bar:sidebar', 'bottomsidebar-test', ''); + function test_adminPluginTitle() { + global $ID,$ACT,$INPUT,$conf; - $ID = 'foo:bar:baz:test'; - $sidebar = tpl_include_page('sidebar', false, true); - $this->assertTrue(strpos($sidebar, 'bottomsidebar-test') > 0); + if (!plugin_load('admin','config')) { + $this->markTestSkipped('Plugin Config not found, unable to test admin plugin titles'); + return; + } - $ID = 'foo:bar:test'; - $sidebar = tpl_include_page('sidebar', false, true); - $this->assertTrue(strpos($sidebar, 'bottomsidebar-test') > 0); + $ID = 'foo:bar'; + $ACT = 'admin'; + $conf['lang'] = 'en'; + $INPUT->set('page','config'); - $ID = 'foo'; - $sidebar = tpl_include_page('sidebar', false, true); - $this->assertTrue(strpos($sidebar, 'topsidebar-test') > 0); + $this->assertEquals('Configuration Settings', tpl_pagetitle(null, true)); } + function test_nonPageFunctionTitle() { + global $ID,$ACT; + + $ID = 'foo:bar'; + + $ACT = 'index'; + $this->assertEquals('Sitemap', tpl_pagetitle(null, true)); + } + + function test_pageFunctionTitle() { + global $ID,$ACT; + + $ID = 'foo:bar'; + + $ACT = 'revisions'; + $this->assertEquals('foo:bar - Old revisions', tpl_pagetitle(null, true)); + } } -- cgit v1.2.3 From a61966c55d9d0ac4b800d65cfc6ee1aea44899b5 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sat, 16 May 2015 19:07:23 +0200 Subject: Provide a function to return admin plugin for the page request. This was previously carried out in three separate places. Refactor that code to use the new function. Update tpl_pageTitle test to use a manager level admin plugin. --- _test/tests/inc/template_include_page.test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to '_test/tests/inc') diff --git a/_test/tests/inc/template_include_page.test.php b/_test/tests/inc/template_include_page.test.php index 580221979..7dd13ba23 100644 --- a/_test/tests/inc/template_include_page.test.php +++ b/_test/tests/inc/template_include_page.test.php @@ -34,17 +34,17 @@ class template_pagetitle_test extends DokuWikiTest { function test_adminPluginTitle() { global $ID,$ACT,$INPUT,$conf; - if (!plugin_load('admin','config')) { - $this->markTestSkipped('Plugin Config not found, unable to test admin plugin titles'); + if (!plugin_load('admin','revert')) { + $this->markTestSkipped('Revert plugin not found, unable to test admin plugin titles'); return; } $ID = 'foo:bar'; $ACT = 'admin'; $conf['lang'] = 'en'; - $INPUT->set('page','config'); + $INPUT->set('page','revert'); - $this->assertEquals('Configuration Settings', tpl_pagetitle(null, true)); + $this->assertEquals('Revert Manager', tpl_pagetitle(null, true)); } function test_nonPageFunctionTitle() { -- 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/tests/inc') 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/tests/inc') 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/tests/inc') 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/tests/inc') 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/tests/inc') 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/tests/inc') 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/tests/inc') 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/tests/inc') 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/tests/inc') 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/tests/inc') 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/tests/inc') 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/tests/inc') 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