FeedsEntityProcessorBasicTest.test in Feeds entity processor 7
Tests for plugins/FeedsEntityProcessor.inc.
File
tests/src/FeedsEntityProcessorBasicTest.testView source
<?php
/**
* @file
* Tests for plugins/FeedsEntityProcessor.inc.
*/
/**
* Tests importing entities using the generic processor.
*/
class FeedsEntityProcessorBasicTest extends FeedsWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Basic import capabilities',
'description' => 'Tests importing entities using the generic processor.',
'group' => 'Feeds entity processor',
);
}
/**
* Set up test.
*/
public function setUp() {
parent::setUp(array(
'entity_test',
'feeds_entity_processor',
));
// Create an importer configuration.
$this
->createImporterConfiguration('Syndication', 'syndication');
$this
->setPlugin('syndication', 'FeedsEntityProcessorEntity_test');
}
/**
* Test basic entity creation.
*/
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());
}
/**
* Tests if the entity ID can be used as an unique target.
*/
public function testEntityIdAsUniqueTarget() {
// Include FeedsProcessor.inc so processor related constants are available.
module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');
$bundle = drupal_strtolower($this
->randomName());
// Create bundle entity.
entity_create('entity_test_type', array(
'id' => drupal_strtolower($this
->randomName()),
'name' => $bundle,
))
->save();
// Create an entity_test record in the database.
$record = array(
'pid' => 1,
'name' => $bundle,
'uid' => 0,
);
drupal_write_record('entity_test', $record);
// Set importer settings.
$this
->setPlugin('syndication', 'FeedsCSVParser');
$this
->setSettings('syndication', 'FeedsEntityProcessorEntity_test', array(
'bundle' => $bundle,
'update_existing' => FEEDS_UPDATE_EXISTING,
));
// Map to entity ID.
$this
->addMappings('syndication', array(
0 => array(
'source' => 'guid',
'target' => 'pid',
'unique' => TRUE,
),
));
// Run import.
$this
->importURL('syndication', $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/content.csv');
$this
->assertText('Updated 1 test entity');
$this
->assertText('Created 1 test entity');
}
}
Classes
Name![]() |
Description |
---|---|
FeedsEntityProcessorBasicTest | Tests importing entities using the generic processor. |