function ForumTest::testForumWithNewPost

Same name in other branches
  1. 8.9.x core/modules/forum/tests/src/Functional/ForumTest.php \Drupal\Tests\forum\Functional\ForumTest::testForumWithNewPost()
  2. 10 core/modules/forum/tests/src/Functional/ForumTest.php \Drupal\Tests\forum\Functional\ForumTest::testForumWithNewPost()
  3. 11.x core/modules/forum/tests/src/Functional/ForumTest.php \Drupal\Tests\forum\Functional\ForumTest::testForumWithNewPost()

Tests a forum with a new post displays properly.

File

core/modules/forum/tests/src/Functional/ForumTest.php, line 522

Class

ForumTest
Tests for forum.module.

Namespace

Drupal\Tests\forum\Functional

Code

public function testForumWithNewPost() {
    // Log in as the first user.
    $this->drupalLogin($this->adminUser);
    // Create a forum container.
    $this->forumContainer = $this->createForum('container');
    // Create a forum.
    $this->forum = $this->createForum('forum');
    // Create a topic.
    $node = $this->createForumTopic($this->forum, FALSE);
    // Log in as a second user.
    $this->drupalLogin($this->postCommentUser);
    // Post a reply to the topic.
    $edit = [];
    $edit['subject[0][value]'] = $this->randomMachineName();
    $edit['comment_body[0][value]'] = $this->randomMachineName();
    $this->drupalGet('node/' . $node->id());
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Test adding a new comment.
    $this->clickLink('Add new comment');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->fieldExists('comment_body[0][value]');
    // Log in as the first user.
    $this->drupalLogin($this->adminUser);
    // Check that forum renders properly.
    $this->drupalGet("forum/{$this->forum['tid']}");
    $this->assertSession()
        ->statusCodeEquals(200);
    // Verify there is no unintentional HTML tag escaping.
    $this->assertSession()
        ->assertNoEscaped('<');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.