| 1 comment.test | CommentFieldsTest::testCommentEnable() |
Tests that comment module works when enabled after a content module.
File
- core/
modules/ comment/ tests/ comment.test, line 2136 - Tests for the Comment module.
Class
- CommentFieldsTest
- Tests fields on comments.
Code
function testCommentEnable() {
// Create a user to do module administration.
$this->admin_user = $this->backdropCreateUser(array(
'access administration pages',
'administer modules',
'administer fields',
'administer content types',
'administer comment settings',
'administer comments',
));
$this->backdropLogin($this->admin_user);
// Disable the comment module.
$edit = array();
$edit['modules[Comments][comment][enable]'] = FALSE;
$this->backdropPost('admin/modules', $edit, t('Save configuration'));
$this->resetAll();
$this->assertFalse(module_exists('comment'), 'Comment module disabled.');
// Enable core content type module: book.
$edit = array();
$edit['modules[System][book][enable]'] = 'book';
$this->backdropPost('admin/modules', $edit, t('Save configuration'));
$this->resetAll();
// Now enable the comment module.
$edit = array();
$edit['modules[Comments][comment][enable]'] = 'comment';
$this->backdropPost('admin/modules', $edit, t('Save configuration'));
$this->resetAll();
$this->assertTrue(module_exists('comment'), 'Comment module enabled.');
// Check that comments are not enabled by default.
$this->backdropGet('admin/structure/types/manage/book');
$this->assertNoFieldChecked('edit-comment-enabled', 'Comments not enabled on a new content type by default.');
$this->assertNoLink(t('Comment fields'));
$this->assertNoLink(t('Comment display'));
// Enable comments on the book content type.
$edit = array('comment_enabled' => TRUE);
$this->backdropPost(NULL, $edit, t('Save content type'));
$this->backdropGet('admin/structure/types/manage/book');
$this->assertFieldChecked('edit-comment-enabled', 'Comments are enabled after updating content type.');
$this->assertLink(t('Comment fields'));
$this->assertLink(t('Comment display'));
// Create a few test nodes on which comments can be posted.
$book_node = $this->backdropCreateNode(array('type' => 'book'));
$post_node = $this->backdropCreateNode(array('type' => 'post'));
$this->backdropLogout();
// Try to post a comment on the book node. A failure will be triggered if
// the comment body is missing on one of these forms, due to postComment()
// asserting that the body is actually posted correctly.
$this->web_user = $this->backdropCreateUser(array('access content', 'access comments', 'post comments', 'skip comment approval'));
$this->backdropLogin($this->web_user);
$book_comment_value = $this->randomName();
$this->postComment($book_node, $book_comment_value);
// Post an additional comment on a "post" node.
$post_comment_value = $this->randomName();
$this->postComment($post_node, $post_comment_value);
$this->backdropLogout();
$this->backdropLogin($this->admin_user);
// Verify comments are shown on admin/content/node.
$this->backdropGet('admin/content/comment');
$this->assertText($book_comment_value, 'Book comment found');
$this->assertText($post_comment_value, 'Post comment found');
// Disable comments on the book content type and verify the comment is
// removed from the listing.
$edit = array('comment_enabled' => FALSE);
$this->backdropPost('admin/structure/types/manage/book', $edit, t('Save content type'));
$this->backdropGet('admin/content/comment');
$this->assertNoText($book_comment_value, 'Book comment removed when comments are disabled on book content type');
$this->assertText($post_comment_value, 'Post comment still present when comments disabled on book content type');
}