diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index e9ccb3e..2d0152a 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -506,7 +506,7 @@ function template_preprocess_forums(&$variables) { } $row[] = array( - 'data' => $topic->comment_count . $new_replies, + 'data' => array('#markup' => $topic->comment_count . $new_replies), 'class' => array('forum__replies'), ); $row[] = array( diff --git a/core/modules/forum/src/Tests/ForumIndexTest.php b/core/modules/forum/src/Tests/ForumIndexTest.php index b9ee537..9b95037 100644 --- a/core/modules/forum/src/Tests/ForumIndexTest.php +++ b/core/modules/forum/src/Tests/ForumIndexTest.php @@ -17,6 +17,20 @@ class ForumIndexTest extends WebTestBase { /** + * User account with access to create forum topics. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $webUser; + + /** + * User account with access to create replies in a forum topic. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $forumUser; + + /** * Modules to enable. * * @var array @@ -26,15 +40,15 @@ class ForumIndexTest extends WebTestBase { protected function setUp() { parent::setUp(); - // Create a test user. - $web_user = $this->drupalCreateUser(array('create forum content', 'edit own forum content', 'edit any forum content', 'administer nodes')); - $this->drupalLogin($web_user); + $this->webUser = $this->drupalCreateUser(array('create forum content', 'edit own forum content', 'edit any forum content', 'administer nodes')); + $this->forumUser = $this->drupalCreateUser(array('create forum content', 'edit own forum content', 'edit any forum content', 'administer nodes', 'administer comments', 'post comments', 'skip comment approval')); } /** * Tests the forum index for published and unpublished nodes. */ - function testForumIndexStatus() { + public function testForumIndexStatus() { + $this->drupalLogin($this->webUser); // The forum ID to use. $tid = 1; @@ -68,4 +82,41 @@ function testForumIndexStatus() { $this->drupalGet('forum/' . $tid); $this->assertNoText($title, 'Unpublished forum topic no longer appears on index.'); } + + public function testHistory() { + $this->drupalLogin($this->webUser); + // The forum ID to use. + $tid = 1; + + // Create a test node. + $title = $this->randomMachineName(20); + $edit = array( + 'title[0][value]' => $title, + 'body[0][value]' => $this->randomMachineName(200), + ); + + // Create the forum topic, preselecting the forum ID via a URL parameter. + $this->drupalGet("forum/$tid"); + $this->clickLink(t('Add new @node_type', array('@node_type' => 'Forum topic'))); + $this->drupalPostForm(NULL, $edit, t('Save and publish')); + + // Login as the forum user to create a reply. + $this->drupalLogin($this->forumUser); + + // Create a comment. + $edit = array(); + $edit['comment_body[0][value]'] = $this->randomMachineName(); + + $this->drupalGet("forum/$tid"); + $this->clickLink(t($title)); + $this->drupalPostForm(NULL, $edit, t('Save')); + + // Verify the new post message link is not escaped. + $this->drupalLogin($this->webUser); + $this->drupalGet("forum/$tid"); + $xpath = $this->buildXPathQuery('//td[@class="forum__replies"]/a/span[@class="visually-hidden"]'); + $new_replies_message = $this->xpath($xpath); + $this->assertTrue(!empty($new_replies_message), "The new replies message was found."); + } + }