diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_user_uid.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_user_uid.yml index 030b4a745133..f3ea880d0666 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_user_uid.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_user_uid.yml @@ -45,6 +45,13 @@ display: plugin_id: node entity_type: node entity_field: nid + title: + field: title + id: title + table: node_field_data + plugin_id: field + entity_type: node + entity_field: title pager: type: full query: diff --git a/core/modules/comment/tests/src/Functional/Views/ArgumentUserUIDTest.php b/core/modules/comment/tests/src/Functional/Views/ArgumentUserUIDTest.php deleted file mode 100644 index ad08f4fa912d..000000000000 --- a/core/modules/comment/tests/src/Functional/Views/ArgumentUserUIDTest.php +++ /dev/null @@ -1,51 +0,0 @@ - 'new user']); - $new_user->save(); - - $comment = Comment::create([ - 'uid' => $new_user->uid->value, - 'entity_id' => $this->nodeUserCommented->id(), - 'entity_type' => 'node', - 'field_name' => 'comment', - 'subject' => 'if a woodchuck could chuck wood.', - ]); - $comment->save(); - - $view = Views::getView('test_comment_user_uid'); - $this->executeView($view, [$this->account->id()]); - $result_set = [ - [ - 'nid' => $this->nodeUserPosted->id(), - ], - [ - 'nid' => $this->nodeUserCommented->id(), - ], - ]; - $column_map = ['nid' => 'nid']; - $this->assertIdenticalResultset($view, $result_set, $column_map); - } - -} diff --git a/core/modules/comment/tests/src/Functional/Views/FilterUserUIDTest.php b/core/modules/comment/tests/src/Functional/Views/FilterUserUIDTest.php deleted file mode 100644 index 719c5978a5ed..000000000000 --- a/core/modules/comment/tests/src/Functional/Views/FilterUserUIDTest.php +++ /dev/null @@ -1,63 +0,0 @@ -setDisplay(); - $view->removeHandler('default', 'argument', 'uid_touch'); - - // Add an additional comment which is not created by the user. - $new_user = User::create(['name' => 'new user']); - $new_user->save(); - - $comment = Comment::create([ - 'uid' => $new_user->uid->value, - 'entity_id' => $this->nodeUserCommented->id(), - 'entity_type' => 'node', - 'field_name' => 'comment', - 'subject' => 'if a woodchuck could chuck wood.', - ]); - $comment->save(); - - $options = [ - 'id' => 'uid_touch', - 'table' => 'node_field_data', - 'field' => 'uid_touch', - 'value' => [$this->loggedInUser->id()], - ]; - $view->addHandler('default', 'filter', 'node_field_data', 'uid_touch', $options); - $this->executeView($view, [$this->account->id()]); - $result_set = [ - [ - 'nid' => $this->nodeUserPosted->id(), - ], - [ - 'nid' => $this->nodeUserCommented->id(), - ], - ]; - $column_map = ['nid' => 'nid']; - $this->assertIdenticalResultset($view, $result_set, $column_map); - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Views/FilterAndArgumentUserUidTest.php b/core/modules/comment/tests/src/Kernel/Views/FilterAndArgumentUserUidTest.php new file mode 100644 index 000000000000..7dfc6896ff21 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Views/FilterAndArgumentUserUidTest.php @@ -0,0 +1,138 @@ +installEntitySchema('user'); + $this->installSchema('system', ['sequences']); + $this->installEntitySchema('node'); + $this->installEntitySchema('comment'); + $this->installSchema('comment', ['comment_entity_statistics']); + $this->installConfig(['filter']); + + NodeType::create(['type' => 'page'])->save(); + + FieldStorageConfig::create([ + 'type' => 'text_long', + 'entity_type' => 'comment', + 'field_name' => 'comment_body', + ])->save(); + $this->addDefaultCommentField('node', 'page', 'comment'); + + $account = $this->createUser(); + $other_account = $this->createUser(); + + $node_authored_by_account = $this->createNode([ + 'uid' => $account->id(), + 'title' => "authored by {$account->id()}", + ]); + $node_commented_by_account = $this->createNode([ + 'title' => "commented by {$account->id()}", + ]); + $arbitrary_node = $this->createNode(); + + // Comment added by $account. + Comment::create([ + 'uid' => $account->id(), + 'entity_id' => $node_commented_by_account->id(), + 'entity_type' => 'node', + 'field_name' => 'comment', + ])->save(); + // Comment added by $other_account on $node_commented_by_account + Comment::create([ + 'uid' => $other_account->id(), + 'entity_id' => $node_commented_by_account->id(), + 'entity_type' => 'node', + 'field_name' => 'comment', + ])->save(); + // Comment added by $other_account on an arbitrary node. + Comment::create([ + 'uid' => $other_account->id(), + 'entity_id' => $arbitrary_node->id(), + 'entity_type' => 'node', + 'field_name' => 'comment', + ])->save(); + + ViewTestData::createTestViews(static::class, ['comment_test_views']); + + $expected_result = [ + [ + 'nid' => $node_authored_by_account->id(), + 'title' => "authored by {$account->id()}", + ], + [ + 'nid' => $node_commented_by_account->id(), + 'title' => "commented by {$account->id()}", + ], + ]; + $column_map = ['nid' => 'nid', 'title' => 'title']; + $view = Views::getView('test_comment_user_uid'); + + // Test the argument handler. + $view->preview(NULL, [$account->id()]); + $this->assertIdenticalResultset($view, $expected_result, $column_map); + + // Test the filter handler. Reuse the same view but replace the argument + // handler with a filter handler. + $view->removeHandler('default', 'argument', 'uid_touch'); + $options = [ + 'id' => 'uid_touch', + 'table' => 'node_field_data', + 'field' => 'uid_touch', + 'value' => [$account->id()], + ]; + $view->addHandler('default', 'filter', 'node_field_data', 'uid_touch', $options); + + $view->preview(); + $this->assertIdenticalResultset($view, $expected_result, $column_map); + } + +}