3 namespace Drupal\Tests\forum\Functional\Views;
5 use Drupal\node\NodeInterface;
6 use Drupal\views\Views;
7 use Drupal\Tests\views\Functional\ViewTestBase;
8 use Drupal\views\Tests\ViewTestData;
11 * Tests the forum integration into views.
15 class ForumIntegrationTest extends ViewTestBase {
22 public static $modules = ['forum_test_views'];
25 * Views used by this test.
29 public static $testViews = ['test_forum_index'];
31 protected function setUp($import_test_views = TRUE) {
32 parent::setUp($import_test_views);
34 ViewTestData::createTestViews(get_class($this), ['forum_test_views']);
39 * Tests the integration.
41 public function testForumIntegration() {
43 $entity_manager = $this->container->get('entity.manager');
44 $term = $entity_manager->getStorage('taxonomy_term')->create(['vid' => 'forums', 'name' => $this->randomMachineName()]);
47 $comment_storage = $entity_manager->getStorage('comment');
49 // Create some nodes which are part of this forum with some comments.
51 for ($i = 0; $i < 3; $i++) {
52 $node = $this->drupalCreateNode(['type' => 'forum', 'taxonomy_forums' => [$term->id()], 'sticky' => $i == 0 ? NodeInterface::STICKY : NodeInterface::NOT_STICKY]);
56 $account = $this->drupalCreateUser(['skip comment approval']);
57 $this->drupalLogin($account);
60 foreach ($nodes as $index => $node) {
61 for ($i = 0; $i <= $index; $i++) {
62 $comment = $comment_storage->create(['entity_type' => 'node', 'entity_id' => $node->id(), 'field_name' => 'comment_forum']);
64 $comments[$comment->get('entity_id')->target_id][$comment->id()] = $comment;
68 $view = Views::getView('test_forum_index');
69 $this->executeView($view);
71 $expected_result = [];
72 $expected_result[] = [
73 'nid' => $nodes[0]->id(),
74 'sticky' => NodeInterface::STICKY,
77 $expected_result[] = [
78 'nid' => $nodes[1]->id(),
79 'sticky' => NodeInterface::NOT_STICKY,
82 $expected_result[] = [
83 'nid' => $nodes[2]->id(),
84 'sticky' => NodeInterface::NOT_STICKY,
89 'forum_index_sticky' => 'sticky',
90 'forum_index_comment_count' => 'comment_count',
92 $this->assertIdenticalResultset($view, $expected_result, $column_map);