You are here

public function CommentNotifyConfigPageTest::testConfigPage in Comment Notify 8

Test to all the options are saved correctly.

File

tests/src/Functional/CommentNotifyConfigPageTest.php, line 19

Class

CommentNotifyConfigPageTest
Tests for the comment_notify module.

Namespace

Drupal\Tests\comment_notify\Functional

Code

public function testConfigPage() {
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet("admin/config/people/comment_notify");

  // Test the default values are working.
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');

  // Test that the content types are saved correctly.
  $this
    ->getSession()
    ->getPage()
    ->checkField('bundle_types[node--article--comment]');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasCheckedField('bundle_types[node--article--comment]'));

  // Test that Available subscription modes are saved correctly.
  $this
    ->getSession()
    ->getPage()
    ->checkField('available_alerts[1]');
  $this
    ->getSession()
    ->getPage()
    ->checkField('available_alerts[2]');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasCheckedField('available_alerts[1]'));
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasCheckedField('available_alerts[2]'));

  // Test that at least one subscription mode must be enabled.
  $this
    ->getSession()
    ->getPage()
    ->uncheckField('available_alerts[1]');
  $this
    ->getSession()
    ->getPage()
    ->uncheckField('available_alerts[2]');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('You must enable at least one subscription mode.');
  $this
    ->getSession()
    ->getPage()
    ->uncheckField('available_alerts[1]');
  $this
    ->getSession()
    ->getPage()
    ->checkField('available_alerts[2]');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasUncheckedField('available_alerts[1]'));
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hascheckedField('available_alerts[2]'));

  // The default state select must hide the option as well.
  $field = $this
    ->getSession()
    ->getPage()
    ->findField('Default state for the notification selection box');
  $this
    ->assertStringNotContainsString('All Comments', $field
    ->getHtml());
  $this
    ->assertStringContainsString('Replies to my comment', $field
    ->getHtml());
  $this
    ->getSession()
    ->getPage()
    ->uncheckField('available_alerts[2]');
  $this
    ->getSession()
    ->getPage()
    ->checkField('available_alerts[1]');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasUncheckedField('available_alerts[2]'));
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hascheckedField('available_alerts[1]'));

  // The default state select must hide the option as well.
  $field = $this
    ->getSession()
    ->getPage()
    ->findField('Default state for the notification selection box');
  $this
    ->assertStringContainsString('All comments', $field
    ->getHtml());
  $this
    ->assertStringNotContainsString('Replies to my comment', $field
    ->getHtml());
  $this
    ->getSession()
    ->getPage()
    ->checkField('available_alerts[1]');
  $this
    ->getSession()
    ->getPage()
    ->checkField('available_alerts[2]');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hascheckedField('available_alerts[1]'));
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hascheckedField('available_alerts[2]'));
  $field = $this
    ->getSession()
    ->getPage()
    ->findField('Default state for the notification selection box');
  $this
    ->assertStringContainsString('All comments', $field
    ->getHtml());
  $this
    ->assertStringContainsString('Replies to my comment', $field
    ->getHtml());
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('Default state for the notification selection box', "0");
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $field = $this
    ->getSession()
    ->getPage()
    ->findField('Default state for the notification selection box');
  $this
    ->assertTrue($field
    ->getValue() == "0");
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('Default state for the notification selection box', "1");
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $field = $this
    ->getSession()
    ->getPage()
    ->findField('Default state for the notification selection box');
  $this
    ->assertTrue($field
    ->getValue() == "1");
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('Default state for the notification selection box', "2");
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $field = $this
    ->getSession()
    ->getPage()
    ->findField('Default state for the notification selection box');
  $this
    ->assertTrue($field
    ->getValue() == "2");
  $this
    ->getSession()
    ->getPage()
    ->checkField('Subscribe users to their entity follow-up notification emails by default');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasCheckedField('Subscribe users to their entity follow-up notification emails by default'));
  $this
    ->getSession()
    ->getPage()
    ->uncheckField('Subscribe users to their entity follow-up notification emails by default');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $this
    ->assertTrue($this
    ->getSession()
    ->getPage()
    ->hasUncheckedField('Subscribe users to their entity follow-up notification emails by default'));
  $this
    ->getSession()
    ->getPage()
    ->fillField('Default mail text for sending out notifications to commenters', 'Hello');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $field = $this
    ->getSession()
    ->getPage()
    ->findField('Default mail text for sending out notifications to commenters');
  $this
    ->assertTrue($field
    ->getValue() == 'Hello');
  $this
    ->getSession()
    ->getPage()
    ->fillField('Default mail text for sending out the notifications to entity authors', 'Hello');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->drupalGet("admin/config/people/comment_notify");
  $field = $this
    ->getSession()
    ->getPage()
    ->findField('Default mail text for sending out the notifications to entity authors');
  $this
    ->assertTrue($field
    ->getValue() == 'Hello');
  $this
    ->drupalLogout();
}