public function FeedsEntityProcessorBasicTest::test in Feeds entity processor 7
Test basic entity creation.
File
- tests/
src/ FeedsEntityProcessorBasicTest.test, line 37 - Tests for plugins/FeedsEntityProcessor.inc.
Class
- FeedsEntityProcessorBasicTest
- Tests importing entities using the generic processor.
Code
public function test() {
$bundle = drupal_strtolower($this
->randomName());
// Create bundle entity.
entity_create('entity_test_type', array(
'id' => drupal_strtolower($this
->randomName()),
'name' => $bundle,
))
->save();
$this
->setSettings('syndication', 'FeedsEntityProcessorEntity_test', array(
'bundle' => $bundle,
));
$this
->addMappings('syndication', array(
0 => array(
'source' => 'guid',
'target' => 'guid',
'unique' => TRUE,
),
));
// Run import.
$this
->importURL('syndication', $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2');
// Assert 10 items created.
$this
->assertText('Created 10 test entities');
$this
->assertEqual(10, db_query("SELECT COUNT(*) FROM {entity_test}")
->fetchField());
// Enable skip missing test entities and import updated feed file.
$this
->setSettings('syndication', 'FeedsEntityProcessorEntity_test', array(
'update_non_existent' => 'skip',
));
$missing_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed_missing.rss2';
$this
->importURL('syndication', $missing_url);
$this
->assertText('There are no new test entities');
$this
->assertEqual(10, db_query("SELECT COUNT(*) FROM {entity_test}")
->fetchField());
// Now delete all items.
$this
->drupalPost('import/syndication/delete-items', array(), 'Delete');
$this
->assertText('Deleted 10 test entities');
$this
->assertEqual(0, db_query("SELECT COUNT(*) FROM {entity_test}")
->fetchField());
// Import again, to reset entity counts.
$this
->importURL('syndication', $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2');
$this
->assertText('Created 10 test entities');
$this
->assertEqual(10, db_query("SELECT COUNT(*) FROM {entity_test}")
->fetchField());
// Change settings to delete non-existent entities from feed.
$this
->setSettings('syndication', 'FeedsEntityProcessorEntity_test', array(
'update_non_existent' => 'delete',
));
$this
->importURL('syndication', $missing_url);
$this
->assertText('Removed 1 test entity');
$this
->assertEqual(9, db_query("SELECT COUNT(*) FROM {entity_test}")
->fetchField());
// Now delete all items.
$this
->drupalPost('import/syndication/delete-items', array(), 'Delete');
$this
->assertText('Deleted 9 test entities');
$this
->assertEqual(0, db_query("SELECT COUNT(*) FROM {entity_test}")
->fetchField());
}