diff --git a/includes/simplenews.subscription.inc b/includes/simplenews.subscription.inc index 13f770a..d77f91b 100644 --- a/includes/simplenews.subscription.inc +++ b/includes/simplenews.subscription.inc @@ -501,8 +501,15 @@ function simplenews_confirm_subscription() { elseif ($op == 'add') { return drupal_get_form('simplenews_confirm_add_form', $subscriber->mail, $category); } - elseif ($op == 'combined' && !empty($subscriber->changes)) { - return drupal_get_form('simplenews_confirm_multi_form', $subscriber); + elseif ($op == 'combined') { + // Redirect and display message if no changes are available. + if (empty($subscriber->changes)) { + drupal_set_message(t('All changes to your subscriptions where already applied. No changes made.')); + drupal_goto(variable_get('site_frontpage', 'node')); + } + else { + return drupal_get_form('simplenews_confirm_multi_form', $subscriber); + } } } else { @@ -524,22 +531,29 @@ function simplenews_confirm_subscription() { drupal_set_message(t('%user was added to the %newsletter mailing list.', array('%user' => $subscriber->mail, '%newsletter' => _simplenews_newsletter_name($category)))); drupal_goto(variable_get('site_frontpage', 'node')); } - elseif ($op == 'combined' && !empty($subscriber->changes)) { - foreach ($subscriber->changes as $tid => $action) { - if ($action == 'subscribe') { - simplenews_subscribe_user($subscriber->mail, $tid, FALSE, 'website'); - } - elseif ($action == 'unsubscribe') { - simplenews_unsubscribe_user($subscriber->mail, $tid, FALSE, 'website'); - } + elseif ($op == 'combined') { + // Redirect and display message if no changes are available. + if (empty($subscriber->changes)) { + drupal_set_message(t('All changes to your subscriptions where already applied. No changes made.')); + drupal_goto(variable_get('site_frontpage', 'node')); } + else { + foreach ($subscriber->changes as $tid => $action) { + if ($action == 'subscribe') { + simplenews_subscribe_user($subscriber->mail, $tid, FALSE, 'website'); + } + elseif ($action == 'unsubscribe') { + simplenews_unsubscribe_user($subscriber->mail, $tid, FALSE, 'website'); + } + } - // Clear changes. - $subscriber->changes = array(); - simplenews_subscriber_save($subscriber); + // Clear changes. + $subscriber->changes = array(); + simplenews_subscriber_save($subscriber); - drupal_set_message(t('Subscription changes confirmed for %user.', array('%user' => $subscriber->mail))); - drupal_goto(variable_get('site_frontpage', 'node')); + drupal_set_message(t('Subscription changes confirmed for %user.', array('%user' => $subscriber->mail))); + drupal_goto(variable_get('site_frontpage', 'node')); + } } } } diff --git a/tests/simplenews.test b/tests/simplenews.test index a4d79e2..9caa2bb 100644 --- a/tests/simplenews.test +++ b/tests/simplenews.test @@ -416,6 +416,18 @@ class SimplenewsSubscribeTestCase extends SimplenewsTestCase { foreach (array_keys($categories) as $tid) { $this->assertFalse(simplenews_user_is_subscribed($mail, $tid)); } + + // Call confirmation url after it is allready used. + // Using direct url. + $this->drupalGet($confirm_url . '/ok'); + $this->assertNoResponse(404, 'Redirected after calling confirmation url more than once.'); + $this->assertRaw(t('All changes to your subscriptions where already applied. No changes made.')); + + // Using confirmation page. + $this->drupalGet($confirm_url); + $this->assertNoResponse(404, 'Redirected after calling confirmation url more than once.'); + $this->assertRaw(t('All changes to your subscriptions where already applied. No changes made.')); + } /**