You are here

public function AggregatorRenderingTest::testFeedPage in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/aggregator/tests/src/Functional/AggregatorRenderingTest.php \Drupal\Tests\aggregator\Functional\AggregatorRenderingTest::testFeedPage()

Creates a feed and checks that feed's page.

File

core/modules/aggregator/tests/src/Functional/AggregatorRenderingTest.php, line 96

Class

AggregatorRenderingTest
Tests display of aggregator items on the page.

Namespace

Drupal\Tests\aggregator\Functional

Code

public function testFeedPage() {

  // Increase the number of items published in the rss.xml feed so we have
  // enough articles to test paging.
  $view = View::load('frontpage');
  $display =& $view
    ->getDisplay('feed_1');
  $display['display_options']['pager']['options']['items_per_page'] = 30;
  $view
    ->save();

  // Create a feed with 30 items.
  $this
    ->createSampleNodes(30);
  $feed = $this
    ->createFeed();
  $this
    ->updateFeedItems($feed, 30);

  // Check for presence of an aggregator pager.
  $this
    ->drupalGet('aggregator');
  $elements = $this
    ->xpath("//ul[contains(@class, :class)]", [
    ':class' => 'pager__items',
  ]);
  $this
    ->assertTrue(!empty($elements), 'Individual source page contains a pager.');

  // Check for sources page title.
  $this
    ->drupalGet('aggregator/sources');
  $titles = $this
    ->xpath('//h1[normalize-space(text())=:title]', [
    ':title' => 'Sources',
  ]);
  $this
    ->assertTrue(!empty($titles), 'Source page contains correct title.');

  // Find the expected read_more link on the sources page.
  $href = $feed
    ->toUrl()
    ->toString();
  $links = $this
    ->xpath('//a[@href = :href]', [
    ':href' => $href,
  ]);
  $this
    ->assertTrue(isset($links[0]), new FormattableMarkup('Link to href %href found.', [
    '%href' => $href,
  ]));
  $cache_tags_header = $this
    ->drupalGetHeader('X-Drupal-Cache-Tags');
  $cache_tags = explode(' ', $cache_tags_header);
  $this
    ->assertContains('aggregator_feed:' . $feed
    ->id(), $cache_tags);

  // Check the rss aggregator page as anonymous user.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('aggregator/rss');
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Check the rss aggregator page as admin.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('aggregator/rss');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertEqual($this
    ->drupalGetHeader('Content-type'), 'application/rss+xml; charset=utf-8');

  // Check the opml aggregator page.
  $this
    ->drupalGet('aggregator/opml');
  $content = $this
    ->getSession()
    ->getPage()
    ->getContent();

  // We can't use Mink xpath queries here because it only supports HTML pages,
  // but we are dealing with XML here.
  $xml = simplexml_load_string($content);
  $attributes = $xml
    ->xpath('//outline[1]')[0]
    ->attributes();
  $this
    ->assertEquals('rss', $attributes->type);
  $this
    ->assertEquals($feed
    ->label(), $attributes->text);
  $this
    ->assertEquals($feed
    ->getUrl(), $attributes->xmlUrl);

  // Check for the presence of a pager.
  $this
    ->drupalGet('aggregator/sources/' . $feed
    ->id());
  $elements = $this
    ->xpath("//ul[contains(@class, :class)]", [
    ':class' => 'pager__items',
  ]);
  $this
    ->assertTrue(!empty($elements), 'Individual source page contains a pager.');
  $cache_tags = explode(' ', $this
    ->drupalGetHeader('X-Drupal-Cache-Tags'));
  $this
    ->assertContains('aggregator_feed:' . $feed
    ->id(), $cache_tags);
  $this
    ->assertContains('aggregator_feed_view', $cache_tags);
  $this
    ->assertContains('aggregator_item_view', $cache_tags);
}