diff --git a/modules/comment/comment.test b/modules/comment/comment.test index 9e69ba6..cbf15b4 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -2102,6 +2102,63 @@ class CommentFieldsTest extends CommentHelperCase { $edit = array('comment_body[und][0][value]' => $this->randomName(8)); $this->drupalPost('node/' . $this->node->nid, $edit, t('Save')); } + + /** + * Test that saving an empty, required body generates a warning, and cannot be saved. + */ + function testCommentEmptyRequiredBody($required = TRUE) { + // Set the requirement-indicator of the comment_body field. + $this->drupalLogin($this->admin_user); + $edit = array('instance[required]' => $required); + $this->drupalPost('admin/structure/types/manage/article/comment/fields/comment_body', $edit, t('Save settings')); + + // Preview an empty comment, and check if an error is shown. + $this->drupalPost('node/' . $this->node->nid, array(), t('Preview')); + $this->assertText('Comment field is required.', 'Cannot preview comment with empty required body.'); + + // Post an empty comment, and check if an error is shown. + $this->drupalPost('node/' . $this->node->nid, array(), t('Save')); + $this->assertText('Comment field is required.', 'Cannot save comment with empty required body.'); + } + + /** + * Test that saving an empty, NON-required body generates a warning, and cannot be saved. + */ + function testCommentEmptyNonRequiredBody($required = FALSE) { + // Set the requirement-indicator of the comment_body field. + $this->drupalLogin($this->admin_user); + $edit = array('instance[required]' => $required); + $this->drupalPost('admin/structure/types/manage/article/comment/fields/comment_body', $edit, t('Save settings')); + + // Preview an empty comment, and check if an error is shown. + $this->drupalPost('node/' . $this->node->nid, array(), t('Preview')); + $this->assertNoText('Comment field is required.', 'Can preview comment with empty required body.'); + + // Post an empty comment, and check if an error is shown. + $this->drupalPost('node/' . $this->node->nid, array(), t('Save')); + $this->assertNoText('Comment field is required.', 'Can save comment with empty required body.'); + $this->assertText('Your comment has been posted.', 'Can save comment with empty required body.'); + } + + /** + * Test that a comment can be previewed and saved without the comment_body field, + * and without generating warnings. + */ + function testCommentDeletedBody() { + // Delete the comment_body field. + $this->drupalLogin($this->admin_user); + $this->drupalPost('admin/structure/types/manage/article/comment/fields/comment_body/delete', array(), t('Delete')); + + // Preview an empty comment. + $this->drupalPost('node/' . $this->node->nid, array(), t('Preview')); + + // Post an empty comment. + $this->drupalPost('node/' . $this->node->nid, array(), t('Save')); + + // View the comment administration overview page. + $this->drupalGet('admin/content/comment'); + } + } /**