function AggregatorRenderingTest::testFeedPage
Same name in other branches
- 8.9.x 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 93
Class
- AggregatorRenderingTest
- Tests display of aggregator items on the page.
Namespace
Drupal\Tests\aggregator\FunctionalCode
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);
// Request the /aggregator page so that it is cached.
$this->drupalGet('aggregator');
$feed = $this->createFeed();
$this->updateFeedItems($feed, 30);
// Verify that items are loaded on the page by checking for the pager.
$this->drupalGet('aggregator');
$this->assertSession()
->elementExists('xpath', '//ul[contains(@class, "pager__items")]');
// Save the feed entity to invalidate the cache so that the paginated cache
// context can be tested.
$feed->save();
// Request page with no feed items to ensure cache context is set correctly.
$this->drupalGet('aggregator', [
'query' => [
'page' => 2,
],
]);
// Check for presence of an aggregator pager.
$this->drupalGet('aggregator');
$this->assertSession()
->elementExists('xpath', '//ul[contains(@class, "pager__items")]');
// Check for sources page title.
$this->drupalGet('aggregator/sources');
$this->assertSession()
->elementTextContains('xpath', '//h1', 'Sources');
// Find the expected read_more link on the sources page.
$href = $feed->toUrl()
->toString();
$this->assertSession()
->linkByHrefExists($href);
$this->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed->id());
// 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->assertSession()
->responseHeaderEquals('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());
$this->assertSession()
->elementExists('xpath', '//ul[contains(@class, "pager__items")]');
$this->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed->id());
$this->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed_view');
$this->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_item_view');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.