You are here

public function UpdateNonExistentTest::testDeleteNonExistentItemsWithCron in Feeds 8.3

Tests 'Delete non-existent' option using cron.

Tests that previously imported items that are no longer available in the feed get deleted when the 'update_non_existent' setting is set to '_delete' and when performing an import using cron.

File

tests/src/Functional/UpdateNonExistentTest.php, line 224

Class

UpdateNonExistentTest
Tests the feature of updating items that are no longer available in the feed.

Namespace

Drupal\Tests\feeds\Functional

Code

public function testDeleteNonExistentItemsWithCron() {

  // Set 'update_non_existent' setting to 'delete'.
  $config = $this->feedType
    ->getProcessor()
    ->getConfiguration();
  $config['update_non_existent'] = ProcessorInterface::DELETE_NON_EXISTENT;
  $this->feedType
    ->getProcessor()
    ->setConfiguration($config);

  // Set the import period to run as often as possible.
  $this->feedType
    ->setImportPeriod(FeedTypeInterface::SCHEDULE_CONTINUOUSLY);
  $this->feedType
    ->save();

  // Create a feed and import first file.
  $feed = $this
    ->createFeed($this->feedType
    ->id(), [
    'source' => $this
      ->resourcesPath() . '/rss/googlenewstz.rss2',
  ]);

  // Run cron to import.
  $this
    ->cronRun();

  // Assert that 6 nodes have been created.
  $feed = $this
    ->reloadFeed($feed);
  static::assertEquals(6, $feed
    ->getItemCount());
  $this
    ->assertNodeCount(6);

  // Import an "updated" version of the file from which one item is removed.
  $feed
    ->setSource($this
    ->resourcesPath() . '/rss/googlenewstz_missing.rss2');
  $feed
    ->save();
  $this
    ->cronRun();

  // Assert that one node is removed.
  $feed = $this
    ->reloadFeed($feed);
  static::assertEquals(5, $feed
    ->getItemCount());
  $this
    ->assertNodeCount(5);

  // Re-import the original feed to import the removed node again.
  $feed
    ->setSource($this
    ->resourcesPath() . '/rss/googlenewstz.rss2');
  $feed
    ->save();
  $this
    ->cronRun();
  $feed = $this
    ->reloadFeed($feed);
  static::assertEquals(6, $feed
    ->getItemCount());
  $this
    ->assertNodeCount(6);
}