Skip to content
Snippets Groups Projects
Commit c32c0f51 authored by Angie Byron's avatar Angie Byron
Browse files

#296487 by lyricnz and beeradb: Tests to make sure comment posting fails when it should.

parent ca858345
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -292,6 +292,27 @@ class CommentInterfaceTest extends CommentHelperCase { ...@@ -292,6 +292,27 @@ class CommentInterfaceTest extends CommentHelperCase {
$this->assertTrue($this->commentExists($reply, TRUE), t('Page two exists. %s')); $this->assertTrue($this->commentExists($reply, TRUE), t('Page two exists. %s'));
$this->setCommentsPerPage(50); $this->setCommentsPerPage(50);
// Attempt to post to node with comments disabled.
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_DISABLED));
$this->assertTrue($this->node, t('Article node created.'));
$this->drupalGet('comment/reply/' . $this->node->nid);
$this->assertText('This discussion is closed', t('Posting to node with comments disabled'));
$this->assertNoField('edit-comment', t('Comment body field found.'));
// Attempt to post to node with read-only comments.
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_READ_ONLY));
$this->assertTrue($this->node, t('Article node created.'));
$this->drupalGet('comment/reply/' . $this->node->nid);
$this->assertText('This discussion is closed', t('Posting to node with comments read-only'));
$this->assertNoField('edit-comment', t('Comment body field found.'));
// Attempt to post to node with comments enabled (check field names etc).
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => COMMENT_NODE_READ_WRITE));
$this->assertTrue($this->node, t('Article node created.'));
$this->drupalGet('comment/reply/' . $this->node->nid);
$this->assertNoText('This discussion is closed', t('Posting to node with comments enabled'));
$this->assertField('edit-comment', t('Comment body field found.'));
// Delete comment and make sure that reply is also removed. // Delete comment and make sure that reply is also removed.
$this->drupalLogout(); $this->drupalLogout();
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->admin_user);
...@@ -418,6 +439,20 @@ class CommentAnonymous extends CommentHelperCase { ...@@ -418,6 +439,20 @@ class CommentAnonymous extends CommentHelperCase {
// Reset. // Reset.
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->admin_user);
$this->setAnonymousUserComment(FALSE, FALSE); $this->setAnonymousUserComment(FALSE, FALSE);
// Attempt to view comments while disallowed.
// NOTE: if authenticated user has permission to post comments, then a
// "Login or register to post comments" type link may be shown.
$this->drupalLogout();
$this->drupalGet('node/' . $this->node->nid);
$this->assertNoRaw('<div id="comments">', t('Comments were not displayed.'));
$this->assertNoLink('Add new comment', t('Link to add comment was found.'));
// Attempt to view node-comment form while disallowed.
$this->drupalGet('comment/reply/' . $this->node->nid);
$this->assertText('You are not authorized to view comments', t('Error attempting to post comment.'));
$this->assertNoFieldByName('subject', '', t('Subject field not found.'));
$this->assertNoFieldByName('comment', '', t('Comment field not found.'));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment