public function ForumBlockTest::testNewForumTopicsBlock in Drupal 9
Same name and namespace in other branches
- 8 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 51
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]);
}
}
}