You are here

public function CommentNotifyUserPreferencesTest::testsCommentFollowUpsNotifications in Comment Notify 8

Tests the "Comment Follow-up notifications" options.

File

tests/src/Functional/CommentNotifyUserPreferencesTest.php, line 137

Class

CommentNotifyUserPreferencesTest
Tests the Comment Notify users preferences.

Namespace

Drupal\Tests\comment_notify\Functional

Code

public function testsCommentFollowUpsNotifications() {
  $this
    ->drupalLogin($this->authenticatedUser);
  $this
    ->drupalGet($this->authenticatedUser
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Receive comment follow-up notification e-mails')));

  // Test the "No notifications" option.
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('comment_notify', COMMENT_NOTIFY_DISABLED);
  $this
    ->getSession()
    ->getPage()
    ->pressButton(t('Save'));
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
  ]);
  $this
    ->drupalGet($node
    ->toUrl()
    ->toString());
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasUncheckedField('Notify me when new comments are posted'));

  // Test the "All comments" option.
  $this
    ->drupalGet($this->authenticatedUser
    ->toUrl('edit-form')
    ->toString());
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('comment_notify', COMMENT_NOTIFY_ENTITY);
  $this
    ->getSession()
    ->getPage()
    ->pressButton(t('Save'));
  $this
    ->drupalGet($node
    ->toUrl()
    ->toString());
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hascheckedField('Notify me when new comments are posted'));
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hascheckedField('All comments'));

  // Tests the "Replies to my comments" option.
  $this
    ->drupalGet($this->authenticatedUser
    ->toUrl('edit-form')
    ->toString());
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('comment_notify', COMMENT_NOTIFY_COMMENT);
  $this
    ->getSession()
    ->getPage()
    ->pressButton(t('Save'));
  $this
    ->drupalGet($node
    ->toUrl()
    ->toString());
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hascheckedField('Notify me when new comments are posted'));
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hascheckedField('Replies to my comment'));
  $this
    ->drupalLogout();
}