You are here

public function FeedsRSStoNodesTest::testExpiry in Feeds 8.2

Tests expiring nodes.

File

lib/Drupal/feeds/Tests/FeedsRSStoNodesTest.php, line 445
Tests for plugins/FeedsNodeProcessor.inc.

Class

FeedsRSStoNodesTest
Test aggregating a feed as node items.

Namespace

Drupal\feeds\Tests

Code

public function testExpiry() {

  // Create importer configuration.
  $this
    ->setSettings('syndication', NULL, array(
    'content_type' => '',
  ));
  $this
    ->setSettings('syndication', 'node', array(
    'expire' => 43200,
  ));

  // Create importer.
  $this
    ->importURL('syndication');

  // Set date of a few nodes to current date so they don't expire.
  $edit = array(
    'date[date]' => date('Y-m-d'),
  );
  $this
    ->drupalPost('node/2/edit', $edit, 'Save and keep published');
  $this
    ->assertText(date('m/d/Y'), 'Found correct date.');
  $this
    ->drupalPost('node/5/edit', $edit, 'Save and keep published');
  $this
    ->assertText(date('m/d/Y'), 'Found correct date.');

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

  // Set feeds source expire to run immediately.
  db_update('job_schedule')
    ->fields(array(
    'next' => 0,
  ))
    ->condition('name', 'feeds_source_expire')
    ->execute();

  // Run cron to execute scheduled jobs.
  $this
    ->cronRun();

  // Query the feeds_items table and count the number of entries.
  $row_count = db_query('SELECT COUNT(*) FROM {feeds_item}')
    ->fetchField();

  // Check that number of feeds items is equal to the expected items.
  $this
    ->assertEqual($row_count, 2, 'Nodes expired.');
}