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 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