function AggregatorTestBase::updateFeedItems
Updates the feed items.
This method simulates a click to admin/config/services/aggregator/update/$fid.
Parameters
\Drupal\aggregator\FeedInterface $feed: Feed object representing the feed.
int|null $expected_count: Expected number of feed items. If omitted no check will happen.
File
-
core/
modules/ aggregator/ tests/ src/ Functional/ AggregatorTestBase.php, line 190
Class
- AggregatorTestBase
- Defines a base class for testing the Aggregator module.
Namespace
Drupal\Tests\aggregator\FunctionalCode
public function updateFeedItems(FeedInterface $feed, $expected_count = NULL) {
// First, let's ensure we can get to the rss xml.
$this->drupalGet($feed->getUrl());
$this->assertSession()
->statusCodeEquals(200);
// Attempt to access the update link directly without an access token.
$this->drupalGet('admin/config/services/aggregator/update/' . $feed->id());
$this->assertSession()
->statusCodeEquals(403);
// Refresh the feed (simulated link click).
$this->drupalGet('admin/config/services/aggregator');
$this->clickLink('Update items');
// Ensure we have the right number of items.
$item_ids = \Drupal::entityQuery('aggregator_item')->accessCheck(FALSE)
->condition('fid', $feed->id())
->execute();
$feed->items = array_values($item_ids);
if ($expected_count !== NULL) {
$feed->item_count = count($feed->items);
$this->assertEquals($expected_count, $feed->item_count, new FormattableMarkup('Total items in feed equal to the total items in database (@val1 != @val2)', [
'@val1' => $expected_count,
'@val2' => $feed->item_count,
]));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.