CommentNodeAccessTest.php 2.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?php

/**
 * @file
 * Definition of Drupal\comment\Tests\CommentNodeAccessTest.
 */

namespace Drupal\comment\Tests;

use Drupal\simpletest\WebTestBase;

/**
 * Tests comments with node access.
 *
 * See http://drupal.org/node/886752 -- verify there is no PostgreSQL error when
 * viewing a node with threaded comments (a comment and a reply), if a node
 * access module is in use.
 */
class CommentNodeAccessTest extends CommentTestBase {
20 21 22 23 24 25 26 27

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('node_access_test');

28 29 30 31 32 33 34 35 36
  public static function getInfo() {
    return array(
      'name' => 'Comment node access',
      'description' => 'Test comment viewing with node access.',
      'group' => 'Comment',
    );
  }

  function setUp() {
37 38
    parent::setUp();

39 40
    node_access_rebuild();

41
    // Re-create user.
42 43 44 45 46 47 48 49 50 51 52 53 54
    $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments', 'node test view'));
  }

  /**
   * Test that threaded comments can be viewed.
   */
  function testThreadedCommentView() {
    $langcode = LANGUAGE_NOT_SPECIFIED;
    // Set comments to have subject required and preview disabled.
    $this->drupalLogin($this->admin_user);
    $this->setCommentPreview(DRUPAL_DISABLED);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(TRUE);
55
    $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
56 57 58 59 60 61 62 63
    $this->drupalLogout();

    // Post comment.
    $this->drupalLogin($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);
64
    $this->assertTrue($this->commentExists($comment), 'Comment found.');
65 66 67

    // Check comment display.
    $this->drupalGet('node/' . $this->node->nid . '/' . $comment->id);
68 69
    $this->assertText($comment_subject, 'Individual comment subject found.');
    $this->assertText($comment_text, 'Individual comment body found.');
70 71 72 73 74 75 76

    // Reply to comment, creating second comment.
    $this->drupalGet('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);
77
    $this->assertTrue($this->commentExists($reply, TRUE), 'Reply found.');
78 79 80 81 82 83 84 85 86

    // Go to the node page and verify comment and reply are visible.
    $this->drupalGet('node/' . $this->node->nid);
    $this->assertText($comment_text);
    $this->assertText($comment_subject);
    $this->assertText($reply_text);
    $this->assertText($reply_subject);
  }
}