public function CommentNotifyNotificationsTest::testCommentNotification in Comment Notify 8
Tests that the Mail notification is sent properly and it is only send once.
File
- tests/
src/ Functional/ CommentNotifyNotificationsTest.php, line 51
Class
- CommentNotifyNotificationsTest
- Tests that all the notifications are sent as expected.
Namespace
Drupal\Tests\comment_notify\FunctionalCode
public function testCommentNotification() {
$user1 = $this
->drupalCreateUser($this->permissions);
/** @var \Drupal\comment_notify\UserNotificationSettings $user_settings */
$this->container
->get('comment_notify.user_settings')
->saveSettings($user1
->id(), COMMENT_NOTIFY_ENTITY, 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_ENTITY,
]);
// 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();
}