function ForumTest::testForumWithNewPost

Same name and namespace in other branches
  1. 9 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 523

Class

ForumTest
Tests for <a href="/api/drupal/core%21modules%21forum%21forum.module/8.9.x" title="Provides discussion forums." class="local">forum.module</a>.

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->drupalPostForm('node/' . $node->id(), $edit, t('Save'));
    $this->assertSession()
        ->statusCodeEquals(200);
    // Test replying to a comment.
    $this->clickLink('Reply');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertFieldByName('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->assertNoEscaped('<');
}

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