CommentTestBase.php 2.36 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\comment\Tests\Views\CommentTestBase.
merlinofchaos's avatar
merlinofchaos committed
6 7
 */

8
namespace Drupal\comment\Tests\Views;
9

10
use Drupal\comment\Tests\CommentTestTrait;
11
use Drupal\views\Tests\ViewTestBase;
12
use Drupal\views\Tests\ViewTestData;
13
use Drupal\comment\Entity\Comment;
14

merlinofchaos's avatar
merlinofchaos committed
15 16 17
/**
 * Tests the argument_comment_user_uid handler.
 */
18
abstract class CommentTestBase extends ViewTestBase {
19

20 21
  use CommentTestTrait;

22
  /**
23
   * Modules to install.
24 25 26
   *
   * @var array
   */
27
  public static $modules = array('node', 'comment', 'comment_test_views');
merlinofchaos's avatar
merlinofchaos committed
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  /**
   * A normal user with permission to post comments (without approval).
   *
   * @var \Drupal\user\UserInterface
   */
  protected $account;

  /**
   * A second normal user that will author a node for $account to comment on.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $account2;

  /**
   * Stores a node posted by the user created as $account.
   *
   * @var \Drupal\node\NodeInterface
   */
  protected $nodeUserPosted;

  /**
   * Stores a node posted by the user created as $account2.
   *
   * @var \Drupal\node\NodeInterface
   */
  protected $nodeUserCommented;

57 58 59
  /**
   * Stores a comment used by the tests.
   *
60
   * @var \Drupal\comment\Entity\Comment
61
   */
62
  protected $comment;
63

64
  protected function setUp() {
merlinofchaos's avatar
merlinofchaos committed
65 66
    parent::setUp();

67
    ViewTestData::createTestViews(get_class($this), array('comment_test_views'));
68

69 70
    // Add two users, create a node with the user1 as author and another node
    // with user2 as author. For the second node add a comment from user1.
71
    $this->account = $this->drupalCreateUser(array('skip comment approval'));
merlinofchaos's avatar
merlinofchaos committed
72 73
    $this->account2 = $this->drupalCreateUser();
    $this->drupalLogin($this->account);
74

75
    $this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
76
    $this->addDefaultCommentField('node', 'page');
77

78 79
    $this->nodeUserPosted = $this->drupalCreateNode();
    $this->nodeUserCommented = $this->drupalCreateNode(array('uid' => $this->account2->id()));
merlinofchaos's avatar
merlinofchaos committed
80

81
    $comment = array(
82
      'uid' => $this->loggedInUser->id(),
83
      'entity_id' => $this->nodeUserCommented->id(),
84 85
      'entity_type' => 'node',
      'field_name' => 'comment',
86
      'subject' => 'How much wood would a woodchuck chuck',
87 88
      'cid' => '',
      'pid' => '',
89
      'mail' => 'someone@example.com',
merlinofchaos's avatar
merlinofchaos committed
90
    );
91
    $this->comment = Comment::create($comment);
92
    $this->comment->save();
merlinofchaos's avatar
merlinofchaos committed
93 94 95
  }

}