1 comment.test CommentNodeChangesTestCase::testNodeCommentSettings()

Tests opening, closing, and hiding comments.


core/modules/comment/tests/comment.test, line 2289
Tests for the Comment module.


Tests that comments behave correctly when the node is changed.


function testNodeCommentSettings() {

  // Check that the comment settings only include "Open" and "Closed" if
  // no comments yet exist.
  $this->backdropGet('node/' . $this->node->nid . '/edit');
  $this->assertField('edit-comment-' . COMMENT_NODE_OPEN, 'Comments open field found.');
  $this->assertField('edit-comment-' . COMMENT_NODE_CLOSED, 'Comments closed field found.');
  $this->assertNoField('edit-comment-' . COMMENT_NODE_HIDDEN, 'Comments hidden field not shown when no comments exist.');

  // Post a comment with the default settings (comments open).
  $comment = $this->postComment($this->node, $this->randomName());
  $this->backdropGet('node/' . $this->node->nid);
  $this->assertTrue($this->commentExists($comment), 'Comments shown when comments are open.');
  $this->assertEqual(count($this->xpath('//form[@id="comment-form"]')), 1, 'Comment form found on node page when comments are open.');

  // Now check that the hidden option exists in the edit form.
  $this->backdropGet('node/' . $this->node->nid . '/edit');
  $this->assertField('edit-comment-hidden', 'Comments hidden field shown after comments have been added.');

  // Close the comments and check that adding a comment is no longer possible.
  $edit = array(
    'comment' => COMMENT_NODE_CLOSED,
  $this->backdropPost(NULL, $edit, t('Save'));
  $this->assertTrue($this->commentExists($comment), 'Comments shown when comments are closed.');
  $this->assertEqual(count($this->xpath('//form[@id="comment-form"]')), 0, 'Comment form not on node page when comments are closed.');

  // Hide comments and check that adding comments is disabled also.
  $edit = array(
    'comment_hidden' => TRUE,
  $this->backdropPost('node/' . $this->node->nid . '/edit', $edit, t('Save'));
  $this->assertFalse($this->commentExists($comment), 'Comments are not shown when hidden.');
  $this->assertEqual(count($this->xpath('//form[@id="comment-form"]')), 0, 'Comment form not on node page when comments are hidden.');