File
- drupal/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php, line 99
- Definition of Drupal\forum\Tests\ForumBlockTest.
Class
- ForumBlockTest
- Provides automated tests for the Forum blocks.
Namespace
Drupal\forum\Tests
Code
function testActiveForumTopicsBlock() {
$this
->drupalLogin($this->adminUser);
$topics = $this
->createForumTopics(10);
$timestamp = time();
$langcode = LANGUAGE_NOT_SPECIFIED;
for ($index = 0; $index < 5; $index++) {
$node = $this
->drupalGetNodeByTitle($topics[$index]);
$comment = entity_create('comment', array(
'nid' => $node->nid,
'subject' => $this
->randomString(20),
'comment_body' => array(
LANGUAGE_NOT_SPECIFIED => $this
->randomString(256),
),
'created' => $timestamp + $index,
));
comment_save($comment);
}
$edit = array();
$edit['blocks[forum_active][region]'] = 'sidebar_second';
$this
->drupalPost('admin/structure/block', $edit, t('Save blocks'));
$this
->assertResponse(200);
$this
->assertText(t('The block settings have been updated.'), 'Active forum topics forum block was enabled');
$this
->assertLink(t('More'), 0, 'Active forum topics block has a "more"-link.');
$this
->assertLinkByHref('forum', 0, 'Active forum topics block has a "more"-link.');
$this
->drupalGet('<front>');
for ($index = 0; $index < 10; $index++) {
if ($index < 5) {
$this
->assertLink($topics[$index], 0, format_string('Forum topic @topic found in the "Active forum topics" block.', array(
'@topic' => $topics[$index],
)));
}
else {
$this
->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "Active forum topics" block.', array(
'@topic' => $topics[$index],
)));
}
}
$edit = array();
$edit['block_active_limit'] = 2;
$this
->drupalPost('admin/structure/block/manage/forum/active/configure', $edit, t('Save block'));
$this
->assertResponse(200);
for ($index = 0; $index < 10; $index++) {
if (in_array($index, array(
3,
4,
))) {
$this
->assertLink($topics[$index], 0, 'Forum topic found in the "Active forum topics" block.');
}
else {
$this
->assertNoText($topics[$index], 'Forum topic not found in the "Active forum topics" block.');
}
}
$edit = array();
$edit['blocks[forum_active][region]'] = BLOCK_REGION_NONE;
$this
->drupalPost('admin/structure/block', $edit, t('Save blocks'));
$this
->assertResponse(200);
$this
->assertText(t('The block settings have been updated.'), '"Active forum topics" block was disabled');
}