You are here

public function AggregatorTestBase::updateFeedItems in Drupal 8

Same name in this branch
  1. 8 core/modules/aggregator/src/Tests/AggregatorTestBase.php \Drupal\aggregator\Tests\AggregatorTestBase::updateFeedItems()
  2. 8 core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php \Drupal\Tests\aggregator\Functional\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.

1 call to AggregatorTestBase::updateFeedItems()
AggregatorTestBase::updateAndDelete in core/modules/aggregator/src/Tests/AggregatorTestBase.php
Adds and deletes feed items and ensure that the count is zero.

File

core/modules/aggregator/src/Tests/AggregatorTestBase.php, line 188

Class

AggregatorTestBase
Defines a base class for testing the Aggregator module.

Namespace

Drupal\aggregator\Tests

Code

public function updateFeedItems(FeedInterface $feed, $expected_count = NULL) {

  // First, let's ensure we can get to the rss xml.
  $this
    ->drupalGet($feed
    ->getUrl());
  $this
    ->assertResponse(200, new FormattableMarkup(':url is reachable.', [
    ':url' => $feed
      ->getUrl(),
  ]));

  // Attempt to access the update link directly without an access token.
  $this
    ->drupalGet('admin/config/services/aggregator/update/' . $feed
    ->id());
  $this
    ->assertResponse(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.
  $iids = \Drupal::entityQuery('aggregator_item')
    ->condition('fid', $feed
    ->id())
    ->execute();
  $feed->items = [];
  foreach ($iids as $iid) {
    $feed->items[] = $iid;
  }
  if ($expected_count !== NULL) {
    $feed->item_count = count($feed->items);
    $this
      ->assertEqual($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,
    ]));
  }
}