ForumIndexTest.php in Drupal 9
File
core/modules/forum/tests/src/Functional/ForumIndexTest.php
View source
<?php
namespace Drupal\Tests\forum\Functional;
use Drupal\Tests\BrowserTestBase;
class ForumIndexTest extends BrowserTestBase {
protected static $modules = [
'taxonomy',
'comment',
'forum',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
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('Add new Forum topic');
$this
->assertSession()
->addressEquals("node/add/forum?forum_id={$tid}");
$this
->submitForm($edit, '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
->drupalGet('admin/structure/forum/add/forum');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->linkExists('edit forum');
$tid_child = $tid + 1;
$this
->drupalGet('forum/' . $tid);
$this
->assertSession()
->pageTextContains($title);
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'node_list');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'config:node.type.forum');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'comment_list');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'node:' . $node
->id());
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'taxonomy_term:' . $tid);
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'taxonomy_term:' . $tid_child);
$edit = [
'status[value]' => FALSE,
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->pageTextContains('Access denied');
$this
->drupalGet('forum/' . $tid);
$this
->assertSession()
->pageTextNotContains($title);
}
}