X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fforum%2Fsrc%2FTests%2FViews%2FForumIntegrationTest.php;fp=web%2Fcore%2Fmodules%2Fforum%2Fsrc%2FTests%2FViews%2FForumIntegrationTest.php;h=f5677e41b6a9314c17cab7ed095826889403ffd2;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/forum/src/Tests/Views/ForumIntegrationTest.php b/web/core/modules/forum/src/Tests/Views/ForumIntegrationTest.php new file mode 100644 index 000000000..f5677e41b --- /dev/null +++ b/web/core/modules/forum/src/Tests/Views/ForumIntegrationTest.php @@ -0,0 +1,95 @@ +container->get('entity.manager'); + $term = $entity_manager->getStorage('taxonomy_term')->create(['vid' => 'forums', 'name' => $this->randomMachineName()]); + $term->save(); + + $comment_storage = $entity_manager->getStorage('comment'); + + // Create some nodes which are part of this forum with some comments. + $nodes = []; + for ($i = 0; $i < 3; $i++) { + $node = $this->drupalCreateNode(['type' => 'forum', 'taxonomy_forums' => [$term->id()], 'sticky' => $i == 0 ? NodeInterface::STICKY : NodeInterface::NOT_STICKY]); + $nodes[] = $node; + } + + $account = $this->drupalCreateUser(['skip comment approval']); + $this->drupalLogin($account); + + $comments = []; + foreach ($nodes as $index => $node) { + for ($i = 0; $i <= $index; $i++) { + $comment = $comment_storage->create(['entity_type' => 'node', 'entity_id' => $node->id(), 'field_name' => 'comment_forum']); + $comment->save(); + $comments[$comment->get('entity_id')->target_id][$comment->id()] = $comment; + } + } + + $view = Views::getView('test_forum_index'); + $this->executeView($view); + + $expected_result = []; + $expected_result[] = [ + 'nid' => $nodes[0]->id(), + 'sticky' => NodeInterface::STICKY, + 'comment_count' => 1. + ]; + $expected_result[] = [ + 'nid' => $nodes[1]->id(), + 'sticky' => NodeInterface::NOT_STICKY, + 'comment_count' => 2. + ]; + $expected_result[] = [ + 'nid' => $nodes[2]->id(), + 'sticky' => NodeInterface::NOT_STICKY, + 'comment_count' => 3. + ]; + $column_map = [ + 'nid' => 'nid', + 'forum_index_sticky' => 'sticky', + 'forum_index_comment_count' => 'comment_count', + ]; + $this->assertIdenticalResultset($view, $expected_result, $column_map); + } + +}