You are here

public function FeedsRSStoNodesTest::testSkipNewItems in Feeds 7.2

Tests skip new items.

File

tests/feeds_processor_node.test, line 709
Tests for plugins/FeedsNodeProcessor.inc.

Class

FeedsRSStoNodesTest
Test aggregating a feed as node items.

Code

public function testSkipNewItems() {

  // Include FeedsProcessor.inc so processor related constants are available.
  module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');

  // Attach to standalone importer.
  $this
    ->setSettings('syndication', NULL, array(
    'content_type' => '',
  ));

  // Set that new items should not be imported.
  $this
    ->setSettings('syndication', 'FeedsNodeProcessor', array(
    'insert_new' => FEEDS_SKIP_NEW,
    'update_existing' => FEEDS_SKIP_EXISTING,
  ));

  // Make title unique target.
  $this
    ->removeMappings('syndication', $this
    ->getCurrentMappings('syndication'));
  $this
    ->addMappings('syndication', array(
    0 => array(
      'source' => 'title',
      'target' => 'title',
      'unique' => TRUE,
    ),
    1 => array(
      'source' => 'description',
      'target' => 'body',
    ),
    2 => array(
      'source' => 'timestamp',
      'target' => 'created',
    ),
  ));

  // Do a first import, no nodes should be created.
  $edit = array(
    'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
  );
  $this
    ->drupalPost('import/syndication', $edit, 'Import');
  $this
    ->assertText('There are no new nodes');

  // Now create two nodes with titles that are present in the source
  // "developmentseed.rss2".
  $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'title' => 'Open Atrium Translation Workflow: Two Way Translation Updates',
  ));
  $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'title' => 'Week in DC Tech: October 5th Edition',
  ));

  // Import again. Since the processor is set to not update as well, nothing
  // should be imported.
  $this
    ->drupalPost('import/syndication', array(), 'Import');
  $this
    ->assertText('There are no new nodes');

  // Now set importer to update existing.
  $this
    ->setSettings('syndication', 'FeedsNodeProcessor', array(
    'update_existing' => FEEDS_UPDATE_EXISTING,
  ));

  // And import again. Two nodes should be updated.
  $this
    ->drupalPost('import/syndication', array(), 'Import');
  $this
    ->assertText('Updated 2 nodes.');

  // Change "insert_new" setting to insert new items to verify if changing the
  // setting later has the effect that new items will be imported as yet.
  $this
    ->setSettings('syndication', 'FeedsNodeProcessor', array(
    'insert_new' => FEEDS_INSERT_NEW,
  ));

  // Import. Eight nodes should be created. No nodes should be updated.
  $this
    ->drupalPost('import/syndication', array(), 'Import');
  $this
    ->assertText('Created 8 nodes.');
  $this
    ->assertNoText('Updated 2 nodes.');
}