diff --git a/tests/feeds_processor_node.test b/tests/feeds_processor_node.test index c72cff2..622c5c5 100644 --- a/tests/feeds_processor_node.test +++ b/tests/feeds_processor_node.test @@ -701,4 +701,56 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase { $this->assertText('There are no new nodes.'); } + /** + * Tests if importing items does not result into errors if the feeds_item contains references + * to entities that no longer exist. + * + * @todo Add a test for an item that points to a non-existing feed node as well. + */ + public function testOrphanedFeedsItem() { + // Include FeedsProcessor.inc so processor related constants are available. + module_load_include('inc', 'feeds', 'plugins/FeedsProcessor'); + + // Create a feeds item with a reference to a non-existing entity. + // Note that the GUID value is used in the file that gets imported later. + $item = array( + 'entity_type' => 'node', + 'entity_id' => 120, + 'id' => 'syndication', + 'feed_nid' => 0, + 'imported' => REQUEST_TIME -1, + 'url' => '', + 'guid' => 1, + 'hash' => '', + ); + drupal_write_record('feeds_item', $item); + + // Attach to standalone importer and configure. + $this->setSettings('syndication', NULL, array('content_type' => '')); + $this->setPlugin('syndication', 'FeedsFileFetcher'); + $this->setPlugin('syndication', 'FeedsCSVParser'); + $this->setSettings('syndication', 'FeedsNodeProcessor', array( + 'update_existing' => FEEDS_UPDATE_EXISTING, + )); + $this->removeMappings('syndication', $this->getCurrentMappings('syndication')); + $this->addMappings('syndication', array( + 0 => array( + 'source' => 'guid', + 'target' => 'guid', + 'unique' => TRUE, + ), + 1 => array( + 'source' => 'title', + 'target' => 'title', + ), + )); + + // Import file. + $this->importFile('syndication', $this->absolutePath() . '/tests/feeds/content.csv'); + + // Although for one item in the file a reference existed in the feeds_item table, both + // items did not exist on the website, so we expect that for both items a node is created. + $this->assertText('Created 2 nodes'); + } + }