View source
<?php
namespace Drupal\Tests\forum\Functional;
use Drupal\Tests\BrowserTestBase;
class ForumIndexTest extends BrowserTestBase {
public static $modules = [
'taxonomy',
'comment',
'forum',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$web_user = $this
->drupalCreateUser([
'create forum content',
'edit own forum content',
'edit any forum content',
'administer nodes',
'administer forums',
]);
$this
->drupalLogin($web_user);
}
public function testForumIndexStatus() {
$tid = 1;
$title = $this
->randomMachineName(20);
$edit = [
'title[0][value]' => $title,
'body[0][value]' => $this
->randomMachineName(200),
];
$this
->drupalGet("forum/{$tid}");
$this
->clickLink(t('Add new @node_type', [
'@node_type' => 'Forum topic',
]));
$this
->assertUrl('node/add/forum', [
'query' => [
'forum_id' => $tid,
],
]);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($title);
$this
->assertTrue(!empty($node), 'New forum node found in database.');
$edit = [
'name[0][value]' => $this
->randomMachineName(20),
'description[0][value]' => $this
->randomMachineName(200),
'parent[0]' => $tid,
];
$this
->drupalPostForm('admin/structure/forum/add/forum', $edit, t('Save'));
$this
->assertSession()
->linkExists(t('edit forum'));
$tid_child = $tid + 1;
$this
->drupalGet('forum/' . $tid);
$this
->assertText($title, 'Published forum topic appears on index.');
$this
->assertCacheTag('node_list');
$this
->assertCacheTag('config:node.type.forum');
$this
->assertCacheTag('comment_list');
$this
->assertCacheTag('node:' . $node
->id());
$this
->assertCacheTag('taxonomy_term:' . $tid);
$this
->assertCacheTag('taxonomy_term:' . $tid_child);
$edit = [
'status[value]' => FALSE,
];
$this
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, t('Save'));
$this
->drupalGet('node/' . $node
->id());
$this
->assertText(t('Access denied'), 'Unpublished node is no longer accessible.');
$this
->drupalGet('forum/' . $tid);
$this
->assertNoText($title, 'Unpublished forum topic no longer appears on index.');
}
}