diff --git a/comment_notify.inc b/comment_notify.inc index ea57733b0a89f572fa2580c8334ea95cf65f739d..61f08ecf15d9e7d002900d82e3b68839edb4c1e2 100644 --- a/comment_notify.inc +++ b/comment_notify.inc @@ -129,10 +129,11 @@ function comment_notify_set_user_notification_setting($uid, $node_notification = * @param integer $cid * @param integer $notify * @param string $notify_hash + * @param integer|NULL $notified * * @return boolean */ -function comment_notify_add_notification($cid, $notify, $notify_hash) { +function comment_notify_add_notification($cid, $notify, $notify_hash, $notified) { // Check if comment already exist. $results = db_select('comment_notify', 'cn') ->fields('cn', array('cid')) @@ -146,6 +147,7 @@ function comment_notify_add_notification($cid, $notify, $notify_hash) { ->fields(array( 'notify' => $notify === NULL ? 0 : $notify, 'notify_hash' => $notify_hash, + 'notified' => $notified === NULL ? 0 : $notified, )) ->condition('cid', $cid) ->execute(); @@ -158,6 +160,7 @@ function comment_notify_add_notification($cid, $notify, $notify_hash) { 'cid' => $cid, 'notify' => $notify === NULL ? 0 : $notify, 'notify_hash' => $notify_hash, + 'notified' => $notified === NULL ? 0 : $notified, )) ->execute(); } diff --git a/comment_notify.module b/comment_notify.module index 7359efb104444e131c85a5bb58d3dc37901a027e..3d7ea76d4c87773cbd032a5f1017ffb3b6b91db9 100644 --- a/comment_notify.module +++ b/comment_notify.module @@ -151,7 +151,7 @@ function _comment_notify_submit_comment_form(array &$form, FormStateInterface $f // unique/unguessable. See comment_notify_unsubscribe_by_hash(). $hostname = !$comment->getHostname() ? $comment->getHostname() : (isset($user->hostname) ? $user->hostname : ''); $notify_hash = \Drupal::csrfToken()->get($hostname . $comment->id()); - comment_notify_add_notification($comment->id(), $status, $notify_hash); + comment_notify_add_notification($comment->id(), $status, $notify_hash, $comment->notified); } } @@ -491,4 +491,3 @@ function comment_notify_entity_extra_field_info() { ); return $extras; } - diff --git a/tests/src/Functional/CommentNotifyNotificationsTest.php b/tests/src/Functional/CommentNotifyNotificationsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..dfd7bd22b8544f5628d4717cca509b6cda59518a --- /dev/null +++ b/tests/src/Functional/CommentNotifyNotificationsTest.php @@ -0,0 +1,60 @@ +drupalCreateUser($this->permissions); + comment_notify_set_user_notification_setting($user1->id(), COMMENT_NOTIFY_NODE, COMMENT_NOTIFY_COMMENT); + $user2 = $this->drupalCreateUser($this->permissions); + $node = $this->drupalCreateNode( + [ + 'type' => 'article', + 'uid' => $user1, + ] + ); + $this->drupalLogin($user2); + $comment = $this->postComment( + $node->toUrl()->toString(), + $this->randomMachineName(), + $this->randomMachineName(), + ['notify' => TRUE, 'notify_type' => COMMENT_NOTIFY_NODE] + ); + // Test that the notification was sent. + $this->assertMail('to', $user1->getEmail(), t('Message was sent to the user.')); + $this->container->get('state')->set('system.test_mail_collector', []); + + // Edit the comment, no notification must be sent. + $this->drupalGet('comment/' . $comment['id'] . '/edit'); + $this->getSession()->getPage()->fillField(t('Comment'), $this->randomMachineName()); + $this->getSession()->getPage()->pressButton(t('Save')); + $captured_emails = $this->container->get('state')->get('system.test_mail_collector'); + $this->assertEmpty($captured_emails, 'No notifications has been sent.'); + $this->drupalLogout(); + + } + +}