summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgnuget2019-02-06 22:18:35 (GMT)
committerDavid Valdez2019-02-06 22:18:35 (GMT)
commitd50f43cf03ed0596ea3af79207a0f719ca58df89 (patch)
tree23fde63b5f7721212823b7ab8c464f2647a32fa9
parentda54d1db75e194d02eab27615fb167b2832f6a62 (diff)
Issue #2879921 by gnuget, kmonahan, Quicksaver, toamit: Notifications sent when user edits comment8.x-1.0-beta4
-rw-r--r--comment_notify.inc5
-rw-r--r--comment_notify.module3
-rw-r--r--tests/src/Functional/CommentNotifyNotificationsTest.php60
3 files changed, 65 insertions, 3 deletions
diff --git a/comment_notify.inc b/comment_notify.inc
index ea57733..61f08ec 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 7359efb..3d7ea76 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 0000000..dfd7bd2
--- /dev/null
+++ b/tests/src/Functional/CommentNotifyNotificationsTest.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Drupal\Tests\comment_notify\Functional;
+
+/**
+ * Tests that all the notifications are sent as expected.
+ *
+ * @group comment_notify
+ */
+class CommentNotifyNotificationsTest extends CommentNotifyTestBase {
+
+ /**
+ * The permissions required by the tests.
+ *
+ * @var array
+ */
+ protected $permissions = [
+ 'access comments',
+ 'access content',
+ 'edit own comments',
+ 'post comments',
+ 'skip comment approval',
+ 'subscribe to comments',
+ ];
+
+ /**
+ * Tests that the Mail notification is sent properly and it is only send once.
+ */
+ public function testCommentNotification() {
+ $user1 = $this->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();
+
+ }
+
+}