public function AggregatorRenderingTest::testBlockLinks

Adds a feed block to the page and checks its links.

@todo Test the category block as well.

File

drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php, line 37
Definition of Drupal\aggregator\Tests\AggregatorRenderingTest.

Class

AggregatorRenderingTest
Tests rendering functionality in the Aggregator module.

Namespace

Drupal\aggregator\Tests

Code

public function testBlockLinks() {

  // Create feed.
  $this
    ->createSampleNodes();
  $feed = $this
    ->createFeed();
  $this
    ->updateFeedItems($feed, $this
    ->getDefaultFeedItemCount());

  // Clear the block cache to load the new block definitions.
  $this->container
    ->get('plugin.manager.block')
    ->clearCachedDefinitions();

  // Need admin user to be able to access block admin.
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer blocks',
    'access administration pages',
    'administer news feeds',
    'access news feeds',
  ));
  $this
    ->drupalLogin($admin_user);
  $block = $this
    ->drupalPlaceBlock("aggregator_feed_block:{$feed->id()}", array(
    'label' => 'feed-' . $feed
      ->label(),
    'block_count' => 2,
  ));

  // Confirm that the block is now being displayed on pages.
  $this
    ->drupalGet('test-page');
  $this
    ->assertText($block
    ->label(), 'Feed block is displayed on the page.');

  // Find the expected read_more link.
  $href = 'aggregator/sources/' . $feed
    ->id();
  $links = $this
    ->xpath('//a[@href = :href]', array(
    ':href' => url($href),
  ));
  $this
    ->assert(isset($links[0]), format_string('Link to href %href found.', array(
    '%href' => $href,
  )));

  // Visit that page.
  $this
    ->drupalGet($href);
  $correct_titles = $this
    ->xpath('//h1[normalize-space(text())=:title]', array(
    ':title' => $feed
      ->label(),
  ));
  $this
    ->assertFalse(empty($correct_titles), 'Aggregator feed page is available and has the correct title.');

  // Set the number of news items to 0 to test that the block does not show
  // up.
  $feed->block = 0;
  $feed
    ->save();

  // Check that the block is no longer displayed.
  $this
    ->drupalGet('test-page');
  $this
    ->assertNoText($block
    ->label(), 'Feed block is not displayed on the page when number of items is set to 0.');
}