3 namespace Drupal\Tests\forum\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests the forum index listing.
12 class ForumIndexTest extends BrowserTestBase {
19 public static $modules = ['taxonomy', 'comment', 'forum'];
21 protected function setUp() {
24 // Create a test user.
25 $web_user = $this->drupalCreateUser(['create forum content', 'edit own forum content', 'edit any forum content', 'administer nodes', 'administer forums']);
26 $this->drupalLogin($web_user);
30 * Tests the forum index for published and unpublished nodes.
32 public function testForumIndexStatus() {
33 // The forum ID to use.
36 // Create a test node.
37 $title = $this->randomMachineName(20);
39 'title[0][value]' => $title,
40 'body[0][value]' => $this->randomMachineName(200),
43 // Create the forum topic, preselecting the forum ID via a URL parameter.
44 $this->drupalGet("forum/$tid");
45 $this->clickLink(t('Add new @node_type', ['@node_type' => 'Forum topic']));
46 $this->assertUrl('node/add/forum', ['query' => ['forum_id' => $tid]]);
47 $this->drupalPostForm(NULL, $edit, t('Save and publish'));
49 // Check that the node exists in the database.
50 $node = $this->drupalGetNodeByTitle($title);
51 $this->assertTrue(!empty($node), 'New forum node found in database.');
53 // Create a child forum.
55 'name[0][value]' => $this->randomMachineName(20),
56 'description[0][value]' => $this->randomMachineName(200),
59 $this->drupalPostForm('admin/structure/forum/add/forum', $edit, t('Save'));
60 $tid_child = $tid + 1;
62 // Verify that the node appears on the index.
63 $this->drupalGet('forum/' . $tid);
64 $this->assertText($title, 'Published forum topic appears on index.');
65 $this->assertCacheTag('node_list');
66 $this->assertCacheTag('config:node.type.forum');
67 $this->assertCacheTag('comment_list');
68 $this->assertCacheTag('node:' . $node->id());
69 $this->assertCacheTag('taxonomy_term:' . $tid);
70 $this->assertCacheTag('taxonomy_term:' . $tid_child);
73 // Unpublish the node.
74 $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and unpublish'));
75 $this->drupalGet('node/' . $node->id());
76 $this->assertText(t('Access denied'), 'Unpublished node is no longer accessible.');
78 // Verify that the node no longer appears on the index.
79 $this->drupalGet('forum/' . $tid);
80 $this->assertNoText($title, 'Unpublished forum topic no longer appears on index.');