You are here

public function ForumTest::testForumWithNewPost in Drupal 8

Same name and namespace in other branches
  1. 9 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 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
    ->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('<');
}