diff options
author | Michael Hamann <michael@content-space.de> | 2012-09-07 21:06:57 +0200 |
---|---|---|
committer | Michael Hamann <michael@content-space.de> | 2012-09-07 21:11:44 +0200 |
commit | 0a78cb463952660f3bb257dd3dd030db725cd4f4 (patch) | |
tree | 89ef2469293cec3fdfa196efa7730ad79247a7cd | |
parent | 05be3a57144498a28e918684364813560623a898 (diff) | |
download | rpg-0a78cb463952660f3bb257dd3dd030db725cd4f4.tar.gz rpg-0a78cb463952660f3bb257dd3dd030db725cd4f4.tar.bz2 |
Fix the test if a subscription already exists FS#2580
This fixes the test for existing subscriptions by not only testing if
the subscription for the deepest namespace level is for the current page
but by simply testing all levels. Test case is included, it fails
without this change.
-rw-r--r-- | _test/tests/inc/subscription_set.test.php | 20 | ||||
-rw-r--r-- | inc/subscription.php | 2 |
2 files changed, 21 insertions, 1 deletions
diff --git a/_test/tests/inc/subscription_set.test.php b/_test/tests/inc/subscription_set.test.php new file mode 100644 index 000000000..5c0a6c816 --- /dev/null +++ b/_test/tests/inc/subscription_set.test.php @@ -0,0 +1,20 @@ +<?php +/** + * Tests the subscription set function + */ +class subscription_set_test extends DokuWikiTest { + /** + * 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() { + subscription_set('admin', ':', 'digest', '123456789'); + subscription_set('admin', ':wiki:', 'digest', '123456789'); + subscription_set('admin', ':', 'digest', '1234', true); + subscription_set('admin', ':wiki:', 'digest', '1234', true); + $subscriptions = subscription_find(':wiki:', array('user' => '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'); + } +} diff --git a/inc/subscription.php b/inc/subscription.php index 1bee1152e..029d93e66 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -132,7 +132,7 @@ function subscription_set($user, $page, $style, $data = null, // Delete subscription if one exists and $overwrite is true. If $overwrite // is false, fail. $subs = subscription_find($page, array('user' => $user)); - if (count($subs) > 0 && array_pop(array_keys($subs)) === $page) { + if (count($subs) > 0 && isset($subs[$page])) { if (!$overwrite) { msg(sprintf($lang['subscr_already_subscribed'], $user, prettyprint_id($page)), -1); |