From 1ea7a6bada66fc9b7a45f61b4892e4ea23196d89 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 28 Jul 2012 14:55:45 +0200 Subject: support CONNECT for tunneling SSL via HTTP proxies FS#2431 The included test cases currently expect a squid at localhost:3128 --- _test/tests/inc/httpclient_http_proxy.test.php | 19 +++++++++++++++++++ _test/tests/inc/httpclient_https.test.php | 1 + _test/tests/inc/httpclient_https_proxy.test.php | 15 +++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 _test/tests/inc/httpclient_http_proxy.test.php create mode 100644 _test/tests/inc/httpclient_https_proxy.test.php (limited to '_test') diff --git a/_test/tests/inc/httpclient_http_proxy.test.php b/_test/tests/inc/httpclient_http_proxy.test.php new file mode 100644 index 000000000..81abdbca0 --- /dev/null +++ b/_test/tests/inc/httpclient_http_proxy.test.php @@ -0,0 +1,19 @@ +proxy_host = 'localhost'; //FIXME we need a public server + $http->proxy_port = 3128; + + $data = $http->get($this->url); + $this->assertFalse($data === false, 'HTTP response'); + $this->assertTrue(strpos($data,'DokuWiki') !== false, 'response content'); + } + +} \ No newline at end of file diff --git a/_test/tests/inc/httpclient_https.test.php b/_test/tests/inc/httpclient_https.test.php index 26a0f86db..955d467ec 100644 --- a/_test/tests/inc/httpclient_https.test.php +++ b/_test/tests/inc/httpclient_https.test.php @@ -1,4 +1,5 @@ markTestSkipped('No SSL support available.'); + } + parent::setUp(); + } +} \ No newline at end of file -- cgit v1.2.3 From 2240ea1f316156f3cb4475ea23a16246c999b6f0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 12:00:37 +0200 Subject: first start at refactoring the subscription system BROKEN This introduces a class for nicer wrapping and easier testing. Some functions were changed to provide nicer APIs (no throwing around of unescaped regexps) and to simplify things (hopefully). The refactoring isn't completed yet, so this will break the subscription system. The goal is to move as much subscription related stuff to this class as possible. Currently there is some code in lib/exe/indexer.php and maybe elsewhere (common.php?). Additionally everything should be covered by tests. A few tests are included here already. --- _test/tests/inc/subscription.test.php | 121 ++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 _test/tests/inc/subscription.test.php (limited to '_test') diff --git a/_test/tests/inc/subscription.test.php b/_test/tests/inc/subscription.test.php new file mode 100644 index 000000000..77bf3e830 --- /dev/null +++ b/_test/tests/inc/subscription.test.php @@ -0,0 +1,121 @@ +buildregex($test[0], $test[1], $test[2]); + $this->assertFalse(empty($re), "test line $row"); + $result = preg_grep($re, $data); + $this->assertEquals($test[3], count($result), "test line $row. $re got\n".print_r($result, true)); + + $row++; + } + } + + function test_addremove(){ + $sub = new MockupSubscription(); + + // no subscriptions + $this->assertArrayNotHasKey( + 'wiki:dokuwiki', + $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + ); + + // add page subscription + $sub->add('wiki:dokuwiki', 'testuser', 'every'); + + // one subscription + $this->assertArrayHasKey( + 'wiki:dokuwiki', + $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + ); + + // remove page subscription + $sub->remove('wiki:dokuwiki', 'testuser'); + + // no subscription + $this->assertArrayNotHasKey( + 'wiki:dokuwiki', + $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + ); + + // add namespace subscription + $sub->add('wiki:', 'testuser', 'every'); + + // one subscription + $this->assertArrayHasKey( + 'wiki:', + $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + ); + + // remove (non existing) page subscription + $sub->remove('wiki:dokuwiki', 'testuser'); + + // still one subscription + $this->assertArrayHasKey( + 'wiki:', + $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + ); + + // change namespace subscription + $sub->add('wiki:', 'testuser', 'digest', '1234567'); + + // still one subscription + $this->assertArrayHasKey( + 'wiki:', + $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + ); + + // check contents + $this->assertEquals( + array('wiki:' => array('testuser' => array('digest', '1234567'))), + $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + ); + } + + + +} + +/** + * makes protected methods visible for testing + */ +class MockupSubscription extends Subscription { + public function buildregex($user = null, $style = null, $data = null) { + return parent::buildregex($user, $style, $data); + } +} + +//Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From adec979fd5453cf213b776d7dceaaaac4eb05713 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 15:07:03 +0200 Subject: more subscription refactoring BROKEN now the actual sending of bulk messages (digest, list) is reimplemented and partially tested. Still not complete --- _test/tests/inc/subscription.test.php | 97 +++++++++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 15 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/subscription.test.php b/_test/tests/inc/subscription.test.php index 77bf3e830..b3d49a533 100644 --- a/_test/tests/inc/subscription.test.php +++ b/_test/tests/inc/subscription.test.php @@ -2,7 +2,7 @@ class subscription_test extends DokuWikiTest { - function test_regexp(){ + function test_regexp() { // data to test against $data = array( "casper every\n", @@ -19,13 +19,13 @@ class subscription_test extends DokuWikiTest { array('casper', null, null, 1), array('nope', null, null, 0), array('lights', null, null, 0), - array(array('Cold Fusion','casper','nope'), null, null, 2), + array(array('Cold Fusion', 'casper', 'nope'), null, null, 2), array(null, 'list', null, 1), array(null, 'every', null, 2), array(null, 'digest', null, 3), array(null, array('list', 'every'), null, 3), array('casper', 'digest', null, 0), - array('casper', array('digest','every'), null, 1), + array('casper', array('digest', 'every'), null, 1), array('zioth', 'list', '1344691369', 1), array('zioth', null, '1344691369', 1), array('zioth', 'digest', '1344691369', 0), @@ -34,7 +34,7 @@ class subscription_test extends DokuWikiTest { $sub = new MockupSubscription(); $row = 0; - foreach($tests as $test){ + foreach($tests as $test) { $re = $sub->buildregex($test[0], $test[1], $test[2]); $this->assertFalse(empty($re), "test line $row"); $result = preg_grep($re, $data); @@ -44,13 +44,13 @@ class subscription_test extends DokuWikiTest { } } - function test_addremove(){ + function test_addremove() { $sub = new MockupSubscription(); // no subscriptions $this->assertArrayNotHasKey( 'wiki:dokuwiki', - $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) ); // add page subscription @@ -59,7 +59,7 @@ class subscription_test extends DokuWikiTest { // one subscription $this->assertArrayHasKey( 'wiki:dokuwiki', - $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) ); // remove page subscription @@ -68,7 +68,7 @@ class subscription_test extends DokuWikiTest { // no subscription $this->assertArrayNotHasKey( 'wiki:dokuwiki', - $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) ); // add namespace subscription @@ -77,7 +77,7 @@ class subscription_test extends DokuWikiTest { // one subscription $this->assertArrayHasKey( 'wiki:', - $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) ); // remove (non existing) page subscription @@ -86,7 +86,7 @@ class subscription_test extends DokuWikiTest { // still one subscription $this->assertArrayHasKey( 'wiki:', - $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) ); // change namespace subscription @@ -95,17 +95,66 @@ class subscription_test extends DokuWikiTest { // still one subscription $this->assertArrayHasKey( 'wiki:', - $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) ); // check contents $this->assertEquals( array('wiki:' => array('testuser' => array('digest', '1234567'))), - $sub->subscribers('wiki:dokuwiki', null, array('every','list','digest')) + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) + ); + + // change subscription data + $sub->add('wiki:', 'testuser', 'digest', '7654321'); + + // still one subscription + $this->assertArrayHasKey( + 'wiki:', + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) + ); + + // check contents + $this->assertEquals( + array('wiki:' => array('testuser' => array('digest', '7654321'))), + $sub->subscribers('wiki:dokuwiki', null, array('every', 'list', 'digest')) ); } + function test_bulkdigest(){ + $sub = new MockupSubscription(); + + // let's start with nothing + $this->assertEquals(0, $sub->send_bulk('sub1:test')); + + // create a subscription + $sub->add('sub1:', 'testuser', 'digest', '978328800'); // last mod 2001-01-01 + + // now create change + $_SERVER['REMOTE_USER'] = 'someguy'; + saveWikiText('sub1:test', 'foo bar', 'a subscription change', false); + // should trigger a mail + $this->assertEquals(1, $sub->send_bulk('sub1:test')); + $this->assertEquals(array('arthur@example.com'), $sub->mails); + + $sub->reset(); + + // now create more changes + $_SERVER['REMOTE_USER'] = 'someguy'; + saveWikiText('sub1:sub2:test', 'foo bar', 'a subscription change', false); + saveWikiText('sub1:another_test', 'foo bar', 'a subscription change', false); + + // should not trigger a mail, because the subscription time has not been reached, yet + $this->assertEquals(0, $sub->send_bulk('sub1:test')); + $this->assertEquals(array(), $sub->mails); + + // reset the subscription time + $sub->add('sub1:', 'testuser', 'digest', '978328800'); // last mod 2001-01-01 + + // we now should get mails for three changes + $this->assertEquals(3, $sub->send_bulk('sub1:test')); + $this->assertEquals(array('arthur@example.com','arthur@example.com','arthur@example.com'), $sub->mails); + } } @@ -113,9 +162,27 @@ class subscription_test extends DokuWikiTest { * makes protected methods visible for testing */ class MockupSubscription extends Subscription { - public function buildregex($user = null, $style = null, $data = null) { - return parent::buildregex($user, $style, $data); - } + public $mails; // we keep sent mails here + + public function __construct(){ + $this->reset(); + } + + /** + * resets the mail array + */ + public function reset(){ + $this->mails = array(); + } + + public function buildregex($user = null, $style = null, $data = null) { + return parent::buildregex($user, $style, $data); + } + + protected function send($subscriber_mail, $replaces, $subject, $id, $template){ + $this->mails[] = $subscriber_mail; + return true; + } } //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 8c7bcacde38ed7306d14a7e5769d6d1f2f8b9a21 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 16:50:37 +0200 Subject: added list test --- _test/tests/inc/subscription.test.php | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/subscription.test.php b/_test/tests/inc/subscription.test.php index b3d49a533..be2e68b74 100644 --- a/_test/tests/inc/subscription.test.php +++ b/_test/tests/inc/subscription.test.php @@ -156,6 +156,43 @@ class subscription_test extends DokuWikiTest { $this->assertEquals(array('arthur@example.com','arthur@example.com','arthur@example.com'), $sub->mails); } + function test_bulklist(){ + $sub = new MockupSubscription(); + + // let's start with nothing + $this->assertEquals(0, $sub->send_bulk('sub1:test')); + + // create a subscription + $sub->add('sub1:', 'testuser', 'list', '978328800'); // last mod 2001-01-01 + + // now create change + $_SERVER['REMOTE_USER'] = 'someguy'; + saveWikiText('sub1:test', 'foo bar', 'a subscription change', false); + + // should trigger a mail + $this->assertEquals(1, $sub->send_bulk('sub1:test')); + $this->assertEquals(array('arthur@example.com'), $sub->mails); + + $sub->reset(); + + // now create more changes + $_SERVER['REMOTE_USER'] = 'someguy'; + saveWikiText('sub1:sub2:test', 'foo bar', 'a subscription change', false); + saveWikiText('sub1:another_test', 'foo bar', 'a subscription change', false); + + // should not trigger a mail, because the subscription time has not been reached, yet + $this->assertEquals(0, $sub->send_bulk('sub1:test')); + $this->assertEquals(array(), $sub->mails); + + // reset the subscription time + $sub->add('sub1:', 'testuser', 'list', '978328800'); // last mod 2001-01-01 + + // we now should get a single mail for all three changes + $this->assertEquals(1, $sub->send_bulk('sub1:test')); + $this->assertEquals(array('arthur@example.com'), $sub->mails); + } + + } /** -- cgit v1.2.3 From 84c1127cc070777c8cbcf488f5422bc4b71470a8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 17:30:01 +0200 Subject: correctly check if subscriptions are enabled --- _test/tests/inc/subscription.test.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/subscription.test.php b/_test/tests/inc/subscription.test.php index be2e68b74..80548160a 100644 --- a/_test/tests/inc/subscription.test.php +++ b/_test/tests/inc/subscription.test.php @@ -212,6 +212,10 @@ class MockupSubscription extends Subscription { $this->mails = array(); } + public function isenabled(){ + return true; + } + public function buildregex($user = null, $style = null, $data = null) { return parent::buildregex($user, $style, $data); } -- cgit v1.2.3 From 2ed38036a53a489d2fcadc46ce601f8c876fca31 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 21 Sep 2012 11:53:17 +0200 Subject: consolidate more notification code in subscription class This is untested and probably broken currently --- _test/tests/inc/subscription.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '_test') diff --git a/_test/tests/inc/subscription.test.php b/_test/tests/inc/subscription.test.php index 80548160a..c6f33dec7 100644 --- a/_test/tests/inc/subscription.test.php +++ b/_test/tests/inc/subscription.test.php @@ -220,7 +220,7 @@ class MockupSubscription extends Subscription { return parent::buildregex($user, $style, $data); } - protected function send($subscriber_mail, $replaces, $subject, $id, $template){ + protected function send($subscriber_mail, $subject, $id, $template, $trep, $hrep){ $this->mails[] = $subscriber_mail; return true; } -- cgit v1.2.3 From bee9f377bc547c99fe99b4e38199cb92cf668554 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 3 Nov 2012 17:54:02 +0100 Subject: Completely rewritten Tar library This new class is only losely based on our previous library. The whole API was changed to make it more flexible and memory saving. Some fisrt unit tests are included --- _test/tests/inc/tar.test.php | 134 +++++++++++++++++++++++++++++++ _test/tests/inc/tar/foobar/testdata2.txt | 1 + _test/tests/inc/tar/test.tar | Bin 0 -> 10240 bytes _test/tests/inc/tar/test.tbz | Bin 0 -> 217 bytes _test/tests/inc/tar/test.tgz | Bin 0 -> 220 bytes _test/tests/inc/tar/testdata1.txt | 1 + _test/tests/inc/tarlib.test.php | 0 7 files changed, 136 insertions(+) create mode 100644 _test/tests/inc/tar.test.php create mode 100644 _test/tests/inc/tar/foobar/testdata2.txt create mode 100644 _test/tests/inc/tar/test.tar create mode 100644 _test/tests/inc/tar/test.tbz create mode 100644 _test/tests/inc/tar/test.tgz create mode 100644 _test/tests/inc/tar/testdata1.txt delete mode 100644 _test/tests/inc/tarlib.test.php (limited to '_test') diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php new file mode 100644 index 000000000..706516d9e --- /dev/null +++ b/_test/tests/inc/tar.test.php @@ -0,0 +1,134 @@ +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'); + + $this->assertTrue(strpos($data, "$dir/testdata1.txt") !== false, 'Path in TAR'); + $this->assertTrue(strpos($data, 'noway/testdata2.txt') !== false, 'Path in TAR'); + $this->assertTrue(strpos($data, 'another/testdata3.txt') !== false, 'Path in TAR'); + + $this->assertTrue(strpos($data, "$dir/foobar/testdata2.txt") === false, 'Path 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'; + $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'); + + $this->assertTrue(strpos($data, "$dir/testdata1.txt") !== false, 'Path in TAR'); + $this->assertTrue(strpos($data, 'noway/testdata2.txt') !== false, 'Path in TAR'); + $this->assertTrue(strpos($data, 'another/testdata3.txt') !== false, 'Path in TAR'); + + $this->assertTrue(strpos($data, "$dir/foobar/testdata2.txt") === false, 'Path 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(array('tar','tgz','tbz') 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(array('tar', 'tgz', 'tbz') 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); + } + + } + + /** + * 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')); + } +} \ No newline at end of file diff --git a/_test/tests/inc/tar/foobar/testdata2.txt b/_test/tests/inc/tar/foobar/testdata2.txt new file mode 100644 index 000000000..a7db15771 --- /dev/null +++ b/_test/tests/inc/tar/foobar/testdata2.txt @@ -0,0 +1 @@ +testcontent2 diff --git a/_test/tests/inc/tar/test.tar b/_test/tests/inc/tar/test.tar new file mode 100644 index 000000000..931866b0b Binary files /dev/null and b/_test/tests/inc/tar/test.tar differ diff --git a/_test/tests/inc/tar/test.tbz b/_test/tests/inc/tar/test.tbz new file mode 100644 index 000000000..5a7374019 Binary files /dev/null and b/_test/tests/inc/tar/test.tbz differ diff --git a/_test/tests/inc/tar/test.tgz b/_test/tests/inc/tar/test.tgz new file mode 100644 index 000000000..b00319649 Binary files /dev/null and b/_test/tests/inc/tar/test.tgz differ diff --git a/_test/tests/inc/tar/testdata1.txt b/_test/tests/inc/tar/testdata1.txt new file mode 100644 index 000000000..ac65bb32e --- /dev/null +++ b/_test/tests/inc/tar/testdata1.txt @@ -0,0 +1 @@ +testcontent1 diff --git a/_test/tests/inc/tarlib.test.php b/_test/tests/inc/tarlib.test.php deleted file mode 100644 index e69de29bb..000000000 -- cgit v1.2.3 From 7252880f21c842017c334eb15c6a7a174f950798 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 3 Nov 2012 18:30:52 +0100 Subject: added test cases for Tar::extract parameters --- _test/tests/inc/tar.test.php | 103 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php index 706516d9e..4de9e668d 100644 --- a/_test/tests/inc/tar.test.php +++ b/_test/tests/inc/tar.test.php @@ -113,9 +113,112 @@ class Tar_TestCase extends DokuWikiTest { 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(array('tar', 'tgz', 'tbz') 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(array('tar', 'tgz', 'tbz') 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(array('tar', 'tgz', 'tbz') 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(array('tar', 'tgz', 'tbz') 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 */ -- cgit v1.2.3 From 421a2704022cbc8fa07ab673c2d503199f460b8e Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 4 Nov 2012 10:36:58 +0100 Subject: Tar: Added extraction support for long file names Supports POSIX ustar prefixes and GNU longlink entries --- _test/tests/inc/tar.test.php | 17 ++++++++++++++++- _test/tests/inc/tar/longpath-gnu.tgz | Bin 0 -> 413 bytes _test/tests/inc/tar/longpath-ustar.tgz | Bin 0 -> 311 bytes 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 _test/tests/inc/tar/longpath-gnu.tgz create mode 100644 _test/tests/inc/tar/longpath-ustar.tgz (limited to '_test') diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php index 4de9e668d..9abd27612 100644 --- a/_test/tests/inc/tar.test.php +++ b/_test/tests/inc/tar.test.php @@ -218,7 +218,6 @@ class Tar_TestCase extends DokuWikiTest { } } - /** * Check the extension to compression guesser */ @@ -234,4 +233,20 @@ class Tar_TestCase extends DokuWikiTest { $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.BZ2')); $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.bz2')); } + + 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); + } + } + } \ No newline at end of file diff --git a/_test/tests/inc/tar/longpath-gnu.tgz b/_test/tests/inc/tar/longpath-gnu.tgz new file mode 100644 index 000000000..6c937c8fe Binary files /dev/null and b/_test/tests/inc/tar/longpath-gnu.tgz differ diff --git a/_test/tests/inc/tar/longpath-ustar.tgz b/_test/tests/inc/tar/longpath-ustar.tgz new file mode 100644 index 000000000..59efbff66 Binary files /dev/null and b/_test/tests/inc/tar/longpath-ustar.tgz differ -- cgit v1.2.3 From 90a1db709d3590e849a5a4966fbdf8fb58ae75cd Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 4 Nov 2012 11:31:20 +0100 Subject: Tar: support for creating archives with long filenames The library now creates either a POSIX ustar prefix or a GNU longlink entry for files which have a name longer than 100 bytes --- _test/tests/inc/tar.test.php | 97 +++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 24 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php index 9abd27612..47851fd4c 100644 --- a/_test/tests/inc/tar.test.php +++ b/_test/tests/inc/tar.test.php @@ -8,7 +8,7 @@ class Tar_TestCase extends DokuWikiTest { * * No check for format correctness */ - public function test_createdynamic(){ + public function test_createdynamic() { $tar = new Tar(); $dir = dirname(__FILE__).'/tar'; @@ -38,7 +38,7 @@ class Tar_TestCase extends DokuWikiTest { * * No check for format correctness */ - public function test_createfile(){ + public function test_createfile() { $tar = new Tar(); $dir = dirname(__FILE__).'/tar'; @@ -70,10 +70,10 @@ class Tar_TestCase extends DokuWikiTest { /** * List the contents of the prebuilt TAR files */ - public function test_tarcontent(){ + public function test_tarcontent() { $dir = dirname(__FILE__).'/tar'; - foreach(array('tar','tgz','tbz') as $ext){ + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -92,11 +92,11 @@ class Tar_TestCase extends DokuWikiTest { /** * Extract the prebuilt tar files */ - public function test_tarextract(){ + public function test_tarextract() { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext){ + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -118,16 +118,16 @@ class Tar_TestCase extends DokuWikiTest { /** * Extract the prebuilt tar files with component stripping */ - public function test_compstripextract(){ + public function test_compstripextract() { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext){ + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; $tar->open($file); - $tar->extract($out,1); + $tar->extract($out, 1); clearstatcache(); @@ -144,16 +144,16 @@ class Tar_TestCase extends DokuWikiTest { /** * Extract the prebuilt tar files with prefix stripping */ - public function test_prefixstripextract(){ + public function test_prefixstripextract() { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext){ + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; $tar->open($file); - $tar->extract($out,'tar/foobar/'); + $tar->extract($out, 'tar/foobar/'); clearstatcache(); @@ -170,22 +170,21 @@ class Tar_TestCase extends DokuWikiTest { /** * Extract the prebuilt tar files with include regex */ - public function test_includeextract(){ + public function test_includeextract() { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext){ + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; $tar->open($file); - $tar->extract($out,'','','/\/foobar\//'); + $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"); @@ -196,16 +195,16 @@ class Tar_TestCase extends DokuWikiTest { /** * Extract the prebuilt tar files with exclude regex */ - public function test_excludeextract(){ + public function test_excludeextract() { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext){ + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; $tar->open($file); - $tar->extract($out,'','/\/foobar\//'); + $tar->extract($out, '', '/\/foobar\//'); clearstatcache(); @@ -221,8 +220,8 @@ class Tar_TestCase extends DokuWikiTest { /** * Check the extension to compression guesser */ - public function test_filetype(){ - $tar = new Tar(); + 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')); @@ -234,12 +233,12 @@ class Tar_TestCase extends DokuWikiTest { $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.bz2')); } - public function test_longpathextract(){ + 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(); + foreach(array('ustar', 'gnu') as $format) { + $tar = new Tar(); $tar->open("$dir/longpath-$format.tgz"); $tar->extract($out); @@ -249,4 +248,54 @@ class Tar_TestCase extends DokuWikiTest { } } + 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); + } + } \ No newline at end of file -- cgit v1.2.3 From 2949ece61602372cf55fba6be4522fa8899fb70d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 4 Nov 2012 12:21:47 +0100 Subject: unit test for tar bombs --- _test/tests/inc/tar.test.php | 18 ++++++++++++++++++ _test/tests/inc/tar/tarbomb.tgz | Bin 0 -> 183 bytes 2 files changed, 18 insertions(+) create mode 100644 _test/tests/inc/tar/tarbomb.tgz (limited to '_test') diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php index 47851fd4c..e8805a75d 100644 --- a/_test/tests/inc/tar.test.php +++ b/_test/tests/inc/tar.test.php @@ -298,4 +298,22 @@ class Tar_TestCase extends DokuWikiTest { @unlink($tmp); } + /** + * Extract a tarbomomb + */ + 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); + } } \ No newline at end of file diff --git a/_test/tests/inc/tar/tarbomb.tgz b/_test/tests/inc/tar/tarbomb.tgz new file mode 100644 index 000000000..8418d4073 Binary files /dev/null and b/_test/tests/inc/tar/tarbomb.tgz differ -- cgit v1.2.3 From a20ce704cbd26eccbca8bf01dadac23a1432e1a5 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 8 Nov 2012 23:24:57 +0100 Subject: changed proxy in test case --- _test/tests/inc/httpclient_http_proxy.test.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/httpclient_http_proxy.test.php b/_test/tests/inc/httpclient_http_proxy.test.php index 81abdbca0..faa7a4280 100644 --- a/_test/tests/inc/httpclient_http_proxy.test.php +++ b/_test/tests/inc/httpclient_http_proxy.test.php @@ -8,8 +8,9 @@ class httpclient_http_proxy_test extends DokuWikiTest { */ function test_simpleget(){ $http = new HTTPClient(); - $http->proxy_host = 'localhost'; //FIXME we need a public server - $http->proxy_port = 3128; + // proxy provided by Andrwe Lord Weber + $http->proxy_host = 'proxy.andrwe.org'; + $http->proxy_port = 8080; $data = $http->get($this->url); $this->assertFalse($data === false, 'HTTP response'); -- cgit v1.2.3 From 1f61f312a78e212aaa4a4bc3f60961036ec07fd7 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Fri, 23 Nov 2012 18:48:09 +0100 Subject: remove empty BCC/CC mail headers Empty BCC/CC headers may cause errors on IIS. --- _test/tests/inc/mailer.test.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/mailer.test.php b/_test/tests/inc/mailer.test.php index b2c74a257..91c4a999d 100644 --- a/_test/tests/inc/mailer.test.php +++ b/_test/tests/inc/mailer.test.php @@ -7,6 +7,14 @@ class TestMailer extends Mailer { public function prop($name){ return $this->$name; } + + public function &propRef($name) { + return $this->$name; + } + + public function prepareHeaders() { + return parent::prepareHeaders(); + } } class mailer_test extends DokuWikiTest { @@ -90,5 +98,14 @@ class mailer_test extends DokuWikiTest { } } + function test_emptyBCCorCC() { + $mail = new TestMailer(); + $headers = &$mail->propRef('headers'); + $headers['Bcc'] = ''; + $headers['Cc'] = ''; + $header = $mail->prepareHeaders(); + $this->assertEquals(0, preg_match('/(^|\n)Bcc: (\n|$)/', $header), 'Bcc found in headers.'); + $this->assertEquals(0, preg_match('/(^|\n)Cc: (\n|$)/', $header), 'Bcc found in headers.'); + } } //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 91effd8de07e4afc59b6763ac72b268f58cfc941 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Fri, 23 Nov 2012 19:55:44 +0100 Subject: ignore empty header on mail sending --- _test/tests/inc/mailer.test.php | 3 +++ 1 file changed, 3 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/mailer.test.php b/_test/tests/inc/mailer.test.php index 91c4a999d..053e216b8 100644 --- a/_test/tests/inc/mailer.test.php +++ b/_test/tests/inc/mailer.test.php @@ -98,6 +98,9 @@ class mailer_test extends DokuWikiTest { } } + /** + * @see https://forum.dokuwiki.org/post/35822 + */ function test_emptyBCCorCC() { $mail = new TestMailer(); $headers = &$mail->propRef('headers'); -- cgit v1.2.3 From eb3ce0d55290dd4a60193e680aa50b46571350bd Mon Sep 17 00:00:00 2001 From: Kazutaka Miyasaka Date: Sun, 25 Nov 2012 21:02:32 +0900 Subject: Fix case-insensitive match in ACL checking ACL checking of DokuWiki is currently always case-sensitive regardless of auth backend setting ($auth->isCaseSensitive). This commit enables case-insensitive match in the same way of auth_isMember(). --- .../inc/auth_aclcheck_caseinsensitive.test.php | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 _test/tests/inc/auth_aclcheck_caseinsensitive.test.php (limited to '_test') diff --git a/_test/tests/inc/auth_aclcheck_caseinsensitive.test.php b/_test/tests/inc/auth_aclcheck_caseinsensitive.test.php new file mode 100644 index 000000000..9f1fb6aa0 --- /dev/null +++ b/_test/tests/inc/auth_aclcheck_caseinsensitive.test.php @@ -0,0 +1,131 @@ +oldConf = $conf; + $this->oldAuth = $auth; + $this->oldAuthAcl = $AUTH_ACL; + + $auth = new auth_acl_caseinsensitive_auth(); + } + + function teardown() { + global $conf; + global $AUTH_ACL; + global $auth; + + $conf = $this->oldConf; + $auth = $this->oldAuth; + $AUTH_ACL = $this->oldAuthAcl; + } + + function test_multiadmin_restricted_ropage() { + global $conf; + global $AUTH_ACL; + + $conf['superuser'] = 'John,doe,@Admin1,@admin2'; + $conf['useacl'] = 1; + + $AUTH_ACL = array( + '* @ALL 0', + '* @Group1 8', + '* @group2 8', + 'namespace:page @Group1 1', + 'namespace:page @group2 1', + ); + + // anonymous user + $this->assertEquals(auth_aclcheck('page', '', array()), AUTH_NONE); + $this->assertEquals(auth_aclcheck('namespace:page', '', array()), AUTH_NONE); + $this->assertEquals(auth_aclcheck('namespace:*', '', array()), AUTH_NONE); + + // user with no matching group + $this->assertEquals(auth_aclcheck('page', 'jill', array('foo')), AUTH_NONE); + $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo')), AUTH_NONE); + $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo')), AUTH_NONE); + + // user with matching group 1 + $this->assertEquals(auth_aclcheck('page', 'jill', array('foo', 'group1')), AUTH_UPLOAD); + $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo', 'group1')), AUTH_READ); + $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo', 'group1')), AUTH_UPLOAD); + + // user with matching group 2 + $this->assertEquals(auth_aclcheck('page', 'jill', array('foo', 'Group2')), AUTH_UPLOAD); + $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo', 'Group2')), AUTH_READ); + $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo', 'Group2')), AUTH_UPLOAD); + + // super user John + $this->assertEquals(auth_aclcheck('page', 'john', array('foo')), AUTH_ADMIN); + $this->assertEquals(auth_aclcheck('namespace:page', 'john', array('foo')), AUTH_ADMIN); + $this->assertEquals(auth_aclcheck('namespace:*', 'john', array('foo')), AUTH_ADMIN); + + // super user doe + $this->assertEquals(auth_aclcheck('page', 'Doe', array('foo')), AUTH_ADMIN); + $this->assertEquals(auth_aclcheck('namespace:page', 'Doe', array('foo')), AUTH_ADMIN); + $this->assertEquals(auth_aclcheck('namespace:*', 'Doe', array('foo')), AUTH_ADMIN); + + // user with matching admin group 1 + $this->assertEquals(auth_aclcheck('page', 'jill', array('foo', 'admin1')), AUTH_ADMIN); + $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo', 'admin1')), AUTH_ADMIN); + $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo', 'admin1')), AUTH_ADMIN); + + // user with matching admin group 2 + $this->assertEquals(auth_aclcheck('page', 'jill', array('foo', 'Admin2')), AUTH_ADMIN); + $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo', 'Admin2')), AUTH_ADMIN); + $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo', 'Admin2')), AUTH_ADMIN); + } + + /* + * Test aclcheck on @ALL group + * + * The default permission for @ALL group is AUTH_NONE. So we use an + * ACL entry which grants @ALL group an AUTH_READ permission to see + * whether ACL matching is properly done or not. + */ + function test_restricted_allread() { + global $conf; + global $AUTH_ACL; + + $conf['superuser'] = 'john'; + $conf['useacl'] = 1; + + $AUTH_ACL = array( + '* @ALL 1', + '* @group1 8', + ); + + // anonymous user + $this->assertEquals(auth_aclcheck('page', '', array()), AUTH_READ); + $this->assertEquals(auth_aclcheck('namespace:page', '', array()), AUTH_READ); + $this->assertEquals(auth_aclcheck('namespace:*', '', array()), AUTH_READ); + + // user with no matching group + $this->assertEquals(auth_aclcheck('page', 'jill', array('foo')), AUTH_READ); + $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo')), AUTH_READ); + $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo')), AUTH_READ); + + // user with matching group + $this->assertEquals(auth_aclcheck('page', 'jill', array('foo', 'Group1')), AUTH_UPLOAD); + $this->assertEquals(auth_aclcheck('namespace:page', 'jill', array('foo', 'Group1')), AUTH_UPLOAD); + $this->assertEquals(auth_aclcheck('namespace:*', 'jill', array('foo', 'Group1')), AUTH_UPLOAD); + + // super user + $this->assertEquals(auth_aclcheck('page', 'John', array('foo')), AUTH_ADMIN); + $this->assertEquals(auth_aclcheck('namespace:page', 'John', array('foo')), AUTH_ADMIN); + $this->assertEquals(auth_aclcheck('namespace:*', 'John', array('foo')), AUTH_ADMIN); + } +} -- cgit v1.2.3 From ff576d9309a9a8c229caea79f2f8509cc986eee4 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Thu, 29 Nov 2012 14:59:46 +0100 Subject: use correct setUp method and parent calls. --- _test/tests/inc/auth_aclcheck.test.php | 10 +++------- _test/tests/inc/auth_aclcheck_caseinsensitive.test.php | 9 +++------ _test/tests/inc/auth_admincheck.test.php | 5 ++--- _test/tests/inc/auth_nameencode.test.php | 2 +- _test/tests/inc/parser/parser.inc.php | 3 ++- _test/tests/inc/parser/parser_footnote.test.php | 4 ++-- _test/tests/inc/parser/parser_quotes.test.php | 4 ++-- _test/tests/inc/remote.test.php | 5 +---- 8 files changed, 16 insertions(+), 26 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/auth_aclcheck.test.php b/_test/tests/inc/auth_aclcheck.test.php index 991f82da7..8e5a04ff5 100644 --- a/_test/tests/inc/auth_aclcheck.test.php +++ b/_test/tests/inc/auth_aclcheck.test.php @@ -2,22 +2,18 @@ class auth_acl_test extends DokuWikiTest { - var $oldConf; var $oldAuthAcl; - function setup() { - global $conf; + function setUp() { + parent::setUp(); global $AUTH_ACL; global $auth; - $this->oldConf = $conf; $this->oldAuthAcl = $AUTH_ACL; $auth = new auth_basic(); } - function teardown() { - global $conf; + function tearDown() { global $AUTH_ACL; - $conf = $this->oldConf; $AUTH_ACL = $this->oldAuthAcl; } diff --git a/_test/tests/inc/auth_aclcheck_caseinsensitive.test.php b/_test/tests/inc/auth_aclcheck_caseinsensitive.test.php index 9f1fb6aa0..2f4821c2d 100644 --- a/_test/tests/inc/auth_aclcheck_caseinsensitive.test.php +++ b/_test/tests/inc/auth_aclcheck_caseinsensitive.test.php @@ -7,28 +7,25 @@ class auth_acl_caseinsensitive_auth extends auth_basic { } class auth_acl_caseinsensitive_test extends DokuWikiTest { - protected $oldConf; protected $oldAuth; protected $oldAuthAcl; - function setup() { - global $conf; + function setUp() { + parent::setUp(); global $auth; global $AUTH_ACL; - $this->oldConf = $conf; $this->oldAuth = $auth; $this->oldAuthAcl = $AUTH_ACL; $auth = new auth_acl_caseinsensitive_auth(); } - function teardown() { + function tearDown() { global $conf; global $AUTH_ACL; global $auth; - $conf = $this->oldConf; $auth = $this->oldAuth; $AUTH_ACL = $this->oldAuthAcl; } diff --git a/_test/tests/inc/auth_admincheck.test.php b/_test/tests/inc/auth_admincheck.test.php index d88399cbe..17424a08e 100644 --- a/_test/tests/inc/auth_admincheck.test.php +++ b/_test/tests/inc/auth_admincheck.test.php @@ -10,7 +10,8 @@ class auth_admin_test extends DokuWikiTest { private $oldauth; - function setup() { + function setUp() { + parent::setUp(); global $auth; $this->oldauth = $auth; } @@ -27,9 +28,7 @@ class auth_admin_test extends DokuWikiTest { function teardown() { global $auth; - global $conf; global $AUTH_ACL; - unset($conf); unset($AUTH_ACL); $auth = $this->oldauth; } diff --git a/_test/tests/inc/auth_nameencode.test.php b/_test/tests/inc/auth_nameencode.test.php index 21db304e0..da9f31f90 100644 --- a/_test/tests/inc/auth_nameencode.test.php +++ b/_test/tests/inc/auth_nameencode.test.php @@ -2,7 +2,7 @@ class auth_nameencode_test extends DokuWikiTest { - function teardown() { + function tearDown() { global $cache_authname; $cache_authname = array(); } diff --git a/_test/tests/inc/parser/parser.inc.php b/_test/tests/inc/parser/parser.inc.php index e9efef0d3..61f15678b 100644 --- a/_test/tests/inc/parser/parser.inc.php +++ b/_test/tests/inc/parser/parser.inc.php @@ -8,7 +8,8 @@ abstract class TestOfDoku_Parser extends PHPUnit_Framework_TestCase { var $P; var $H; - function setup() { + function setUp() { + parent::setUp(); $this->P = new Doku_Parser(); $this->H = new Doku_Handler(); $this->P->Handler = & $this->H; diff --git a/_test/tests/inc/parser/parser_footnote.test.php b/_test/tests/inc/parser/parser_footnote.test.php index f3b5ddf56..b47a575de 100644 --- a/_test/tests/inc/parser/parser_footnote.test.php +++ b/_test/tests/inc/parser/parser_footnote.test.php @@ -3,8 +3,8 @@ require_once 'parser.inc.php'; class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser { - function setup() { - parent::setup(); + function setUp() { + parent::setUp(); $this->P->addMode('footnote',new Doku_Parser_Mode_Footnote()); } diff --git a/_test/tests/inc/parser/parser_quotes.test.php b/_test/tests/inc/parser/parser_quotes.test.php index b2dae1039..b82328212 100644 --- a/_test/tests/inc/parser/parser_quotes.test.php +++ b/_test/tests/inc/parser/parser_quotes.test.php @@ -3,8 +3,8 @@ require_once 'parser.inc.php'; class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser { - function setup() { - parent::setup(); + function setUp() { + parent::setUp(); global $conf; $conf['typography'] = 2; } diff --git a/_test/tests/inc/remote.test.php b/_test/tests/inc/remote.test.php index 49152d8db..611e1ab0f 100644 --- a/_test/tests/inc/remote.test.php +++ b/_test/tests/inc/remote.test.php @@ -112,12 +112,12 @@ class remote_plugin_testplugin extends DokuWiki_Remote_Plugin { class remote_test extends DokuWikiTest { - var $originalConf; var $userinfo; var $remote; function setUp() { + parent::setUp(); global $plugin_controller; global $conf; global $USERINFO; @@ -131,7 +131,6 @@ class remote_test extends DokuWikiTest { $plugin_controller = $pluginManager; - $this->originalConf = $conf; $conf['remote'] = 1; $conf['remoteuser'] = '!!not set!!'; $conf['useacl'] = 0; @@ -143,9 +142,7 @@ class remote_test extends DokuWikiTest { } function tearDown() { - global $conf; global $USERINFO; - $conf = $this->originalConf; $USERINFO = $this->userinfo; } -- cgit v1.2.3 From 0572700e3546546abe8375a0fff7245673f2b02a Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 4 Dec 2012 15:35:00 +0100 Subject: Indexer: Add test case for the PID functions --- _test/tests/inc/indexer_pid.test.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 _test/tests/inc/indexer_pid.test.php (limited to '_test') diff --git a/_test/tests/inc/indexer_pid.test.php b/_test/tests/inc/indexer_pid.test.php new file mode 100644 index 000000000..8c58b1abd --- /dev/null +++ b/_test/tests/inc/indexer_pid.test.php @@ -0,0 +1,18 @@ + + */ +class indexer_pid_test extends DokuWikiTest { + function test_pid() { + $indexer = idx_get_indexer(); + $syntaxPID = $indexer->getPID('wiki:syntax'); + $this->assertEquals('wiki:syntax', $indexer->getPageFromPID($syntaxPID), 'getPageFromPID(getPID(\'wiki:syntax\')) != \'wiki:syntax\''); + $dokuwikiPID = $indexer->getPID('wiki:dokuwiki'); + $this->assertEquals('wiki:syntax', $indexer->getPageFromPID($syntaxPID), 'getPageFromPID(getPID(\'wiki:syntax\')) != \'wiki:syntax\' after getting the PID for wiki:dokuwiki'); + $this->assertEquals($syntaxPID, $indexer->getPID('wiki:syntax'), 'getPID(\'wiki:syntax\') didn\'t returned different PIDs when called twice'); + $this->assertNotEquals($syntaxPID, $dokuwikiPID, 'Same PID returned for different pages'); + $this->assertTrue(is_numeric($syntaxPID) && is_numeric($dokuwikiPID), 'PIDs are not numeric'); + } +} -- cgit v1.2.3 From 4f7083212993bf72f0b8969e6d57f587faaa5dfc Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Thu, 20 Dec 2012 17:47:39 +0100 Subject: Remove global $Indexer, clear index in the testing system instead --- _test/core/DokuWikiTest.php | 2 ++ 1 file changed, 2 insertions(+) (limited to '_test') diff --git a/_test/core/DokuWikiTest.php b/_test/core/DokuWikiTest.php index b9e151456..91eb5293b 100644 --- a/_test/core/DokuWikiTest.php +++ b/_test/core/DokuWikiTest.php @@ -30,6 +30,8 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase { // remove any leftovers from the last run if(is_dir(DOKU_TMP_DATA)){ + // clear indexer data and cache + idx_get_indexer()->clear(); TestUtils::rdelete(DOKU_TMP_DATA); } -- cgit v1.2.3 From 629196125e06679f0f7111b6b4ce740d28db8a99 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Tue, 8 Jan 2013 09:38:39 +0100 Subject: allow template unit tests --- _test/phpunit.xml | 4 ++++ 1 file changed, 4 insertions(+) (limited to '_test') diff --git a/_test/phpunit.xml b/_test/phpunit.xml index 13676f207..fc7dd8be0 100644 --- a/_test/phpunit.xml +++ b/_test/phpunit.xml @@ -10,6 +10,9 @@ ../lib/plugins/*/_test + + ../lib/tpl/*/_test + @@ -19,6 +22,7 @@ ../_cs/ ../_test/ ../lib/plugins/*/_test/ + ../lib/tpl/*/_test/ -- cgit v1.2.3 From 6686e3d1ac97a3c4d256f4e9df7f772102baed96 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 18 Jan 2013 10:40:49 +0100 Subject: fixed tests --- _test/tests/inc/subscription.test.php | 31 ++++++++++++++++++++++++------- _test/tests/inc/subscription_set.test.php | 20 -------------------- 2 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 _test/tests/inc/subscription_set.test.php (limited to '_test') diff --git a/_test/tests/inc/subscription.test.php b/_test/tests/inc/subscription.test.php index c6f33dec7..333400576 100644 --- a/_test/tests/inc/subscription.test.php +++ b/_test/tests/inc/subscription.test.php @@ -120,7 +120,7 @@ class subscription_test extends DokuWikiTest { ); } - function test_bulkdigest(){ + function test_bulkdigest() { $sub = new MockupSubscription(); // let's start with nothing @@ -153,10 +153,10 @@ class subscription_test extends DokuWikiTest { // we now should get mails for three changes $this->assertEquals(3, $sub->send_bulk('sub1:test')); - $this->assertEquals(array('arthur@example.com','arthur@example.com','arthur@example.com'), $sub->mails); + $this->assertEquals(array('arthur@example.com', 'arthur@example.com', 'arthur@example.com'), $sub->mails); } - function test_bulklist(){ + function test_bulklist() { $sub = new MockupSubscription(); // let's start with nothing @@ -192,7 +192,24 @@ class subscription_test extends DokuWikiTest { $this->assertEquals(array('arthur@example.com'), $sub->mails); } + /** + * Tests, if overwriting subscriptions works even when subscriptions for the same + * user exist for two nested namespaces, this is a test for the bug described in FS#2580 + */ + function test_overwrite() { + $sub = new MockupSubscription(); + $sub->add(':', 'admin', 'digest', '123456789'); + $sub->add(':wiki:', 'admin', 'digest', '123456789'); + $sub->add(':', 'admin', 'digest', '1234'); + $sub->add(':wiki:', 'admin', 'digest', '1234'); + + $subscriptions = $sub->subscribers(':wiki:', 'admin'); + + $this->assertCount(1, $subscriptions[':'], 'More than one subscription saved for the root namespace even though the old one should have been overwritten.'); + $this->assertCount(1, $subscriptions[':wiki:'], 'More than one subscription saved for the wiki namespace even though the old one should have been overwritten.'); + $this->assertCount(2, $subscriptions, 'Didn\'t find the expected two subscriptions'); + } } /** @@ -201,18 +218,18 @@ class subscription_test extends DokuWikiTest { class MockupSubscription extends Subscription { public $mails; // we keep sent mails here - public function __construct(){ + public function __construct() { $this->reset(); } /** * resets the mail array */ - public function reset(){ + public function reset() { $this->mails = array(); } - public function isenabled(){ + public function isenabled() { return true; } @@ -220,7 +237,7 @@ class MockupSubscription extends Subscription { return parent::buildregex($user, $style, $data); } - protected function send($subscriber_mail, $subject, $id, $template, $trep, $hrep){ + protected function send($subscriber_mail, $subject, $id, $template, $trep, $hrep = null) { $this->mails[] = $subscriber_mail; return true; } diff --git a/_test/tests/inc/subscription_set.test.php b/_test/tests/inc/subscription_set.test.php deleted file mode 100644 index 5c0a6c816..000000000 --- a/_test/tests/inc/subscription_set.test.php +++ /dev/null @@ -1,20 +0,0 @@ - 'admin')); - $this->assertCount(1, $subscriptions[':'], 'More than one subscription saved for the root namespace even though the old one should have been overwritten.'); - $this->assertCount(1, $subscriptions[':wiki:'], 'More than one subscription saved for the wiki namespace even though the old one should have been overwritten.'); - $this->assertCount(2, $subscriptions, 'Didn\'t find the expected two subscriptions'); - } -} -- cgit v1.2.3 From 3fed52e12907b55aa9542b8d0da42c3992f8384f Mon Sep 17 00:00:00 2001 From: Guillaume Turri Date: Mon, 21 Jan 2013 21:13:15 +0100 Subject: Added test for search_allpages Currently both the 2nd and the third assertions fail (the first one is just for upcoming non-regression) --- _test/tests/inc/search/search.test.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/search/search.test.php b/_test/tests/inc/search/search.test.php index 33cc80e74..9b75821f5 100644 --- a/_test/tests/inc/search/search.test.php +++ b/_test/tests/inc/search/search.test.php @@ -1,6 +1,7 @@ 0), 'ns1'); + $this->assertEquals(3, count($data)); + + //depth is 1 and we start too deep to expect results + $data = array(); + search($data, dirname(__FILE__) . '/data', 'search_allpages', array('depth' => 1), 'ns1/ns3'); + $this->assertEquals(0, count($data)); + + //depth is 1 so I should get only pages from ns1 + $data = array(); + search($data, dirname(__FILE__) . '/data', 'search_allpages', array('depth' => 1), 'ns1'); + $this->assertEquals(2, count($data)); + } + function test_search_index(){ + return; $data = array(); search($data, dirname(__FILE__) . '/data', 'search_index', array('ns' => 'ns2')); -- cgit v1.2.3 From f2cb3ec76dec3fe2b40f25765ef842223c7132fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 23 Jan 2013 13:55:25 +0200 Subject: handle bzip1 as well in fact .tbz is tar.bz (bzip1) and .tbz2 is what tar.bz2 is used commonly. --- _test/tests/inc/tar.test.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php index e8805a75d..f27b9506b 100644 --- a/_test/tests/inc/tar.test.php +++ b/_test/tests/inc/tar.test.php @@ -73,7 +73,7 @@ class Tar_TestCase extends DokuWikiTest { public function test_tarcontent() { $dir = dirname(__FILE__).'/tar'; - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -96,7 +96,7 @@ class Tar_TestCase extends DokuWikiTest { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -122,7 +122,7 @@ class Tar_TestCase extends DokuWikiTest { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -148,7 +148,7 @@ class Tar_TestCase extends DokuWikiTest { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -174,7 +174,7 @@ class Tar_TestCase extends DokuWikiTest { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -199,7 +199,7 @@ class Tar_TestCase extends DokuWikiTest { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz') as $ext) { + foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -229,6 +229,10 @@ class Tar_TestCase extends DokuWikiTest { $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.tbz2')); + $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tBZ2')); + $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.bz')); + $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.BZ')); $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.BZ2')); $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.bz2')); } @@ -316,4 +320,4 @@ class Tar_TestCase extends DokuWikiTest { TestUtils::rdelete($out); } -} \ No newline at end of file +} -- cgit v1.2.3 From 7afccd0aab62eed3797273e5241b7729bab1fb3f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 23 Jan 2013 16:16:18 +0100 Subject: Revert "handle bzip1 as well" This reverts commit f2cb3ec76dec3fe2b40f25765ef842223c7132fe. Turns out I was too fast merging this. I can't get PHP's bzip handler to handle a bzip1 compressed file. --- _test/tests/inc/tar.test.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php index f27b9506b..e8805a75d 100644 --- a/_test/tests/inc/tar.test.php +++ b/_test/tests/inc/tar.test.php @@ -73,7 +73,7 @@ class Tar_TestCase extends DokuWikiTest { public function test_tarcontent() { $dir = dirname(__FILE__).'/tar'; - foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -96,7 +96,7 @@ class Tar_TestCase extends DokuWikiTest { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -122,7 +122,7 @@ class Tar_TestCase extends DokuWikiTest { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -148,7 +148,7 @@ class Tar_TestCase extends DokuWikiTest { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -174,7 +174,7 @@ class Tar_TestCase extends DokuWikiTest { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -199,7 +199,7 @@ class Tar_TestCase extends DokuWikiTest { $dir = dirname(__FILE__).'/tar'; $out = sys_get_temp_dir().'/dwtartest'.md5(time()); - foreach(array('tar', 'tgz', 'tbz', 'tbz2') as $ext) { + foreach(array('tar', 'tgz', 'tbz') as $ext) { $tar = new Tar(); $file = "$dir/test.$ext"; @@ -229,10 +229,6 @@ class Tar_TestCase extends DokuWikiTest { $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.tbz2')); - $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tBZ2')); - $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.bz')); - $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.BZ')); $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.BZ2')); $this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.bz2')); } @@ -320,4 +316,4 @@ class Tar_TestCase extends DokuWikiTest { TestUtils::rdelete($out); } -} +} \ No newline at end of file -- cgit v1.2.3 From 4dfbea875bd419fca4d9a5248c53c98c1e2af376 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 23 Jan 2013 16:24:15 +0100 Subject: fixed test case --- _test/tests/inc/search/search.test.php | 1 - 1 file changed, 1 deletion(-) (limited to '_test') diff --git a/_test/tests/inc/search/search.test.php b/_test/tests/inc/search/search.test.php index 9b75821f5..9c854a661 100644 --- a/_test/tests/inc/search/search.test.php +++ b/_test/tests/inc/search/search.test.php @@ -29,7 +29,6 @@ class search_test extends DokuWikiTest { } function test_search_index(){ - return; $data = array(); search($data, dirname(__FILE__) . '/data', 'search_index', array('ns' => 'ns2')); -- cgit v1.2.3 From b21a57bf3a948df8baf78cc9dc5387bf27592de1 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Fri, 25 Jan 2013 22:28:22 +0100 Subject: Add test cases for indexer rename page/meta value methods --- _test/tests/inc/indexer_rename.test.php | 83 +++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 _test/tests/inc/indexer_rename.test.php (limited to '_test') diff --git a/_test/tests/inc/indexer_rename.test.php b/_test/tests/inc/indexer_rename.test.php new file mode 100644 index 000000000..c9825ae4e --- /dev/null +++ b/_test/tests/inc/indexer_rename.test.php @@ -0,0 +1,83 @@ +indexer = idx_get_indexer(); + $this->indexer->clear(); + + saveWikiText($this->old_id, 'Old test content', 'Created old test page for indexer rename test'); + idx_addPage($this->old_id); + } + + function test_rename_to_new_page() { + $newid = 'new_id_1'; + + $oldpid = $this->indexer->getPID($this->old_id); + + $this->indexer->renamePage($this->old_id, $newid); + io_rename(wikiFN($this->old_id), wikiFN($newid)); + + $this->assertNotEquals($this->indexer->getPID($this->old_id), $oldpid, 'PID for the old page unchanged after rename.'); + $this->assertEquals($this->indexer->getPID($newid), $oldpid, 'New page has not the old pid.'); + $query = array('old'); + $this->assertEquals(array('old' => array($newid => 1)), $this->indexer->lookup($query), '"Old" doesn\'t find the new page'); + } + + function test_rename_to_existing_page() { + $newid = 'existing_page'; + saveWikiText($newid, 'Existing content', 'Created page for move_to_existing_page'); + idx_addPage($newid); + + $oldpid = $this->indexer->getPID($this->old_id); + $existingpid = $this->indexer->getPID($newid); + + $this->indexer->renamePage($this->old_id, $newid); + + $this->assertNotEquals($this->indexer->getPID($this->old_id), $oldpid, 'PID for old page unchanged after rename.'); + $this->assertNotEquals($this->indexer->getPID($this->old_id), $existingpid, 'PID for old page is now PID of the existing page.'); + $this->assertEquals($this->indexer->getPID($newid), $oldpid, 'New page has not the old pid.'); + $query = array('existing'); + $this->assertEquals(array('existing' => array()), $this->indexer->lookup($query), 'Existing page hasn\'t been deleted from the index.'); + $query = array('old'); + $this->assertEquals(array('old' => array($newid => 1)), $this->indexer->lookup($query), '"Old" doesn\'t find the new page'); + } + + function test_meta_rename_to_new_value() { + $this->indexer->addMetaKeys($this->old_id, array('mkey' => 'old_value')); + + $this->indexer->renameMetaValue('mkey', 'old_value', 'new_value'); + $query = 'old_value'; + $this->assertEquals(array(), $this->indexer->lookupKey('mkey', $query), 'Page can still be found under old value.'); + $query = 'new_value'; + $this->assertEquals(array($this->old_id), $this->indexer->lookupKey('mkey', $query), 'Page can\'t be found under new value.'); + } + + function test_meta_rename_to_existing_value() { + $this->indexer->addMetaKeys($this->old_id, array('mkey' => array('old_value', 'new_value'))); + + saveWikiText('newvalue', 'Test page', ''); + idx_addPage('newvalue'); + $this->indexer->addMetaKeys('newvalue', array('mkey' => array('new_value'))); + + saveWikiText('oldvalue', 'Test page', ''); + idx_addPage('oldvalue'); + $this->indexer->addMetaKeys('oldvalue', array('mkey' => array('old_value'))); + + $this->indexer->renameMetaValue('mkey', 'old_value', 'new_value'); + $query = 'old_value'; + $this->assertEquals(array(), $this->indexer->lookupKey('mkey', $query), 'Page can still be found under old value.'); + $query = 'new_value'; + $result = $this->indexer->lookupKey('mkey', $query); + $this->assertContains($this->old_id, $result, 'Page with both values can\'t be found anymore'); + $this->assertContains('newvalue', $result, 'Page with new value can\'t be found anymore'); + $this->assertContains('oldvalue', $result, 'Page with only the old value can\'t be found anymore'); + } +} -- cgit v1.2.3 From b1cfdc5fd569b4dc4b06d4443191b1e2bff27567 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sat, 26 Jan 2013 11:17:20 +0100 Subject: Indexer rename test cases: assert that renames succeed --- _test/tests/inc/indexer_rename.test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to '_test') diff --git a/_test/tests/inc/indexer_rename.test.php b/_test/tests/inc/indexer_rename.test.php index c9825ae4e..d8c456f8e 100644 --- a/_test/tests/inc/indexer_rename.test.php +++ b/_test/tests/inc/indexer_rename.test.php @@ -22,7 +22,7 @@ class indexer_rename_test extends DokuWikiTest { $oldpid = $this->indexer->getPID($this->old_id); - $this->indexer->renamePage($this->old_id, $newid); + $this->assertTrue($this->indexer->renamePage($this->old_id, $newid), 'Renaming the page to a new id failed'); io_rename(wikiFN($this->old_id), wikiFN($newid)); $this->assertNotEquals($this->indexer->getPID($this->old_id), $oldpid, 'PID for the old page unchanged after rename.'); @@ -39,7 +39,7 @@ class indexer_rename_test extends DokuWikiTest { $oldpid = $this->indexer->getPID($this->old_id); $existingpid = $this->indexer->getPID($newid); - $this->indexer->renamePage($this->old_id, $newid); + $this->assertTrue($this->indexer->renamePage($this->old_id, $newid), 'Renaming the page to an existing id failed'); $this->assertNotEquals($this->indexer->getPID($this->old_id), $oldpid, 'PID for old page unchanged after rename.'); $this->assertNotEquals($this->indexer->getPID($this->old_id), $existingpid, 'PID for old page is now PID of the existing page.'); @@ -53,7 +53,7 @@ class indexer_rename_test extends DokuWikiTest { function test_meta_rename_to_new_value() { $this->indexer->addMetaKeys($this->old_id, array('mkey' => 'old_value')); - $this->indexer->renameMetaValue('mkey', 'old_value', 'new_value'); + $this->assertTrue($this->indexer->renameMetaValue('mkey', 'old_value', 'new_value'), 'Meta value rename to new value failed.'); $query = 'old_value'; $this->assertEquals(array(), $this->indexer->lookupKey('mkey', $query), 'Page can still be found under old value.'); $query = 'new_value'; @@ -71,7 +71,7 @@ class indexer_rename_test extends DokuWikiTest { idx_addPage('oldvalue'); $this->indexer->addMetaKeys('oldvalue', array('mkey' => array('old_value'))); - $this->indexer->renameMetaValue('mkey', 'old_value', 'new_value'); + $this->assertTrue($this->indexer->renameMetaValue('mkey', 'old_value', 'new_value'), 'Meta value rename to existing value failed'); $query = 'old_value'; $this->assertEquals(array(), $this->indexer->lookupKey('mkey', $query), 'Page can still be found under old value.'); $query = 'new_value'; -- cgit v1.2.3 From 529b04166c604b1d086cbfeac1bd676227d04872 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 26 Jan 2013 12:59:15 +0100 Subject: added mediawiki password method FS#2559 This should make migrating from MediaWiki a bit easier. --- _test/tests/inc/auth_password.test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to '_test') diff --git a/_test/tests/inc/auth_password.test.php b/_test/tests/inc/auth_password.test.php index 426353291..53b9b2c6c 100644 --- a/_test/tests/inc/auth_password.test.php +++ b/_test/tests/inc/auth_password.test.php @@ -61,6 +61,11 @@ class auth_password_test extends PHPUnit_Framework_TestCase { $this->assertTrue(auth_verifyPassword('test12345','$H$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0')); } + function test_veryPassword_mediawiki(){ + $this->assertTrue(auth_verifyPassword('password', ':B:838c83e1:e4ab7024509eef084cdabd03d8b2972c')); + } + + /** * pmd5 checking should throw an exception when a hash with a too high * iteration count is passed -- cgit v1.2.3 From dfbe4adfd080433f91409f028935b9f9879fceca Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 26 Jan 2013 13:38:20 +0100 Subject: added SHA512 hashing method FS#2663 --- _test/tests/inc/auth_password.test.php | 1 + 1 file changed, 1 insertion(+) (limited to '_test') diff --git a/_test/tests/inc/auth_password.test.php b/_test/tests/inc/auth_password.test.php index 53b9b2c6c..27e03be60 100644 --- a/_test/tests/inc/auth_password.test.php +++ b/_test/tests/inc/auth_password.test.php @@ -16,6 +16,7 @@ class auth_password_test extends PHPUnit_Framework_TestCase { 'kmd5' => 'a579299436d7969791189acadd86fcb716', 'djangomd5' => 'md5$abcde$d0fdddeda8cd92725d2b54148ac09158', 'djangosha1' => 'sha1$abcde$c8e65a7f0acc9158843048a53dcc5a6bc4d17678', + 'sha512' => '$6$abcdefgh12345678$J9.zOcgx0lotwZdcz0uulA3IVQMinZvFZVjA5vapRLVAAqtay23XD4xeeUxQ3B4JvDWYFBIxVWW1tOYlHX13k1' ); -- cgit v1.2.3