Version 1
[yaffs-website] / web / core / modules / forum / tests / src / Functional / ForumIndexTest.php
1 <?php
2
3 namespace Drupal\Tests\forum\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests the forum index listing.
9  *
10  * @group forum
11  */
12 class ForumIndexTest extends BrowserTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['taxonomy', 'comment', 'forum'];
20
21   protected function setUp() {
22     parent::setUp();
23
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);
27   }
28
29   /**
30    * Tests the forum index for published and unpublished nodes.
31    */
32   public function testForumIndexStatus() {
33     // The forum ID to use.
34     $tid = 1;
35
36     // Create a test node.
37     $title = $this->randomMachineName(20);
38     $edit = [
39       'title[0][value]' => $title,
40       'body[0][value]' => $this->randomMachineName(200),
41     ];
42
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'));
48
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.');
52
53     // Create a child forum.
54     $edit = [
55       'name[0][value]' => $this->randomMachineName(20),
56       'description[0][value]' => $this->randomMachineName(200),
57       'parent[0]' => $tid,
58     ];
59     $this->drupalPostForm('admin/structure/forum/add/forum', $edit, t('Save'));
60     $tid_child = $tid + 1;
61
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);
71
72
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.');
77
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.');
81   }
82
83 }