- <?php
- * @file
- * Tests for the Comment module.
- */
-
- class CommentHelperCase extends BackdropWebTestCase {
- protected $admin_user;
- protected $web_user;
- protected $node;
- protected $profile = 'testing';
-
- function setUp($modules = array()) {
- $modules = func_get_args();
- if (isset($modules[0]) && is_array($modules[0])) {
- $modules = $modules[0];
- }
- $modules[] = 'comment';
- parent::setUp($modules);
-
-
- $this->backdropCreateContentType(array(
- 'type' => 'post',
- 'name' => 'Post',
- 'settings' => array(
- 'comment_default' => COMMENT_NODE_OPEN,
- ),
- 'is_new' => TRUE,
- ));
-
-
- $filtered_html_format = array(
- 'format' => 'filtered_html',
- 'name' => 'Filtered HTML',
- 'weight' => 0,
- 'editor' => 'ckeditor',
- 'filters' => array(
-
- 'filter_url' => array(
- 'weight' => 0,
- 'status' => 1,
- ),
-
- 'filter_html' => array(
- 'weight' => 1,
- 'status' => 1,
- ),
-
- 'filter_autop' => array(
- 'weight' => 2,
- 'status' => 1,
- ),
-
- 'filter_htmlcorrector' => array(
- 'weight' => 10,
- 'status' => 1,
- ),
- ),
- );
- $filtered_html_format = (object) $filtered_html_format;
- filter_format_save($filtered_html_format);
- $filtered_html_permission = filter_permission_name($filtered_html_format);
-
-
- user_role_grant_permissions(BACKDROP_ANONYMOUS_ROLE, array('access content', 'access comments', $filtered_html_permission));
- user_role_grant_permissions(BACKDROP_AUTHENTICATED_ROLE, array('access content', 'access comments', 'post comments', 'skip comment approval', $filtered_html_permission));
-
-
- $this->admin_user = $this->backdropCreateUser(array('administer site configuration', 'administer content types', 'create post content', 'edit any post content', 'delete any post content', 'administer comments', 'administer layouts', 'administer fields'));
- $this->web_user = $this->backdropCreateUser(array('create post content', 'edit own comments'));
- $this->node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1, 'uid' => $this->web_user->uid));
-
-
-
- config_get('system.core', 'cron_safe_threshold', 0);
- }
-
-
- * Posts a comment.
- *
- * @param Node|NULL $node
- * Node to post comment on or NULL to post to the previously loaded page.
- * @param $comment
- * Comment body.
- * @param $subject
- * Comment subject.
- * @param $contact
- * Set to NULL for no contact info, TRUE to ignore success checking, and
- * array of values to set contact info.
- */
- function postComment($node, $comment, $subject = '', $contact = NULL) {
- $langcode = LANGUAGE_NONE;
- $edit = array();
- $edit['comment_body[' . $langcode . '][0][value]'] = $comment;
- $node_type = node_type_get_type('post');
-
- $preview_mode = $node_type->settings['comment_preview'];
- $subject_mode = $node_type->settings['comment_subject_field'];
-
-
- if ($node !== NULL) {
- $this->backdropGet('comment/reply/' . $node->nid);
- }
-
- if ($subject_mode == TRUE) {
- $edit['subject'] = $subject;
- }
- else {
- $this->assertNoFieldByName('subject', '', 'Title field not found.');
- }
-
- if ($contact !== NULL && is_array($contact)) {
- $edit += $contact;
- }
- switch ($preview_mode) {
- case BACKDROP_REQUIRED:
-
- $this->assertNoFieldByName('op', t('Save'), 'Save button not found.');
- $this->backdropPost(NULL, $edit, t('Preview'));
-
-
- case BACKDROP_OPTIONAL:
- $this->assertFieldByName('op', t('Preview'), 'Preview button found.');
- $this->assertFieldByName('op', t('Save'), 'Save button found.');
- $this->backdropPost(NULL, $edit, t('Save'));
- break;
-
- case BACKDROP_DISABLED:
- $this->assertNoFieldByName('op', t('Preview'), 'Preview button not found.');
- $this->assertFieldByName('op', t('Save'), 'Save button found.');
- $this->backdropPost(NULL, $edit, t('Save'));
- break;
- }
- $match = array();
-
- preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
-
-
- if ($contact !== TRUE) {
- if ($subject && $subject_mode) {
- $this->assertText($subject, 'Comment subject posted.');
- }
- $this->assertText($comment, 'Comment body posted.');
- $this->assertTrue((!empty($match) && !empty($match[1])), 'Comment id found.');
- }
-
- if (isset($match[1])) {
- return entity_create('comment', array('id' => $match[1], 'subject' => $subject, 'comment' => $comment));
- }
- }
-
-
- * Checks current page for specified comment.
- *
- * @param object $comment
- * The comment object.
- * @param boolean $reply
- * Boolean indicating whether the comment is a reply to another comment.
- *
- * @return boolean
- * Boolean indicating whether the comment was found.
- */
- function commentExists($comment, $reply = FALSE) {
- if ($comment && is_object($comment)) {
- $regex = '/' . ($reply ? '<div class="indented">(.*?)' : '');
- $regex .= '<a id="comment-' . $comment->id . '"(.*?)';
- $regex .= '<article(.*?)';
- $regex .= $comment->subject . '(.*?)';
- $regex .= $comment->comment . '(.*?)';
- $regex .= '/s';
-
- return (boolean)preg_match($regex, $this->backdropGetContent());
- }
- else {
- return FALSE;
- }
- }
-
-
- * Deletes a comment.
- *
- * @param object $comment
- * Comment to delete.
- */
- function deleteComment($comment) {
- $this->backdropPost('comment/' . $comment->id . '/delete', array(), t('Delete'));
- $this->assertText(t('The comment and all its replies have been deleted.'), 'Comment deleted.');
- }
-
-
- * Sets the value governing whether the subject field should be enabled.
- *
- * @param boolean $enabled
- * Boolean specifying whether the subject field should be enabled.
- */
- function setCommentSubject($enabled) {
- $this->setCommentSettings('comment_subject_field', ($enabled ? '1' : '0'), 'Comment subject ' . ($enabled ? 'enabled' : 'disabled') . '.');
- }
-
-
- * Sets the value governing the previewing mode for the comment form.
- *
- * @param int $mode
- * The preview mode: BACKDROP_DISABLED, BACKDROP_OPTIONAL or BACKDROP_REQUIRED.
- */
- function setCommentPreview($mode) {
- switch ($mode) {
- case BACKDROP_DISABLED:
- $mode_text = 'disabled';
- break;
-
- case BACKDROP_OPTIONAL:
- $mode_text = 'optional';
- break;
-
- case BACKDROP_REQUIRED:
- $mode_text = 'required';
- break;
- }
- $this->setCommentSettings('comment_preview', $mode, format_string('Comment preview @mode_text.', array('@mode_text' => $mode_text)));
- }
-
-
- * Sets the value governing whether the comment form is on its own page.
- *
- * @param boolean $enabled
- * TRUE if the comment form should be displayed on the same page as the
- * comments; FALSE if it should be displayed on its own page.
- */
- function setCommentForm($enabled) {
- $this->setCommentSettings('comment_form_location', ($enabled ? COMMENT_FORM_BELOW : COMMENT_FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.');
- }
-
-
- * Sets the value governing restrictions on anonymous comments.
- *
- * @param integer $level
- * The level of the contact information allowed for anonymous comments:
- * - 0: No contact information allowed.
- * - 1: Contact information allowed but not required.
- * - 2: Contact information required.
- */
- function setCommentAnonymous($level) {
- $this->setCommentSettings('comment_anonymous', $level, format_string('Anonymous commenting set to level @level.', array('@level' => $level)));
- }
-
-
- * Sets the value specifying the default number of comments per page.
- *
- * @param integer $comments
- * Comments per page value.
- */
- function setCommentsPerPage($number) {
- $this->setCommentSettings('comment_per_page', $number, format_string('Number of comments per page set to @number.', array('@number' => $number)));
- }
-
-
- * Sets a comment config for the post content type.
- *
- * @param string $name
- * Name of setting.
- * @param string $value
- * Value of setting.
- * @param string $message
- * Status message to display.
- */
- function setCommentSettings($name, $value, $message) {
- $node_type = node_type_get_type('post');
- $node_type->settings[$name] = $value;
- node_type_save($node_type);
-
- $this->pass($message);
- }
-
-
- * Checks whether the commenter's contact information is displayed.
- *
- * @return boolean
- * Contact info is available.
- */
- function commentContactInfoAvailable() {
- return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->backdropGetContent());
- }
-
-
- * Performs the specified operation on the specified comment.
- *
- * @param object $comment
- * Comment to perform operation on.
- * @param string $operation
- * Operation to perform.
- * @param boolean $aproval
- * Operation is found on approval page.
- */
- function performCommentOperation($comment, $operation, $approval = FALSE) {
- $edit = array();
- $edit['operation'] = $operation;
- $edit['comments[' . $comment->id . ']'] = TRUE;
- $this->backdropPost('admin/content/comment' . ($approval ? '/approval' : ''), $edit, t('Execute'));
-
- if ($operation == 'delete') {
- $this->backdropPost(NULL, array(), t('Delete comments'));
- $this->assertRaw(format_plural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation @operation was performed on comment.', array('@operation' => $operation)));
- }
- else {
- $this->assertText(t('The update has been performed.'), format_string('Operation @operation was performed on comment.', array('@operation' => $operation)));
- }
- }
-
-
- * Gets the comment ID for an unapproved comment.
- *
- * @param string $subject
- * Comment subject to find.
- *
- * @return integer
- * Comment id.
- */
- function getUnapprovedComment($subject) {
- $this->backdropGet('admin/content/comment/approval');
- preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>(' . $subject . ')/', $this->backdropGetContent(), $match);
-
- return $match[2];
- }
- }
-
- class CommentInterfaceTest extends CommentHelperCase {
-
- * Tests the comment interface.
- */
- function testCommentInterface() {
- $langcode = LANGUAGE_NONE;
-
- $this->backdropLogin($this->admin_user);
- $this->setCommentPreview(BACKDROP_DISABLED);
- $this->setCommentForm(TRUE);
- $this->setCommentSubject(FALSE);
- $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
- $this->backdropLogout();
-
-
- $this->backdropLogin($this->web_user);
- $comment_text = $this->randomName();
- $comment = $this->postComment($this->node, $comment_text);
- $comment_loaded = comment_load($comment->id);
- $this->assertTrue($this->commentExists($comment), 'Comment found.');
-
-
- $this->backdropLogout();
- $this->backdropLogin($this->admin_user);
- $this->setCommentSubject(TRUE);
- $this->setCommentPreview(BACKDROP_REQUIRED);
- $this->backdropLogout();
-
-
- $this->backdropLogin($this->web_user);
- $subject_text = $this->randomName();
- $comment_text = $this->randomName();
- $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
- $comment_loaded = comment_load($comment->id);
- $this->assertTrue($this->commentExists($comment), 'Comment found.');
-
-
- $this->backdropGet('node/' . $this->node->nid . '/' . $comment->id);
- $this->assertText($subject_text, 'Individual comment subject found.');
- $this->assertText($comment_text, 'Individual comment body found.');
-
-
- $this->backdropLogout();
- $this->backdropLogin($this->admin_user);
- $this->setCommentSubject(TRUE);
- $this->setCommentPreview(BACKDROP_OPTIONAL);
-
-
- $this->backdropGet('comment/' . $comment->id . '/edit');
- $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => ''));
- $comment_loaded = comment_load($comment->id);
- $this->assertTrue(empty($comment_loaded->name) && $comment_loaded->uid == 0, 'Comment author successfully changed to anonymous.');
-
-
- $random_name = $this->randomName();
- $this->backdropGet('comment/' . $comment->id . '/edit');
- $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $random_name));
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertText($random_name . ' (' . t('not verified') . ')', 'Comment author successfully changed to an unverified user.');
-
-
- $this->backdropGet('comment/' . $comment->id . '/edit');
- $comment = $this->postComment(NULL, $comment->comment, $comment->subject, array('name' => $this->web_user->name));
- $comment_loaded = comment_load($comment->id);
- $this->assertTrue($comment_loaded->name == $this->web_user->name && $comment_loaded->uid == $this->web_user->uid, 'Comment author successfully changed to a registered user.');
-
- $this->backdropLogout();
-
-
-
- $this->backdropLogin($this->web_user);
- $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
- $this->assertText($subject_text, 'Individual comment-reply subject found.');
- $this->assertText($comment_text, 'Individual comment-reply body found.');
- $this->assertUniqueText($comment_text, 'Comment-reply body found only once.');
- $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
- $reply_loaded = comment_load($reply->id);
- $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
- $this->assertEqual($comment->id, $reply_loaded->pid, 'Pid of a reply to a comment is set correctly.');
- $this->assertEqual(rtrim($comment_loaded->thread, '/') . '.00/', $reply_loaded->thread, 'Thread of reply grows correctly.');
-
-
- $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
- $this->assertText($subject_text, 'Individual comment-reply subject found.');
- $this->assertText($comment_text, 'Individual comment-reply body found.');
- $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
- $reply_loaded = comment_load($reply->id);
- $this->assertTrue($this->commentExists($reply, TRUE), 'Second reply found.');
- $this->assertEqual(rtrim($comment_loaded->thread, '/') . '.01/', $reply_loaded->thread, 'Thread of second reply grows correctly.');
-
-
- $this->backdropGet('comment/' . $reply->id . '/edit');
- $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
- $this->assertTrue($this->commentExists($reply, TRUE), 'Modified reply found.');
-
-
- $this->backdropGet('node');
- $this->assertRaw('4 comments', 'Link to the 4 comments exist.');
-
-
- $this->setCommentsPerPage(2);
- $comment_new_page = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
- $this->assertTrue($this->commentExists($comment_new_page), 'Page one exists. %s');
- $this->backdropGet('node/' . $this->node->nid, array('query' => array('page' => 1)));
- $this->assertTrue($this->commentExists($reply, TRUE), 'Page two exists. %s');
- $this->setCommentsPerPage(50);
-
-
- $this->node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1, 'comment' => COMMENT_NODE_HIDDEN));
- $this->assertTrue($this->node, 'Post node created.');
- $this->backdropGet('comment/reply/' . $this->node->nid);
- $this->assertText('This discussion is closed', 'Posting to node with comments disabled');
- $this->assertNoField('edit-comment', 'Comment body field found.');
-
-
- $this->node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1, 'comment' => COMMENT_NODE_CLOSED));
- $this->assertTrue($this->node, 'Post node created.');
- $this->backdropGet('comment/reply/' . $this->node->nid);
- $this->assertText('This discussion is closed', 'Posting to node with comments read-only');
- $this->assertNoField('edit-comment', 'Comment body field found.');
-
-
- $this->node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1, 'comment' => COMMENT_NODE_OPEN));
- $this->assertTrue($this->node, 'Post node created.');
- $this->backdropGet('comment/reply/' . $this->node->nid);
- $this->assertNoText('This discussion is closed', 'Posting to node with comments enabled');
- $this->assertField('edit-comment-body-' . $langcode . '-0-value', 'Comment body field found.');
-
-
- $this->backdropLogout();
- $this->backdropLogin($this->admin_user);
- $this->deleteComment($comment);
- $this->deleteComment($comment_new_page);
-
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertFalse($this->commentExists($comment), 'Comment not found.');
- $this->assertFalse($this->commentExists($reply, TRUE), 'Reply not found.');
-
-
- $this->backdropLogin($this->admin_user);
- $this->setCommentForm(TRUE);
- $this->backdropLogout();
-
-
- $this->backdropLogin($this->web_user);
- $this->backdropGet('node/' . $this->node->nid);
- $form_comment = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
- $this->assertTrue($this->commentExists($form_comment), 'Form comment found.');
-
-
- $this->backdropLogout();
- $this->backdropLogin($this->admin_user);
- $this->setCommentForm(FALSE);
- }
-
-
- * Tests new comment marker.
- */
- public function testCommentNewCommentsIndicator() {
-
-
- $this->backdropLogin($this->admin_user);
- $this->node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1, 'comment' => COMMENT_NODE_OPEN));
- $this->backdropGet('node');
- $this->assertNoLink(t('@count comments', array('@count' => 0)));
- $this->assertNoLink(t('@count new comments', array('@count' => 0)));
- $this->assertLink(t('Read more'));
- $count = $this->xpath('//article[@id=:id]//ul/li', array(':id' => 'node-' . $this->node->nid));
- $this->assertTrue(count($count) == 2, 'Two node links found ("Read more" and "Add comment")');
-
-
-
- $comment = entity_create('comment', array(
- 'cid' => NULL,
- 'nid' => $this->node->nid,
- 'node_type' => $this->node->type,
- 'pid' => 0,
- 'uid' => $this->loggedInUser->uid,
- 'status' => COMMENT_PUBLISHED,
- 'subject' => $this->randomName(),
- 'hostname' => ip_address(),
- 'langcode' => LANGUAGE_NONE,
- 'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
- ));
- comment_save($comment);
- $this->backdropLogout();
-
-
- $this->backdropLogin($this->web_user);
- $this->backdropGet('node');
- $this->assertLink(t('1 new comment'));
- $this->clickLink(t('1 new comment'));
- $this->assertRaw('<a id="new"></a>', 'Found "new" marker.');
- $this->assertTrue($this->xpath('//a[@id=:new]/following-sibling::a[1][@id=:comment_id]', array(':new' => 'new', ':comment_id' => 'comment-1')), 'The "new" anchor is positioned at the right comment.');
-
-
-
- sleep(1);
-
-
- $this->backdropGet('node');
- $this->assertLink(t('1 comment'));
- $this->assertLink(t('Read more'));
- $this->assertNoLink(t('1 new comment'));
- $this->assertNoLink(t('@count new comments', array('@count' => 0)));
- $count = $this->xpath('//article[@id=:id]//ul/li', array(':id' => 'node-' . $this->node->nid));
- $this->assertTrue(count($count) == 3, print_r($count, TRUE));
- }
-
-
- * Tests CSS classes on comments.
- */
- function testCommentClasses() {
-
- $parameters = array(
- 'node_uid' => array(0, $this->web_user->uid),
- 'comment_uid' => array(0, $this->web_user->uid, $this->admin_user->uid),
- 'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED),
- 'user' => array('anonymous', 'authenticated', 'admin'),
- );
- $permutations = $this->generatePermutations($parameters);
-
- foreach ($permutations as $case) {
-
- $node = $this->backdropCreateNode(array('type' => 'post', 'uid' => $case['node_uid']));
-
-
- $comment = entity_create('comment', array(
- 'nid' => $node->nid,
- 'uid' => $case['comment_uid'],
- 'status' => $case['comment_status'],
- 'subject' => $this->randomName(),
- 'langcode' => LANGUAGE_NONE,
- 'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
- ));
- comment_save($comment);
-
-
- switch ($case['user']) {
- case 'anonymous':
- $this->backdropLogout();
- $case['user_uid'] = 0;
- break;
-
- case 'authenticated':
- $this->backdropLogin($this->web_user);
- $case['user_uid'] = $this->web_user->uid;
- break;
-
- case 'admin':
- $this->backdropLogin($this->admin_user);
- $case['user_uid'] = $this->admin_user->uid;
- break;
- }
-
-
-
- sleep(3);
-
-
- $this->backdropGet('node/' . $node->nid);
-
-
- if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
-
- $comments = $this->xpath('//*[contains(@class, "comment-by-anonymous")]');
- if ($case['comment_uid'] == 0) {
- $this->assertTrue(count($comments) == 1, 'comment-by-anonymous class found.');
- }
- else {
- $this->assertFalse(count($comments), 'comment-by-anonymous class not found.');
- }
-
-
- $comments = $this->xpath('//*[contains(@class, "comment-by-node-author")]');
- if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['node_uid']) {
- $this->assertTrue(count($comments) == 1, 'comment-by-node-author class found.');
- }
- else {
- $this->assertFalse(count($comments), 'comment-by-node-author class not found.');
- }
-
-
- $comments = $this->xpath('//*[contains(@class, "comment-by-viewer")]');
- if ($case['comment_uid'] > 0 && $case['comment_uid'] == $case['user_uid']) {
- $this->assertTrue(count($comments) == 1, 'comment-by-viewer class found.');
- }
- else {
- $this->assertFalse(count($comments), 'comment-by-viewer class not found.');
- }
- }
-
-
- $comments = $this->xpath('//*[contains(@class, "comment-unpublished")]');
- if ($case['comment_status'] == COMMENT_NOT_PUBLISHED && $case['user'] == 'admin') {
- $this->assertTrue(count($comments) == 1, 'comment-unpublished class found.');
- }
- else {
- $this->assertFalse(count($comments), 'comment-unpublished class not found.');
- }
-
-
- if ($case['comment_status'] == COMMENT_PUBLISHED || $case['user'] == 'admin') {
- $comments = $this->xpath('//*[contains(@class, "comment-new")]');
- if ($case['user'] != 'anonymous') {
- $this->assertTrue(count($comments) == 1, 'comment-new class found.');
-
-
-
- sleep(2);
-
-
- $this->backdropGet('node/' . $node->nid);
- $comments = $this->xpath('//*[contains(@class, "comment-new")]');
- $this->assertFalse(count($comments), 'comment-new class not found.');
- }
- else {
- $this->assertFalse(count($comments), 'comment-new class not found.');
- }
- }
- }
- }
-
-
- * Tests the node comment statistics.
- */
- function testCommentNodeCommentStatistics() {
- $langcode = LANGUAGE_NONE;
-
- $this->backdropLogin($this->admin_user);
- $this->setCommentPreview(BACKDROP_DISABLED);
- $this->setCommentForm(TRUE);
- $this->setCommentSubject(FALSE);
- $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
- $this->backdropLogout();
-
-
- $this->web_user2 = $this->backdropCreateUser(array('access comments', 'post comments', 'create post content', 'edit own comments'));
-
-
- $node = node_load($this->node->nid);
- $this->assertEqual($node->last_comment_timestamp, $this->node->created, 'The initial value of node last_comment_timestamp is the node created date.');
- $this->assertEqual($node->last_comment_name, NULL, 'The initial value of node last_comment_name is NULL.');
- $this->assertEqual($node->last_comment_uid, $this->web_user->uid, 'The initial value of node last_comment_uid is the node uid.');
- $this->assertEqual($node->comment_count, 0, 'The initial value of node comment_count is zero.');
-
-
- $this->backdropLogin($this->web_user2);
- $comment_text = $this->randomName();
- $comment = $this->postComment($this->node, $comment_text);
- $comment_loaded = comment_load($comment->id);
-
-
-
- $node = node_load($this->node->nid, NULL, TRUE);
- $this->assertEqual($node->last_comment_name, NULL, 'The value of node last_comment_name is NULL.');
- $this->assertEqual($node->last_comment_uid, $this->web_user2->uid, 'The value of node last_comment_uid is the comment #1 uid.');
- $this->assertEqual($node->comment_count, 1, 'The value of node comment_count is 1.');
-
-
- config_set('system.core', 'user_register', USER_REGISTER_VISITORS);
- $this->backdropLogin($this->admin_user);
- user_role_change_permissions(BACKDROP_ANONYMOUS_ROLE, array(
- 'access comments' => TRUE,
- 'post comments' => TRUE,
- 'skip comment approval' => FALSE,
- ));
-
- $this->setCommentAnonymous('1');
- $this->backdropLogout();
-
-
- $this->backdropGet('comment/reply/' . $this->node->nid);
- $anonymous_comment = $this->postComment($this->node, $this->randomName(), '', TRUE);
- $comment_unpublished_loaded = comment_load($anonymous_comment->id);
-
-
-
-
- $node = node_load($this->node->nid, NULL, TRUE);
- $this->assertEqual($node->last_comment_name, NULL, 'The value of node last_comment_name is still NULL.');
- $this->assertEqual($node->last_comment_uid, $this->web_user2->uid, 'The value of node last_comment_uid is still the comment #1 uid.');
- $this->assertEqual($node->comment_count, 1, 'The value of node comment_count is still 1.');
-
-
- $this->backdropLogin($this->admin_user);
- user_role_change_permissions(BACKDROP_ANONYMOUS_ROLE, array(
- 'access comments' => TRUE,
- 'post comments' => TRUE,
- 'skip comment approval' => TRUE,
- ));
- $this->backdropLogout();
-
-
- $this->backdropGet('comment/reply/' . $this->node->nid);
- $anonymous_comment = $this->postComment($this->node, $this->randomName(), '', array('name' => $this->randomName()));
- $comment_loaded = comment_load($anonymous_comment->id);
-
-
-
- $node = node_load($this->node->nid, NULL, TRUE);
- $this->assertEqual($node->last_comment_name, $comment_loaded->name, 'The value of node last_comment_name is the name of the anonymous user.');
- $this->assertEqual($node->last_comment_uid, 0, 'The value of node last_comment_uid is zero.');
- $this->assertEqual($node->comment_count, 2, 'The value of node comment_count is 2.');
- }
-
-
- * Tests comment links.
- *
- * The output of comment links depends on various environment conditions:
- * - Various Comment module configuration settings, user registration
- * settings, and user access permissions.
- * - Whether the user is authenticated or not, and whether any comments exist.
- *
- * To account for all possible cases, this test creates permutations of all
- * possible conditions and tests the expected appearance of comment links in
- * each environment.
- */
- function testCommentLinks() {
-
- theme_enable(array('stark'));
- config_set('system.core', 'theme_default', 'stark');
-
-
-
- user_role_delete(key($this->web_user->roles));
-
-
-
- $conditions = array(
- 'authenticated' => array(FALSE, TRUE),
- 'comment count' => array(FALSE, TRUE),
- 'access comments' => array(0, 1),
- 'post comments' => array(0, 1),
- 'form' => array(COMMENT_FORM_BELOW, COMMENT_FORM_SEPARATE_PAGE),
-
-
- 'user_register' => array(USER_REGISTER_VISITORS, USER_REGISTER_ADMINISTRATORS_ONLY),
-
-
-
-
- );
-
- $environments = $this->generatePermutations($conditions);
- foreach ($environments as $info) {
- $this->assertCommentLinks($info);
- }
- }
-
-
- * Re-configures the environment, module settings, and user permissions.
- *
- * @param $info
- * An associative array describing the environment to setup:
- * - Environment conditions:
- * - authenticated: Boolean whether to test with $this->web_user or
- * anonymous.
- * - comment count: Boolean whether to test with a new/unread comment on
- * $this->node or no comments.
- * - Configuration settings:
- * - form: COMMENT_FORM_BELOW or COMMENT_FORM_SEPARATE_PAGE.
- * - user_register: USER_REGISTER_ADMINISTRATORS_ONLY or
- * USER_REGISTER_VISITORS.
- * - contact: COMMENT_ANONYMOUS_MAY_CONTACT or
- * COMMENT_ANONYMOUS_MAYNOT_CONTACT.
- * - comments: COMMENT_NODE_OPEN, COMMENT_NODE_CLOSED, or
- * COMMENT_NODE_HIDDEN.
- * - User permissions:
- * These are granted or revoked for the user, according to the
- * 'authenticated' flag above. Pass 0 or 1 as parameter values. See
- * user_role_change_permissions().
- * - access comments
- * - post comments
- * - skip comment approval
- * - edit own comments
- */
- function setEnvironment(array $info) {
- static $current;
-
-
- if (!isset($current)) {
- $current = array(
- 'authenticated' => FALSE,
- 'comment count' => FALSE,
- 'form' => COMMENT_FORM_BELOW,
- 'user_register' => USER_REGISTER_VISITORS,
- 'contact' => COMMENT_ANONYMOUS_MAY_CONTACT,
- 'comments' => COMMENT_NODE_OPEN,
- 'access comments' => 0,
- 'post comments' => 0,
-
- 'skip comment approval' => 1,
- 'edit own comments' => 0,
- );
- }
-
- $info = array_merge($current, $info);
-
-
- if ($current['authenticated'] != $info['authenticated']) {
- if ($this->loggedInUser) {
- $this->backdropLogout();
- }
- else {
- $this->backdropLogin($this->web_user);
- }
- }
- if ($current['comment count'] != $info['comment count']) {
- if ($info['comment count']) {
-
-
- $comment = entity_create('comment', array(
- 'cid' => NULL,
- 'nid' => $this->node->nid,
- 'node_type' => $this->node->type,
- 'pid' => 0,
- 'uid' => 0,
- 'status' => COMMENT_PUBLISHED,
- 'subject' => $this->randomName(),
- 'hostname' => ip_address(),
- 'langcode' => LANGUAGE_NONE,
- 'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
- ));
- comment_save($comment);
- $this->comment = $comment;
-
-
-
- db_delete('history')->condition('nid', $this->node->nid)->execute();
- }
- else {
- $cids = db_query("SELECT cid FROM {comment}")->fetchCol();
- comment_delete_multiple($cids);
- unset($this->comment);
- }
- }
-
-
- $node_type = node_type_get_type($this->node->type);
- $node_type->settings['comment_form_location'] = $info['form'];
- $node_type->settings['comment_anonymous'] = $info['contact'];
- node_type_save($node_type);
- if ($this->node->comment != $info['comments']) {
- $this->node->comment = $info['comments'];
- node_save($this->node);
- }
-
-
- config_set('system.core', 'user_register', $info['user_register']);
-
-
- $role_name = ($this->loggedInUser ? BACKDROP_AUTHENTICATED_ROLE : BACKDROP_ANONYMOUS_ROLE);
- $perms = array_intersect_key($info, array('access comments' => 1, 'post comments' => 1, 'skip comment approval' => 1, 'edit own comments' => 1));
- user_role_change_permissions($role_name, $perms);
-
-
-
- $t_form = array(
- COMMENT_FORM_BELOW => 'below',
- COMMENT_FORM_SEPARATE_PAGE => 'separate page',
- );
- $t_contact = array(
- COMMENT_ANONYMOUS_MAY_CONTACT => 'optional',
- COMMENT_ANONYMOUS_MAYNOT_CONTACT => 'disabled',
- COMMENT_ANONYMOUS_MUST_CONTACT => 'required',
- );
- $t_comments = array(
- COMMENT_NODE_OPEN => 'open',
- COMMENT_NODE_CLOSED => 'closed',
- COMMENT_NODE_HIDDEN => 'hidden',
- );
- $verbose = $info;
- $verbose['form'] = $t_form[$info['form']];
- $verbose['contact'] = $t_contact[$info['contact']];
- $verbose['comments'] = $t_comments[$info['comments']];
- $message = t('Changed environment:<pre>@verbose</pre>', array(
- '@verbose' => var_export($verbose, TRUE),
- ));
- $this->assert('debug', $message, 'Debug');
-
-
- $current = $info;
-
- return $info;
- }
-
-
- * Asserts that comment links appear according to the passed environment.
- *
- * @param $info
- * An associative array describing the environment to pass to
- * setEnvironment().
- */
- function assertCommentLinks(array $info) {
- $info = $this->setEnvironment($info);
-
- $nid = $this->node->nid;
-
- foreach (array('', "node/$nid") as $path) {
- $this->backdropGet($path);
-
-
- if ($info['access comments']) {
- if ($path == '') {
-
-
- if ($info['comment count']) {
- $this->assertLink(t('1 comment'));
-
-
-
-
- if ($this->loggedInUser && isset($this->comment) && !isset($this->comment->seen)) {
- $this->assertLink(t('1 new comment'));
- $this->comment->seen = TRUE;
- }
- }
- }
- }
- else {
- $this->assertNoLink(t('1 comment'));
- $this->assertNoLink(t('1 new comment'));
- }
-
-
-
- if ($path == "node/$nid" && $this->loggedInUser && isset($this->comment)) {
- $this->comment->seen = TRUE;
- }
-
-
- if (!$info['post comments']) {
- $this->assertNoLink('Add comment');
-
-
-
-
- if (!$this->loggedInUser) {
- if (user_access('post comments', $this->web_user)) {
-
- if ($info['user_register'] != USER_REGISTER_ADMINISTRATORS_ONLY) {
- $this->assertText('Log in or register to post comments');
- }
- else {
- $this->assertText('Log in to post comments');
- }
- }
- else {
- $this->assertNoText('Log in or register to post comments');
- $this->assertNoText('Log in to post comments');
- }
- }
- }
-
- else {
- $this->assertNoText('Log in or register to post comments');
-
-
-
- if ($path == "node/$nid" && $info['form'] == COMMENT_FORM_BELOW && (!$info['comment count'] || !$info['access comments'])) {
- $this->assertNoLink('Add comment');
- }
- else {
- $this->assertLink('Add comment');
-
-
-
- if ($info['form'] == COMMENT_FORM_SEPARATE_PAGE) {
- $this->assertLinkByHref("comment/reply/$nid#comment-form", 0, 'Comment form link destination is on a separate page.');
- $this->assertNoLinkByHref("node/$nid#comment-form");
- }
- else {
- $this->assertLinkByHref("node/$nid#comment-form", 0, 'Comment form link destination is on node.');
- $this->assertNoLinkByHref("comment/reply/$nid#comment-form");
- }
- }
-
-
-
- if ($path == "node/$nid") {
- $elements = $this->xpath('//form[@id=:id]', array(':id' => 'comment-form'));
- if ($info['form'] == COMMENT_FORM_BELOW) {
- $this->assertTrue(count($elements), 'Comment form found below.');
- }
- else {
- $this->assertFalse(count($elements), 'Comment form not found below.');
- }
- }
- }
- }
- }
- }
-
- * Tests previewing comments.
- */
- class CommentPreviewTest extends CommentHelperCase {
-
- * Tests comment preview.
- */
- function testCommentPreview() {
- $langcode = LANGUAGE_NONE;
-
-
- $this->backdropLogin($this->admin_user);
- $this->setCommentPreview(BACKDROP_OPTIONAL);
- $this->setCommentForm(TRUE);
- $this->setCommentSubject(TRUE);
- $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
- $this->backdropLogout();
-
-
- $this->backdropLogin($this->web_user);
- config('system.core')
- ->set('user_signatures', 1)
- ->set('user_pictures', 1)
- ->save();
- $test_signature = $this->randomName();
- $edit['signature[value]'] = '<a href="http://example.com/">' . $test_signature. '</a>';
- $edit['signature[format]'] = 'filtered_html';
- $image = current($this->backdropGetTestFiles('image'));
- $edit['files[picture_upload]'] = backdrop_realpath($image->uri);
- $this->backdropPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save'));
-
-
- $edit = array();
- $edit['subject'] = $this->randomName(8);
- $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
- $this->backdropPost('node/' . $this->node->nid, $edit, t('Preview'));
-
-
- $this->assertTitle(t('Preview comment | Backdrop CMS'), 'Page title is "Preview comment".');
- $this->assertText($edit['subject'], 'Title displayed.');
- $this->assertText($edit['comment_body[' . $langcode . '][0][value]'], 'Comment displayed.');
-
-
- $this->assertFieldByName('subject', $edit['subject'], 'Title field displayed.');
- $this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], 'Comment field displayed.');
-
-
- $this->assertLink($test_signature);
-
-
- $this->assertFieldByXPath("//article[contains(@class, 'comment-preview')]//div[contains(@class, 'user-picture')]//img", NULL, 'User picture displayed.');
- }
-
-
- * Tests comment edit, preview, and save.
- */
- function testCommentEditPreviewSave() {
- $langcode = LANGUAGE_NONE;
- $web_user = $this->backdropCreateUser(array('access comments', 'post comments', 'skip comment approval'));
- $this->backdropLogin($this->admin_user);
- $this->setCommentPreview(BACKDROP_OPTIONAL);
- $this->setCommentForm(TRUE);
- $this->setCommentSubject(TRUE);
- $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
-
- $edit = array();
- $edit['subject'] = $this->randomName(8);
- $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
- $edit['name'] = $web_user->name;
- $edit['date'] = '2008-03-02 17:23 +0300';
- $raw_date = strtotime($edit['date']);
- $expected_text_date = format_date($raw_date, 'medium', NULL, 'UTC');
- $expected_form_date = format_date($raw_date, 'custom', 'Y-m-d H:i O', 'UTC');
- $comment = $this->postComment($this->node, $edit['comment_body[' . $langcode . '][0][value]'], '', TRUE);
- $this->backdropPost('comment/' . $comment->id . '/edit', $edit, t('Preview'));
-
-
- $this->assertTitle(t('Preview comment | Backdrop CMS'), 'Page title is "Preview comment".');
- $this->assertText($edit['subject'], 'Title displayed.');
- $this->assertText($edit['comment_body[' . $langcode . '][0][value]'], 'Comment displayed.');
- $this->assertText($edit['name'], 'Author displayed.');
- $this->assertText($expected_text_date, 'Date displayed.');
-
-
- $this->assertFieldByName('subject', $edit['subject'], 'Title field displayed.');
- $this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], 'Comment field displayed.');
- $this->assertFieldByName('name', $edit['name'], 'Author field displayed.');
- $this->assertFieldByName('date', $edit['date'], 'Date field displayed.');
-
-
- $this->backdropPost('comment/' . $comment->id . '/edit', $edit, t('Save'));
- $this->assertText(t('Your comment has been posted.'), 'Comment posted.');
-
-
- $this->backdropGet('comment/' . $comment->id . '/edit');
- $this->assertFieldByName('subject', $edit['subject'], 'Title field displayed.');
- $this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], 'Comment field displayed.');
- $this->assertFieldByName('name', $edit['name'], 'Author field displayed.');
- $this->assertFieldByName('date', $expected_form_date, 'Date field displayed.');
-
-
- $displayed = array();
- $displayed['subject'] = (string) current($this->xpath("//input[@id='edit-subject']/@value"));
- $displayed['comment_body[' . $langcode . '][0][value]'] = (string) current($this->xpath("//textarea[@id='edit-comment-body-" . $langcode . "-0-value']"));
- $displayed['name'] = (string) current($this->xpath("//input[@id='edit-name']/@value"));
- $displayed['date'] = (string) current($this->xpath("//input[@id='edit-date']/@value"));
- $this->backdropPost('comment/' . $comment->id . '/edit', $displayed, t('Save'));
-
-
- $comment_loaded = comment_load($comment->id);
- $this->assertEqual($comment_loaded->subject, $edit['subject'], 'Title loaded.');
- $this->assertEqual($comment_loaded->comment_body[$langcode][0]['value'], $edit['comment_body[' . $langcode . '][0][value]'], 'Comment body loaded.');
- $this->assertEqual($comment_loaded->name, $edit['name'], 'Name loaded.');
- $this->assertEqual($comment_loaded->created, $raw_date, 'Date loaded.');
-
- }
-
- }
- * Tests anonymous commenting.
- */
- class CommentAnonymous extends CommentHelperCase {
- function setUp($modules = array()) {
- parent::setUp();
- config_set('system.core', 'user_register', USER_REGISTER_VISITORS);
- }
-
-
- * Tests anonymous comment functionality.
- */
- function testAnonymous() {
- $this->backdropLogin($this->admin_user);
-
- user_role_change_permissions(BACKDROP_ANONYMOUS_ROLE, array(
- 'access comments' => TRUE,
- 'post comments' => TRUE,
- 'skip comment approval' => TRUE,
- ));
- $this->setCommentAnonymous('0');
- $this->backdropLogout();
-
-
- $anonymous_comment1 = $this->postComment($this->node, $this->randomName());
- $this->assertTrue($this->commentExists($anonymous_comment1), 'Anonymous comment without contact info found.');
-
-
- $this->backdropLogin($this->admin_user);
- $this->setCommentAnonymous('1');
-
-
- $this->backdropGet('comment/' . $anonymous_comment1->id . '/edit');
- $edited_comment = $this->postComment(NULL, $this->randomName());
- $this->assertTrue($this->commentExists($edited_comment, FALSE), 'Modified reply found.');
- $this->backdropLogout();
-
-
- $this->backdropGet('comment/reply/' . $this->node->nid);
- $this->assertTrue($this->commentContactInfoAvailable(), 'Contact information available.');
-
- $anonymous_comment2 = $this->postComment($this->node, $this->randomName());
- $this->assertTrue($this->commentExists($anonymous_comment2), 'Anonymous comment with contact info (optional) found.');
-
-
- $langcode = LANGUAGE_NONE;
- $edit = array(
- 'name' => $this->admin_user->name,
- 'mail' => $this->randomName() . '@example.com',
- 'subject' => $this->randomName(),
- "comment_body[$langcode][0][value]" => $this->randomName(),
- );
- $this->setCommentSubject(TRUE);
-
- $this->backdropPost('comment/reply/' . $this->node->nid, $edit, t('Save'));
- $this->assertText(t('The name you used is a registered username. If it belongs to you, then login to post. If not, then use another name.'));
-
-
- $this->backdropLogin($this->admin_user);
- $this->setCommentAnonymous('2');
- $this->backdropLogout();
-
-
- $this->backdropGet('comment/reply/' . $this->node->nid);
- $this->assertTrue($this->commentContactInfoAvailable(), 'Contact information available.');
-
- $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), '', TRUE);
-
- $this->assertText(t('E-mail field is required.'), 'E-mail required.');
- $this->assertFalse($this->commentExists($anonymous_comment3), 'Anonymous comment with contact info (required) not found.');
-
-
- $author_name = $this->randomName();
- $author_mail = $this->randomName() . '@example.com';
- $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), '', array('name' => $author_name, 'mail' => $author_mail));
- $this->assertTrue($this->commentExists($anonymous_comment3), 'Anonymous comment with contact info (required) found.');
-
-
- $this->backdropLogin($this->admin_user);
- $this->backdropGet('comment/' . $anonymous_comment3->id . '/edit');
- $this->assertRaw($author_name, "The anonymous user's name is correct when editing the comment.");
- $this->assertRaw($author_mail, "The anonymous user's e-mail address is correct when editing the comment.");
-
-
- $this->performCommentOperation($anonymous_comment3, 'unpublish');
-
- $this->backdropGet('admin/content/comment/approval');
- $this->assertRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was unpublished.');
-
-
- $this->performCommentOperation($anonymous_comment3, 'publish', TRUE);
-
- $this->backdropGet('admin/content/comment');
- $this->assertRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was published.');
-
-
- $this->performCommentOperation($anonymous_comment3, 'delete');
-
- $this->backdropGet('admin/content/comment');
- $this->assertNoRaw('comments[' . $anonymous_comment3->id . ']', 'Comment was deleted.');
- $this->backdropLogout();
-
-
- user_role_change_permissions(BACKDROP_ANONYMOUS_ROLE, array(
- 'access comments' => FALSE,
- 'post comments' => FALSE,
- 'skip comment approval' => FALSE,
- ));
-
-
-
-
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.');
- $this->assertNoLink('Add comment', 'Link to add comment was found.');
-
-
- $this->backdropGet('comment/reply/' . $this->node->nid);
- $this->assertText('You are not authorized to post comments', 'Error attempting to post comment.');
- $this->assertNoFieldByName('subject', '', 'Title field not found.');
- $this->assertNoFieldByName("comment_body[$langcode][0][value]", '', 'Comment field not found.');
-
- user_role_change_permissions(BACKDROP_ANONYMOUS_ROLE, array(
- 'access comments' => TRUE,
- 'post comments' => FALSE,
- 'skip comment approval' => FALSE,
- ));
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments were displayed.');
- $this->assertLink('Log in', 1, 'Link to log in was found.');
- $this->assertLink('register', 1, 'Link to register was found.');
-
- user_role_change_permissions(BACKDROP_ANONYMOUS_ROLE, array(
- 'access comments' => FALSE,
- 'post comments' => TRUE,
- 'skip comment approval' => TRUE,
- ));
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.');
- $this->assertFieldByName('subject', '', 'Title field found.');
- $this->assertFieldByName("comment_body[$langcode][0][value]", '', 'Comment field found.');
-
- $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $anonymous_comment3->id);
- $this->assertText('You are not authorized to view comments', 'Error attempting to post reply.');
- $this->assertNoText($author_name, 'Comment not displayed.');
- }
- }
-
- * Verifies pagination of comments.
- */
- class CommentPagerTest extends CommentHelperCase {
-
- * Confirms comment paging works correctly with flat and threaded comments.
- */
- function testCommentPaging() {
- $this->backdropLogin($this->admin_user);
-
-
- $this->setCommentForm(TRUE);
- $this->setCommentSubject(TRUE);
- $this->setCommentPreview(BACKDROP_DISABLED);
-
-
- $node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1));
- $comments = array();
- $comments[] = $this->postComment($node, $this->randomName(), '', TRUE);
- $comments[] = $this->postComment($node, $this->randomName(), '', TRUE);
- $comments[] = $this->postComment($node, $this->randomName(), '', TRUE);
-
- $this->setCommentSettings('comment_mode', COMMENT_MODE_FLAT, 'Comment paging changed.');
-
-
-
- $this->setCommentsPerPage(1);
-
-
-
- $this->backdropGet('node/' . $node->nid);
- $this->assertRaw(t('next'), 'Paging links found.');
- $this->assertTrue($this->commentExists($comments[0]), 'Comment 1 appears on page 1.');
- $this->assertFalse($this->commentExists($comments[1]), 'Comment 2 does not appear on page 1.');
- $this->assertFalse($this->commentExists($comments[2]), 'Comment 3 does not appear on page 1.');
-
-
- $this->backdropGet('node/' . $node->nid, array('query' => array('page' => 1)));
- $this->assertTrue($this->commentExists($comments[1]), 'Comment 2 appears on page 2.');
- $this->assertFalse($this->commentExists($comments[0]), 'Comment 1 does not appear on page 2.');
- $this->assertFalse($this->commentExists($comments[2]), 'Comment 3 does not appear on page 2.');
-
-
- $this->backdropGet('node/' . $node->nid, array('query' => array('page' => 2)));
- $this->assertTrue($this->commentExists($comments[2]), 'Comment 3 appears on page 3.');
- $this->assertFalse($this->commentExists($comments[0]), 'Comment 1 does not appear on page 3.');
- $this->assertFalse($this->commentExists($comments[1]), 'Comment 2 does not appear on page 3.');
-
-
- $replies = array();
- $oldest_comment = reset($comments);
- $this->backdropGet('comment/reply/' . $node->nid . '/' . $oldest_comment->id);
- $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
-
- $this->setCommentsPerPage(2);
-
-
- $this->backdropGet('node/' . $node->nid, array('query' => array('page' => 0)));
- $this->assertFalse($this->commentExists($reply, TRUE), 'In flat mode, reply does not appear on page 1.');
-
-
-
-
- $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.');
- $this->backdropGet('node/' . $node->nid, array('query' => array('page' => 0)));
- $this->assertTrue($this->commentExists($reply, TRUE), 'In threaded mode, reply appears on page 1.');
- $this->assertFalse($this->commentExists($comments[1]), 'In threaded mode, comment 2 has been bumped off of page 1.');
-
-
-
- $reply2 = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
- $this->backdropGet('node/' . $node->nid, array('query' => array('page' => 0)));
- $this->assertFalse($this->commentExists($reply2, TRUE), 'In threaded mode where # replies > # comments per page, the newest reply does not appear on page 1.');
-
- $this->backdropLogout();
- }
-
-
- * Tests comment ordering and threading.
- */
- function testCommentOrderingThreading() {
- $this->backdropLogin($this->admin_user);
-
-
- $this->setCommentForm(TRUE);
- $this->setCommentSubject(TRUE);
- $this->setCommentPreview(BACKDROP_DISABLED);
-
-
- $this->setCommentsPerPage(1000);
-
-
- $node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1));
- $comments = array();
- $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
- $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
- $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
-
-
- $this->backdropGet('comment/reply/' . $node->nid . '/' . $comments[1]->id);
- $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
-
-
- $this->backdropGet('comment/reply/' . $node->nid . '/' . $comments[0]->id);
- $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
-
-
- $this->backdropGet('comment/reply/' . $node->nid . '/' . $comments[2]->id);
- $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
-
-
- $this->backdropGet('comment/reply/' . $node->nid . '/' . $comments[3]->id);
- $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
-
-
-
-
-
-
-
-
-
-
- $this->setCommentSettings('comment_mode', COMMENT_MODE_FLAT, 'Comment paging changed.');
-
- $expected_order = array(
- 0,
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- );
- $this->backdropGet('node/' . $node->nid);
- $this->assertCommentOrder($comments, $expected_order);
-
- $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.');
-
- $expected_order = array(
- 0,
- 4,
- 1,
- 3,
- 6,
- 2,
- 5,
- );
- $this->backdropGet('node/' . $node->nid);
- $this->assertCommentOrder($comments, $expected_order);
- }
-
-
- * Asserts that the comments are displayed in the correct order.
- *
- * @param $comments
- * And array of comments.
- * @param $expected_order
- * An array of keys from $comments describing the expected order.
- */
- function assertCommentOrder(array $comments, array $expected_order) {
- $expected_cids = array();
-
-
- foreach ($expected_order as $key) {
- $expected_cids[] = $comments[$key]->id;
- }
-
- $comment_anchors = $this->xpath('//a[starts-with(@id,"comment-")]');
- $result_order = array();
- foreach ($comment_anchors as $anchor) {
- $result_order[] = substr($anchor['id'], 8);
- }
-
- return $this->assertIdentical($expected_cids, $result_order, format_string('Comment order: expected @expected, returned @returned.', array('@expected' => implode(',', $expected_cids), '@returned' => implode(',', $result_order))));
- }
-
-
- * Tests comment_new_page_count().
- */
- function testCommentNewPageIndicator() {
- $this->backdropLogin($this->admin_user);
-
-
- $this->setCommentForm(TRUE);
- $this->setCommentSubject(TRUE);
- $this->setCommentPreview(BACKDROP_DISABLED);
-
-
-
- $this->setCommentsPerPage(1);
-
-
- $node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1));
- $comments = array();
- $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
- $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
- $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
-
-
- $this->backdropGet('comment/reply/' . $node->nid . '/' . $comments[1]->id);
- $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
-
-
- $this->backdropGet('comment/reply/' . $node->nid . '/' . $comments[0]->id);
- $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
-
-
- $this->backdropGet('comment/reply/' . $node->nid . '/' . $comments[2]->id);
- $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
-
-
-
-
-
-
-
-
-
- $this->setCommentSettings('comment_mode', COMMENT_MODE_FLAT, 'Comment paging changed.');
-
- $expected_pages = array(
- 1 => 5,
- 2 => 4,
- 3 => 3,
- 4 => 2,
- 5 => 1,
- 6 => 0,
- );
-
- $node = node_load($node->nid);
- foreach ($expected_pages as $new_replies => $expected_page) {
- $returned = comment_new_page_count($node->comment_count, $new_replies, $node);
- $returned_page = is_array($returned) ? $returned['page'] : 0;
- $this->assertIdentical($expected_page, $returned_page, format_string('Flat mode, @new replies: expected page @expected, returned page @returned.', array('@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page)));
- }
-
- $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.');
-
- $expected_pages = array(
- 1 => 5,
- 2 => 1,
- 3 => 1,
- 4 => 1,
- 5 => 1,
- 6 => 0,
- );
-
- $node = node_load($node->nid);
- foreach ($expected_pages as $new_replies => $expected_page) {
- $returned = comment_new_page_count($node->comment_count, $new_replies, $node);
- $returned_page = is_array($returned) ? $returned['page'] : 0;
- $this->assertEqual($expected_page, $returned_page, format_string('Threaded mode, @new replies: expected page @expected, returned page @returned.', array('@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page)));
- }
- }
- }
-
- * Tests comments with node access.
- */
- class CommentNodeAccessTest extends CommentHelperCase {
- function setUp($modules = array()) {
- parent::setUp('search', 'node_access_test');
-
- $web_user_role = $this->web_user->roles[count($this->web_user->roles) - 1];
- user_role_grant_permissions($web_user_role, array('node test view'));
- }
-
-
- * Test that threaded comments can be viewed.
- */
- function testThreadedCommentView() {
- $langcode = LANGUAGE_NONE;
-
- $this->backdropLogin($this->admin_user);
- $this->setCommentPreview(BACKDROP_DISABLED);
- $this->setCommentForm(TRUE);
- $this->setCommentSubject(TRUE);
- $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
- $this->backdropLogout();
-
-
- $this->backdropLogin($this->web_user);
- $comment_text = $this->randomName();
- $comment_subject = $this->randomName();
- $comment = $this->postComment($this->node, $comment_text, $comment_subject);
- $comment_loaded = comment_load($comment->id);
- $this->assertTrue($this->commentExists($comment), 'Comment found.');
-
-
- $this->backdropGet('node/' . $this->node->nid . '/' . $comment->id);
- $this->assertText($comment_subject, 'Individual comment subject found.');
- $this->assertText($comment_text, 'Individual comment body found.');
-
-
- $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
- $reply_text = $this->randomName();
- $reply_subject = $this->randomName();
- $reply = $this->postComment(NULL, $reply_text, $reply_subject, TRUE);
- $reply_loaded = comment_load($reply->id);
- $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
-
-
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertText($comment_text);
- $this->assertText($comment_subject);
- $this->assertText($reply_text);
- $this->assertText($reply_subject);
- }
- }
- * Tests comment approval functionality.
- */
- class CommentApprovalTest extends CommentHelperCase {
-
- * Test comment approval functionality through admin/content/comment.
- */
- function testApprovalAdminInterface() {
-
- user_role_change_permissions(BACKDROP_ANONYMOUS_ROLE, array(
- 'access comments' => TRUE,
- 'post comments' => TRUE,
- 'skip comment approval' => FALSE,
- ));
- $this->backdropLogin($this->admin_user);
- $this->setCommentAnonymous('0');
-
-
- $this->backdropGet('admin/content/comment');
- $this->assertText(t('No comments available.'));
-
- $this->backdropLogout();
- $this->setCommentSubject(TRUE);
-
-
- $subject = $this->randomName();
- $body = $this->randomName();
- $this->postComment($this->node, $body, $subject, TRUE);
- $this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), 'Comment requires approval.');
-
-
- $this->backdropLogin($this->admin_user);
- $anonymous_comment4 = $this->getUnapprovedComment($subject);
- $anonymous_comment4 = entity_create('comment', array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body));
- $this->backdropLogout();
-
- $this->assertFalse($this->commentExists($anonymous_comment4), 'Anonymous comment was not published.');
-
-
- $this->backdropLogin($this->admin_user);
- $this->performCommentOperation($anonymous_comment4, 'publish', TRUE);
- $this->backdropLogout();
-
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertTrue($this->commentExists($anonymous_comment4), 'Anonymous comment visible.');
-
-
- $comments[] = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
- $comments[] = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
-
-
- $this->backdropLogin($this->admin_user);
- $this->backdropGet('admin/content/comment/approval');
- $this->assertText(t('Unapproved comments (@count)', array('@count' => 2)), 'Two unapproved comments waiting for approval.');
- $edit = array(
- 'operation' => 'publish',
- "comments[{$comments[0]->id}]" => 1,
- "comments[{$comments[1]->id}]" => 1,
- );
- $this->backdropPost(NULL, $edit, t('Execute'));
- $this->assertText(t('Unapproved comments (@count)', array('@count' => 0)), 'All comments were approved.');
-
-
- $edit = array(
- 'operation' => 'delete',
- "comments[{$comments[0]->id}]" => 1,
- "comments[{$comments[1]->id}]" => 1,
- "comments[{$anonymous_comment4->id}]" => 1,
- );
- $this->backdropPost(NULL, $edit, t('Execute'));
- $this->assertText(t('Are you sure you want to delete these comments and all their children?'), 'Confirmation required.');
- $this->backdropPost(NULL, $edit, t('Delete comments'));
- $this->assertText(t('No comments available.'), 'All comments were deleted.');
- }
-
-
- * Tests comment approval functionality through the node interface.
- */
- function testApprovalNodeInterface() {
-
- user_role_change_permissions(BACKDROP_ANONYMOUS_ROLE, array(
- 'access comments' => TRUE,
- 'post comments' => TRUE,
- 'skip comment approval' => FALSE,
- ));
- $this->backdropLogin($this->admin_user);
- $this->setCommentAnonymous('0');
- $this->backdropLogout();
- $this->setCommentSubject(TRUE);
-
-
- $subject = $this->randomName();
- $body = $this->randomName();
- $this->postComment($this->node, $body, $subject, TRUE);
- $this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), 'Comment requires approval.');
-
-
- $this->backdropLogin($this->admin_user);
- $anonymous_comment4 = $this->getUnapprovedComment($subject);
- $anonymous_comment4 = entity_create('comment', array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body));
- $this->backdropLogout();
-
- $this->assertFalse($this->commentExists($anonymous_comment4), 'Anonymous comment was not published.');
-
-
- $this->backdropLogin($this->admin_user);
- $this->backdropGet('comment/1/approve');
- $this->assertResponse(403, 'Forged comment approval was denied.');
- $this->backdropGet('comment/1/approve', array('query' => array('token' => 'forged')));
- $this->assertResponse(403, 'Forged comment approval was denied.');
- $this->backdropGet('node/' . $this->node->nid);
- $this->clickLink(t('approve'));
- $this->backdropLogout();
-
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertTrue($this->commentExists($anonymous_comment4), 'Anonymous comment visible.');
- }
- }
-
- * Tests the Comment module blocks.
- */
- class CommentBlockFunctionalTest extends CommentHelperCase {
- function setUp($modules = array()) {
- parent::setUp(array('block'));
-
- $admin_user_role = $this->admin_user->roles[count($this->admin_user->roles) - 1];
- user_role_grant_permissions($admin_user_role, array('administer blocks'));
- }
-
-
- * Tests the recent comments block.
- */
- function testRecentCommentBlock() {
- $this->backdropLogin($this->admin_user);
- $this->setCommentSubject(TRUE);
-
-
- $layout_name = 'default';
- $region = 'sidebar';
- $block = array(
- 'module' => 'comment',
- 'delta' => 'recent',
- );
- $block_title = $this->randomName(16);
- $edit = array(
- 'region' => $region,
- 'title' => $block_title,
- 'title_display' => LAYOUT_TITLE_CUSTOM,
- 'block_settings[comment_count]' => 2,
- );
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/add-block/editor/' . $region . '/' . $block['module'] . ':' . $block['delta'], $edit, t('Add block'));
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name, array(), t('Save layout'));
-
-
- $comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
- $comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName());
- $comment3 = $this->postComment($this->node, $this->randomName());
-
-
-
- $this->backdropLogout();
- user_role_revoke_permissions(BACKDROP_ANONYMOUS_ROLE, array('access comments'));
-
- cache_clear_all();
- $this->backdropGet('');
- $this->assertNoText($block_title, 'Block was not found.');
- user_role_grant_permissions(BACKDROP_ANONYMOUS_ROLE, array('access comments'));
-
-
-
- $this->backdropLogin($this->web_user);
- $this->backdropGet('');
- $this->assertText($block_title, 'Block was found.');
-
-
- $this->assertNoText($comment1->subject, 'Comment not found in block.');
- $this->assertText($comment2->subject, 'Comment found in block.');
- $this->assertText($comment3->comment, 'Comment found in block.');
- $this->assertTrue(strpos($this->backdropGetContent(), $comment3->comment) < strpos($this->backdropGetContent(), $comment2->subject), 'Comments were ordered correctly in block.');
-
-
- $this->backdropLogout();
- $this->backdropLogin($this->admin_user);
- $edit = array(
- 'block_settings[comment_count]' => 10,
- );
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/add-block/editor/' . $region . '/' . $block['module'] . ':' . $block['delta'], $edit, t('Add block'));
- $this->backdropPost('admin/structure/layouts/manage/' . $layout_name, array(), t('Save layout'));
-
-
- $comment4 = $this->postComment($this->node, $this->randomName(), $this->randomName());
-
-
- $this->assertText($comment1->subject, 'Comment found in block.');
- $this->assertText($comment2->subject, 'Comment found in block.');
- $this->assertText($comment3->comment, 'Comment found in block.');
- $this->assertText($comment4->subject, 'Comment found in block.');
-
-
- $this->setCommentsPerPage(1);
- $this->backdropGet('');
- $this->clickLink($comment1->subject);
- $this->assertText($comment1->subject, 'Comment link goes to correct page.');
- $this->backdropGet('');
- $this->clickLink($comment2->subject);
- $this->assertText($comment2->subject, 'Comment link goes to correct page.');
- $this->clickLink($comment4->subject);
- $this->assertText($comment4->subject, 'Comment link goes to correct page.');
-
-
- $this->assertRaw('<link rel="canonical"', 'Canonical URL was found in the HTML head');
- }
- }
-
- * Unit tests for Comment module integration with RSS feeds.
- */
- class CommentRSSUnitTest extends CommentHelperCase {
-
- * Tests comments as part of an RSS feed.
- */
- function testCommentRSS() {
-
- $this->backdropLogin($this->web_user);
- $comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
- $this->backdropGet('rss.xml');
- $raw = '<comments>' . url('node/' . $this->node->nid, array('fragment' => 'comments', 'absolute' => TRUE)) . '</comments>';
- $this->assertRaw($raw, 'Comments as part of RSS feed.');
-
-
- $this->node->comment = COMMENT_NODE_HIDDEN;
- node_save($this->node);
- $this->backdropGet('rss.xml');
- $this->assertNoRaw($raw, 'Hidden comments is not a part of RSS feed.');
- }
- }
-
-
- * Tests comment content rebuilding.
- */
- class CommentContentRebuild extends CommentHelperCase {
-
- * Tests the rebuilding of comment's content arrays on calling comment_view().
- */
- function testCommentRebuild() {
-
- $this->backdropLogin($this->admin_user);
- $this->setCommentSubject(TRUE);
- $this->setCommentPreview(BACKDROP_OPTIONAL);
- $this->backdropLogout();
-
-
- $this->backdropLogin($this->web_user);
- $subject_text = $this->randomName();
- $comment_text = $this->randomName();
- $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
- $comment_loaded = comment_load($comment->id);
- $this->assertTrue($this->commentExists($comment), 'Comment found.');
-
-
- $comment_loaded->content['test_property'] = array('#value' => $this->randomString());
- $built_content = comment_view($comment_loaded, $this->node);
-
-
- $this->assertFalse(isset($built_content['test_property']), 'Comment content was emptied before being built.');
- }
- }
-
- * Tests comment token replacement in strings.
- */
- class CommentTokenReplaceTestCase extends CommentHelperCase {
-
- * Creates a comment, then tests the tokens generated from it.
- */
- function testCommentTokenReplacement() {
- global $language;
- $url_options = array(
- 'absolute' => TRUE,
- 'language' => $language,
- );
-
- $this->backdropLogin($this->admin_user);
-
-
- $this->setCommentSubject(TRUE);
-
-
- $node = $this->backdropCreateNode(array('type' => 'post'));
- $parent_comment = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
-
-
- $this->backdropGet('comment/reply/' . $node->nid . '/' . $parent_comment->id);
- $child_comment = $this->postComment(NULL, $this->randomName(), $this->randomName());
- $comment = comment_load($child_comment->id);
- $comment->homepage = 'http://example.org/';
-
-
- $comment->subject = '<blink>Blinking Comment</blink>';
- $instance = field_info_instance('comment', 'body', 'comment_body');
-
-
- $tests = array();
- $tests['[comment:cid]'] = $comment->cid;
- $tests['[comment:hostname]'] = check_plain($comment->hostname);
- $tests['[comment:name]'] = filter_xss($comment->name);
- $tests['[comment:mail]'] = check_plain($this->admin_user->mail);
- $tests['[comment:homepage]'] = check_url($comment->homepage);
- $tests['[comment:title]'] = filter_xss($comment->subject);
- $tests['[comment:body]'] = _text_sanitize($instance, LANGUAGE_NONE, $comment->comment_body[LANGUAGE_NONE][0], 'value');
- $tests['[comment:url]'] = url('comment/' . $comment->cid, $url_options + array('fragment' => 'comment-' . $comment->cid));
- $tests['[comment:edit-url]'] = url('comment/' . $comment->cid . '/edit', $url_options);
- $tests['[comment:created:since]'] = format_interval(REQUEST_TIME - $comment->created, 2, $language->langcode);
- $tests['[comment:changed:since]'] = format_interval(REQUEST_TIME - $comment->changed, 2, $language->langcode);
- $tests['[comment:parent:cid]'] = $comment->pid;
- $tests['[comment:parent:title]'] = check_plain($parent_comment->subject);
- $tests['[comment:node:nid]'] = $comment->nid;
- $tests['[comment:node:title]'] = check_plain($node->title);
- $tests['[comment:author]'] = check_plain(user_format_name($this->admin_user));
- $tests['[comment:author:uid]'] = $comment->uid;
- $tests['[comment:author:name]'] = check_plain(user_format_name($this->admin_user));
-
-
- $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
-
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('comment' => $comment), array('language' => $language));
- $this->assertEqual($output, $expected, format_string('Sanitized comment token %token replaced.', array('%token' => $input)));
- }
-
-
- $tests['[comment:hostname]'] = $comment->hostname;
- $tests['[comment:name]'] = $comment->name;
- $tests['[comment:mail]'] = $this->admin_user->mail;
- $tests['[comment:homepage]'] = $comment->homepage;
- $tests['[comment:title]'] = $comment->subject;
- $tests['[comment:body]'] = $comment->comment_body[LANGUAGE_NONE][0]['value'];
- $tests['[comment:parent:title]'] = $parent_comment->subject;
- $tests['[comment:node:title]'] = $node->title;
- $tests['[comment:author]'] = user_format_name($this->admin_user);
- $tests['[comment:author:name]'] = user_format_name($this->admin_user);
-
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('comment' => $comment), array('language' => $language, 'sanitize' => FALSE));
- $this->assertEqual($output, $expected, format_string('Unsanitized comment token %token replaced.', array('%token' => $input)));
- }
-
-
- $node = node_load($node->nid);
-
-
- $tests = array();
- $tests['[node:comment-count]'] = 2;
- $tests['[node:comment-count-new]'] = 2;
-
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('node' => $node), array('language' => $language));
- $this->assertEqual($output, $expected, format_string('Node comment token %token replaced.', array('%token' => $input)));
- }
- }
- }
-
- * Tests actions provided by the Comment module.
- */
- class CommentActionsTestCase extends CommentHelperCase {
-
- * Tests comment publish and unpublish actions.
- */
- function testCommentPublishUnpublishActions() {
- $this->backdropLogin($this->web_user);
- $comment_text = $this->randomName();
- $subject = $this->randomName();
- $comment = $this->postComment($this->node, $comment_text, '');
- $comment = comment_load($comment->id);
-
- comment_unpublish_action($comment);
- $this->assertEqual(comment_load($comment->cid)->status, COMMENT_NOT_PUBLISHED, 'Comment was unpublished');
-
- comment_publish_action($comment);
- $this->assertEqual(comment_load($comment->cid)->status, COMMENT_PUBLISHED, 'Comment was published');
- }
- }
-
- * Tests fields on comments.
- */
- class CommentFieldsTest extends CommentHelperCase {
- function setUp($modules = array()) {
- parent::setUp(array('field_ui'));
- }
-
-
- * Tests trying to save a comment with an empty, NON-required body.
- *
- * Trying to save should succeed and not generate a warning.
- */
- public function testCommentEmptyNonRequiredBody() {
-
- $this->backdropLogin($this->admin_user);
- $edit = array('instance[required]' => FALSE);
- $this->backdropPost('admin/structure/types/manage/post/comment/fields/comment_body', $edit, t('Save settings'));
-
-
- $this->backdropPost('node/' . $this->node->nid, array(), t('Preview'));
- $this->assertNoText('Comment field is required.', 'Can preview comment with empty required body.');
-
-
- $this->backdropPost('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.');
- }
-
-
- * Tests that the comment_body field is not required.
- *
- * It should be possible to preview and save a comment without the
- * default "comment_body" field and without generating warnings.
- */
- public function testCommentDeletedBody() {
-
- $this->backdropLogin($this->admin_user);
- $this->backdropPost('admin/structure/types/manage/post/comment/fields/comment_body/delete', array(), t('Delete'));
-
-
- $this->backdropPost('node/' . $this->node->nid, array(), t('Preview'));
-
-
- $this->backdropPost('node/' . $this->node->nid, array(), t('Save'));
-
-
- $this->backdropGet('admin/content/comment');
- }
-
-
- * Tests that the default 'comment_body' field is correctly added.
- */
- function testCommentDefaultFields() {
-
-
- $this->backdropCreateContentType(array('type' => 'test_node_type'));
-
-
- $instances = field_info_instances('comment');
- foreach (node_type_get_types() as $type_name => $info) {
- $this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
-
-
- field_delete_instance($instances['comment_node_' . $type_name]['comment_body']);
- }
-
-
- $field = field_info_field('comment_body');
- $this->assertTrue(empty($field), 'The comment_body field was deleted');
-
-
- $type_name = 'test_node_type_2';
- $this->backdropCreateContentType(array('type' => $type_name));
-
-
-
- $field = field_info_field('comment_body');
- $this->assertTrue($field, 'The comment_body field exists');
- $instances = field_info_instances('comment');
- $this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
- }
-
-
- * Tests that comment module works when enabled after a content module.
- */
- function testCommentEnable() {
-
- $this->admin_user = $this->backdropCreateUser(array('access administration pages', 'administer modules'));
- $this->backdropLogin($this->admin_user);
-
-
- $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.');
-
-
- $edit = array();
- $edit['modules[System][book][enable]'] = 'book';
- $this->backdropPost('admin/modules', $edit, t('Save configuration'));
- $this->resetAll();
-
-
- $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.');
-
-
- $book_node = $this->backdropCreateNode(array('type' => 'book'));
-
- $this->backdropLogout();
-
-
-
-
- $this->web_user = $this->backdropCreateUser(array('access content', 'access comments', 'post comments', 'skip comment approval'));
- $this->backdropLogin($this->web_user);
- $this->postComment($book_node, $this->randomName(), '');
- }
-
-
- * Tests that comment module works correctly with plain text format.
- */
- function testCommentFormat() {
-
- $this->backdropLogin($this->admin_user);
- $edit = array('instance[settings][text_processing]' => 0);
- $this->backdropPost('admin/structure/types/manage/post/comment/fields/comment_body', $edit, t('Save settings'));
-
-
- $this->backdropLogin($this->web_user);
- $edit = array('comment_body[und][0][value]' => $this->randomName(8));
- $this->backdropPost('node/' . $this->node->nid, $edit, t('Save'));
- }
- }
-
- * Tests comment threading.
- */
- class CommentThreadingTestCase extends CommentHelperCase {
-
-
- * Tests the comment threading.
- */
- function testCommentThreading() {
- $langcode = LANGUAGE_NONE;
-
- $this->backdropLogin($this->admin_user);
- $this->setCommentPreview(BACKDROP_DISABLED);
- $this->setCommentForm(TRUE);
- $this->setCommentSubject(TRUE);
- $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
- $this->backdropLogout();
-
-
- $this->backdropLogin($this->web_user);
- $this->node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1, 'uid' => $this->web_user->uid));
-
-
- $this->backdropLogin($this->web_user);
- $subject_text = $this->randomName();
- $comment_text = $this->randomName();
- $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
- $comment_loaded = comment_load($comment->id);
- $this->assertTrue($this->commentExists($comment), 'Comment #1. Comment found.');
- $this->assertEqual($comment_loaded->thread, '01/');
-
-
- $this->backdropLogin($this->web_user);
- $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
- $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
- $reply_loaded = comment_load($reply->id);
- $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #2. Reply found.');
- $this->assertEqual($reply_loaded->thread, '01.00/');
-
-
- $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $reply->id);
- $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
- $reply_loaded = comment_load($reply->id);
- $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #3. Second reply found.');
- $this->assertEqual($reply_loaded->thread, '01.00.00/');
-
-
- $this->backdropLogin($this->web_user);
- $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
- $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
- $reply_loaded = comment_load($reply->id);
- $this->assertTrue($this->commentExists($comment), 'Comment #4. Third reply found.');
- $this->assertEqual($reply_loaded->thread, '01.01/');
-
-
- $this->backdropLogin($this->web_user);
- $subject_text = $this->randomName();
- $comment_text = $this->randomName();
- $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
- $comment_loaded = comment_load($comment->id);
- $this->assertTrue($this->commentExists($comment), 'Comment #5. Second comment found.');
- $this->assertEqual($comment_loaded->thread, '02/');
-
-
- $this->backdropLogin($this->web_user);
- $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
- $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
- $reply_loaded = comment_load($reply->id);
- $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #6. Reply found.');
- $this->assertEqual($reply_loaded->thread, '02.00/');
-
-
- $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $reply->id);
- $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
- $reply_loaded = comment_load($reply->id);
- $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #7. Second reply found.');
- $this->assertEqual($reply_loaded->thread, '02.00.00/');
-
-
- $this->backdropLogin($this->web_user);
- $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
- $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
- $reply_loaded = comment_load($reply->id);
- $this->assertTrue($this->commentExists($comment), 'Comment #8. Third reply found.');
- $this->assertEqual($reply_loaded->thread, '02.01/');
- }
- }
-
- * Tests that comments behave correctly when the node is changed.
- */
- class CommentNodeChangesTestCase extends CommentHelperCase {
-
- * Tests that comments are deleted with the node.
- */
- function testNodeDeletion() {
- $this->backdropLogin($this->web_user);
- $comment = $this->postComment($this->node, $this->randomName(), '');
- $this->assertTrue(comment_load($comment->id), 'The comment could be loaded.');
- node_delete($this->node->nid);
- $this->assertFalse(comment_load($comment->id), 'The comment could not be loaded after the node was deleted.');
- }
-
-
- * Tests opening, closing, and hiding comments.
- */
- function testNodeCommentSettings() {
- $this->backdropLogin($this->admin_user);
-
-
-
- $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.');
-
-
- $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.');
-
-
- $this->backdropGet('node/' . $this->node->nid . '/edit');
- $this->assertField('edit-comment-hidden', 'Comments hidden field shown after comments have been added.');
-
-
- $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.');
-
-
- $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.');
-
- }
- }
-
- * Tests that comments behave correctly when the auto closer is enabled.
- */
- class CommentNodeAutoCloserTestCase extends CommentHelperCase {
-
- * Tests the auto closer node type setting and the override setting on individual nodes.
- */
- function testNodeCommentAutoCloserSettings() {
- $this->backdropLogin($this->admin_user);
-
- $this->backdropGet('node/' . $this->node->nid . '/edit');
- $this->assertNoField('edit-comment-close-override', 'Comment auto closer override hidden when auto closer not enabled.');
-
- $this->setCommentSettings('comment_close_enabled', TRUE, 'Comment auto closer enabled.');
-
- $this->backdropGet('node/' . $this->node->nid . '/edit');
- $this->assertField('edit-comment-close-enabled', 'Comment auto closer override visible when auto closer enabled.');
-
-
- $this->cronRun();
-
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertEqual(count($this->xpath('//form[@id="comment-form"]')), 1, 'Comment form visible on node page when created date is younger than comment auto closer default time span.');
-
-
- $comment_close_days = config_get('node.type.post','settings.comment_close_days');
- $this->node->created = time() - strtotime($comment_close_days + 1 . ' days');
- $this->node->save();
-
-
- $this->cronRun();
-
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertEqual(count($this->xpath('//form[@id="comment-form"]')), 0, 'Comment form not on node page when created date is older than the comment auto closer default time span.');
-
-
- $edit = array(
- 'comment' => COMMENT_NODE_OPEN,
- 'comment_close_enabled' => FALSE,
- );
- $this->backdropPost('node/' . $this->node->nid . '/edit', $edit, t('Save'));
-
-
- $this->backdropGet('node/' . $this->node->nid . '/edit');
- $this->assertNoFieldChecked('edit-comment-close-enabled', 'Comment close option still unchecked after saving.');
-
-
- $this->cronRun();
-
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertEqual(count($this->xpath('//form[@id="comment-form"]')), 1, 'Comment form visible on node page when comments auto closer is overridden for individual node.');
- }
- }
-
- * Tests the behavior of comments when the comment author is deleted.
- */
- class CommentAuthorDeletionTestCase extends CommentHelperCase {
-
-
- * Tests that comments are correctly deleted when their author is deleted.
- */
- public function testAuthorDeletion() {
-
- $this->backdropLogin($this->admin_user);
- $comment = $this->postComment($this->node, $this->randomName());
- $this->assertTrue($this->commentExists($comment), t('Comment is displayed initially.'));
- $this->backdropLogout();
-
-
-
-
- user_delete($this->admin_user->uid);
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertResponse(200, t('Node page is accessible after the comment author is deleted.'));
- $this->assertFalse($this->commentExists($comment), t('Comment is not displayed after the comment author is deleted.'));
- }
-
-
- * Test comment author deletion while the comment module is disabled.
- */
- public function testAuthorDeletionCommentModuleDisabled() {
-
- $this->backdropLogin($this->admin_user);
- $comment = $this->postComment($this->node, $this->randomName());
- $this->assertTrue($this->commentExists($comment), t('Comment is displayed initially.'));
- $this->backdropLogout();
-
-
-
-
-
- module_disable(array('comment'));
- user_delete($this->admin_user->uid);
- cache('entity_comment')->flush();
- module_enable(array('comment'));
- $this->backdropGet('node/' . $this->node->nid);
- $this->assertResponse(200, t('Node page is accessible after the comment author is deleted.'));
- $this->assertFalse($this->commentExists($comment), t('Comment is not displayed after the comment author is deleted.'));
- }
-
- }