You are here

public function CommentNotifyUserPreferencesTest::testUserCommentNotifyBox in Comment Notify 8

Tests that the comment notify box is displayed correctly.

It should display different options depending the permissions of the user.

File

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

Class

CommentNotifyUserPreferencesTest
Tests the Comment Notify users preferences.

Namespace

Drupal\Tests\comment_notify\Functional

Code

public function testUserCommentNotifyBox() {

  // The user hasn't the subscribe to comments permission nor the 'administer
  // nodes' permission, nor has permission to create content, so it shouldn't
  // see any Comment notify settings in the profile page.
  $this->authenticatedUser = $this
    ->drupalCreateUser([
    'post comments',
    'skip comment approval',
  ]);
  $this
    ->drupalLogin($this->authenticatedUser);
  $this
    ->drupalGet($this->authenticatedUser
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertFalse($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Comment follow-up notification settings')));
  $this
    ->drupalLogout();

  // The user only has the 'subscribe to comments' permission, he should be
  // able to see the Comment Notify settings box but the 'Receive content
  // follow-up notification e-mails' checkbox shouldn't appear.
  $this->authenticatedUser = $this
    ->drupalCreateUser([
    'post comments',
    'skip comment approval',
    'subscribe to comments',
  ]);
  $this
    ->drupalLogin($this->authenticatedUser);
  $this
    ->drupalGet($this->authenticatedUser
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Comment follow-up notification settings')));
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Receive comment follow-up notification e-mails')));
  $this
    ->assertFalse($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Receive content follow-up notification e-mails')));
  $this
    ->drupalLogout();

  // The user only has the 'administer nodes' permission, he should be
  // able to see the Comment Notify settings box but the 'Comment follow-up
  // notification settings' dropdown shouldn't appear.
  $this->authenticatedUser = $this
    ->drupalCreateUser([
    'post comments',
    'skip comment approval',
    'administer nodes',
  ]);
  $this
    ->drupalLogin($this->authenticatedUser);
  $this
    ->drupalGet($this->authenticatedUser
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Comment follow-up notification settings')));
  $this
    ->assertFalse($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Receive comment follow-up notification e-mails')));
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Receive content follow-up notification e-mails')));
  $this
    ->drupalLogout();

  // The user only hasn't the 'administer nodes' permission nor the 'subscribe
  // to comments' permission but he can create nodes of the type article, so
  // he should be able to see the Comment Notify settings box with the
  // 'Receive content follow-up notification e-mails' checkbox.
  $this->authenticatedUser = $this
    ->drupalCreateUser([
    'post comments',
    'skip comment approval',
    'create article content',
  ]);
  $this
    ->drupalLogin($this->authenticatedUser);
  $this
    ->drupalGet($this->authenticatedUser
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Comment follow-up notification settings')));
  $this
    ->assertFalse($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Receive comment follow-up notification e-mails')));
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Receive content follow-up notification e-mails')));
  $this
    ->drupalLogout();

  // The has all the permissions, so he should be able to see all the Comment
  // notify settings.
  $this->authenticatedUser = $this
    ->drupalCreateUser([
    'post comments',
    'skip comment approval',
    'create article content',
    'subscribe to comments',
  ]);
  $this
    ->drupalLogin($this->authenticatedUser);
  $this
    ->drupalGet($this->authenticatedUser
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Comment follow-up notification settings')));
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Receive comment follow-up notification e-mails')));
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasContent(t('Receive content follow-up notification e-mails')));
  $this
    ->drupalLogout();
}