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