442a0e762b4a748c82b2f933176f217ca4a3651a
[yaffs-website] / web / core / modules / comment / src / Tests / Views / FilterUserUIDTest.php
1 <?php
2
3 namespace Drupal\comment\Tests\Views;
4
5 use Drupal\comment\Entity\Comment;
6 use Drupal\user\Entity\User;
7 use Drupal\views\Views;
8
9 /**
10  * Tests the user posted or commented filter handler.
11  *
12  * The actual stuff is done in the parent class.
13  *
14  * @group comment
15  */
16 class FilterUserUIDTest extends CommentTestBase {
17
18   /**
19    * Views used by this test.
20    *
21    * @var array
22    */
23   public static $testViews = ['test_comment_user_uid'];
24
25   public function testCommentUserUIDTest() {
26     $view = Views::getView('test_comment_user_uid');
27     $view->setDisplay();
28     $view->removeHandler('default', 'argument', 'uid_touch');
29
30     // Add an additional comment which is not created by the user.
31     $new_user = User::create(['name' => 'new user']);
32     $new_user->save();
33
34     $comment = Comment::create([
35       'uid' => $new_user->uid->value,
36       'entity_id' => $this->nodeUserCommented->id(),
37       'entity_type' => 'node',
38       'field_name' => 'comment',
39       'subject' => 'if a woodchuck could chuck wood.',
40     ]);
41     $comment->save();
42
43     $options = [
44       'id' => 'uid_touch',
45       'table' => 'node_field_data',
46       'field' => 'uid_touch',
47       'value' => [$this->loggedInUser->id()],
48     ];
49     $view->addHandler('default', 'filter', 'node_field_data', 'uid_touch', $options);
50     $this->executeView($view, [$this->account->id()]);
51     $result_set = [
52       [
53         'nid' => $this->nodeUserPosted->id(),
54       ],
55       [
56         'nid' => $this->nodeUserCommented->id(),
57       ],
58     ];
59     $column_map = ['nid' => 'nid'];
60     $this->assertIdenticalResultset($view, $result_set, $column_map);
61   }
62
63 }