Commit d50f43cf authored by gnuget's avatar gnuget Committed by gnuget

Issue #2879921 by gnuget, kmonahan, Quicksaver, toamit: Notifications sent when user edits comment

parent da54d1db
......@@ -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();
}
......
......@@ -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;
}
<?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();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment