function ForumBlockTest::testNewForumTopicsBlock
Same name in other branches
- 8.9.x core/modules/forum/tests/src/Functional/ForumBlockTest.php \Drupal\Tests\forum\Functional\ForumBlockTest::testNewForumTopicsBlock()
- 10 core/modules/forum/tests/src/Functional/ForumBlockTest.php \Drupal\Tests\forum\Functional\ForumBlockTest::testNewForumTopicsBlock()
- 11.x core/modules/forum/tests/src/Functional/ForumBlockTest.php \Drupal\Tests\forum\Functional\ForumBlockTest::testNewForumTopicsBlock()
Tests the "New forum topics" block.
File
-
core/
modules/ forum/ tests/ src/ Functional/ ForumBlockTest.php, line 54
Class
- ForumBlockTest
- Tests the forum blocks.
Namespace
Drupal\Tests\forum\FunctionalCode
public function testNewForumTopicsBlock() {
$this->drupalLogin($this->adminUser);
// Enable the new forum topics block.
$block = $this->drupalPlaceBlock('forum_new_block');
$this->drupalGet('');
// Create 5 forum topics.
$topics = $this->createForumTopics();
$this->assertSession()
->linkExists('More', 0, 'New forum topics block has a "more"-link.');
$this->assertSession()
->linkByHrefExists('forum', 0, 'New forum topics block has a "more"-link.');
// We expect all 5 forum topics to appear in the "New forum topics" block.
foreach ($topics as $topic) {
$this->assertSession()
->linkExists($topic, 0, new FormattableMarkup('Forum topic @topic found in the "New forum topics" block.', [
'@topic' => $topic,
]));
}
// Configure the new forum topics block to only show 2 topics.
$block->getPlugin()
->setConfigurationValue('block_count', 2);
$block->save();
$this->drupalGet('');
// We expect only the 2 most recent forum topics to appear in the "New forum
// topics" block.
for ($index = 0; $index < 5; $index++) {
if (in_array($index, [
3,
4,
])) {
$this->assertSession()
->linkExists($topics[$index], 0, new FormattableMarkup('Forum topic @topic found in the "New forum topics" block.', [
'@topic' => $topics[$index],
]));
}
else {
$this->assertSession()
->pageTextNotContains($topics[$index]);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.