Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / comment / tests / src / Functional / Views / CommentTestBase.php
1 <?php
2
3 namespace Drupal\Tests\comment\Functional\Views;
4
5 use Drupal\comment\Tests\CommentTestTrait;
6 use Drupal\Tests\views\Functional\ViewTestBase;
7 use Drupal\views\Tests\ViewTestData;
8 use Drupal\comment\Entity\Comment;
9
10 /**
11  * Provides setup and helper methods for comment views tests.
12  */
13 abstract class CommentTestBase extends ViewTestBase {
14
15   use CommentTestTrait;
16
17   /**
18    * Modules to install.
19    *
20    * @var array
21    */
22   public static $modules = ['node', 'comment', 'comment_test_views'];
23
24   /**
25    * A normal user with permission to post comments (without approval).
26    *
27    * @var \Drupal\user\UserInterface
28    */
29   protected $account;
30
31   /**
32    * A second normal user that will author a node for $account to comment on.
33    *
34    * @var \Drupal\user\UserInterface
35    */
36   protected $account2;
37
38   /**
39    * Stores a node posted by the user created as $account.
40    *
41    * @var \Drupal\node\NodeInterface
42    */
43   protected $nodeUserPosted;
44
45   /**
46    * Stores a node posted by the user created as $account2.
47    *
48    * @var \Drupal\node\NodeInterface
49    */
50   protected $nodeUserCommented;
51
52   /**
53    * Stores a comment used by the tests.
54    *
55    * @var \Drupal\comment\Entity\Comment
56    */
57   protected $comment;
58
59   protected function setUp($import_test_views = TRUE) {
60     parent::setUp($import_test_views);
61
62     ViewTestData::createTestViews(get_class($this), ['comment_test_views']);
63
64     // Add two users, create a node with the user1 as author and another node
65     // with user2 as author. For the second node add a comment from user1.
66     $this->account = $this->drupalCreateUser(['skip comment approval']);
67     $this->account2 = $this->drupalCreateUser();
68     $this->drupalLogin($this->account);
69
70     $this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
71     $this->addDefaultCommentField('node', 'page');
72
73     $this->nodeUserPosted = $this->drupalCreateNode();
74     $this->nodeUserCommented = $this->drupalCreateNode(['uid' => $this->account2->id()]);
75
76     $comment = [
77       'uid' => $this->loggedInUser->id(),
78       'entity_id' => $this->nodeUserCommented->id(),
79       'entity_type' => 'node',
80       'field_name' => 'comment',
81       'subject' => 'How much wood would a woodchuck chuck',
82       'cid' => '',
83       'pid' => '',
84       'mail' => 'someone@example.com',
85     ];
86     $this->comment = Comment::create($comment);
87     $this->comment->save();
88   }
89
90 }