public function ForumBlockTest::testNewForumTopicsBlock

Tests the "New forum topics" block.

File

drupal/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php, line 56
Definition of Drupal\forum\Tests\ForumBlockTest.

Class

ForumBlockTest
Provides automated tests for the Forum blocks.

Namespace

Drupal\forum\Tests

Code

public function testNewForumTopicsBlock() {
  $this
    ->drupalLogin($this->adminUser);

  // Create 5 forum topics.
  $topics = $this
    ->createForumTopics();

  // Enable the new forum topics block.
  $block = $this
    ->drupalPlaceBlock('forum_new_block');
  $this
    ->drupalGet('');
  $this
    ->assertLink(t('More'), 0, 'New forum topics block has a "more"-link.');
  $this
    ->assertLinkByHref('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
      ->assertLink($topic, 0, format_string('Forum topic @topic found in the "New forum topics" block.', array(
      '@topic' => $topic,
    )));
  }

  // Configure the new forum topics block to only show 2 topics.
  $block
    ->getPlugin()
    ->setConfig('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, array(
      3,
      4,
    ))) {
      $this
        ->assertLink($topics[$index], 0, format_string('Forum topic @topic found in the "New forum topics" block.', array(
        '@topic' => $topics[$index],
      )));
    }
    else {
      $this
        ->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "New forum topics" block.', array(
        '@topic' => $topics[$index],
      )));
    }
  }
}