Skip to content
Snippets Groups Projects
Commit 23584efb authored by megachriz's avatar megachriz Committed by MegaChriz
Browse files

Issue #1870528 by MegaChriz: Added tests for rules event...

Issue #1870528 by MegaChriz: Added tests for rules event feeds_import_IMPORTER_ID and the rules action feeds_skip_item. Also specified bundle for all feeds_import_IMPORTER_ID events (previously this attribute was only declared for the node processor).
parent da83212b
No related branches found
No related tags found
No related merge requests found
...@@ -44,16 +44,13 @@ function feeds_rules_event_info() { ...@@ -44,16 +44,13 @@ function feeds_rules_event_info() {
$entity_type => array( $entity_type => array(
'label' => t('Imported @label', array('@label' => $label)), 'label' => t('Imported @label', array('@label' => $label)),
'type' => $entity_type, 'type' => $entity_type,
'bundle' => $processor->bundle(),
// Saving is handled by feeds anyway (unless the skip action is used). // Saving is handled by feeds anyway (unless the skip action is used).
'skip save' => TRUE, 'skip save' => TRUE,
), ),
), ),
'access callback' => 'feeds_rules_access_callback', 'access callback' => 'feeds_rules_access_callback',
); );
// Add bundle information if the node processor is used.
if ($processor instanceof FeedsNodeProcessor) {
$info['feeds_import_'. $importer->id]['variables'][$entity_type]['bundle'] = $processor->bundle();
}
} }
return $info; return $info;
} }
......
...@@ -39,6 +39,9 @@ class FeedsRulesTest extends FeedsWebTestCase { ...@@ -39,6 +39,9 @@ class FeedsRulesTest extends FeedsWebTestCase {
), ),
) )
); );
// Clear static cache to make dynamic events available to Rules.
drupal_static_reset();
} }
/** /**
...@@ -54,11 +57,7 @@ class FeedsRulesTest extends FeedsWebTestCase { ...@@ -54,11 +57,7 @@ class FeedsRulesTest extends FeedsWebTestCase {
*/ */
protected function createTestRule($event, $action = TRUE) { protected function createTestRule($event, $action = TRUE) {
$rule = rules_reaction_rule(); $rule = rules_reaction_rule();
$rule->event($event) $rule->event($event);
->condition('data_is', array(
'data:select' => 'source:id',
'value' => 'node'
));
if ($action) { if ($action) {
$rule->action('feeds_tests_create_node'); $rule->action('feeds_tests_create_node');
} }
...@@ -70,6 +69,10 @@ class FeedsRulesTest extends FeedsWebTestCase { ...@@ -70,6 +69,10 @@ class FeedsRulesTest extends FeedsWebTestCase {
*/ */
public function testFeedsBeforeImportEvent() { public function testFeedsBeforeImportEvent() {
$rule = $this->createTestRule('feeds_before_import'); $rule = $this->createTestRule('feeds_before_import');
$rule->condition('data_is', array(
'data:select' => 'source:id',
'value' => 'node',
));
$rule->integrityCheck()->save(); $rule->integrityCheck()->save();
// Set source file to import. // Set source file to import.
...@@ -96,6 +99,10 @@ class FeedsRulesTest extends FeedsWebTestCase { ...@@ -96,6 +99,10 @@ class FeedsRulesTest extends FeedsWebTestCase {
*/ */
public function testFeedsAfterImportEvent() { public function testFeedsAfterImportEvent() {
$rule = $this->createTestRule('feeds_after_import'); $rule = $this->createTestRule('feeds_after_import');
$rule->condition('data_is', array(
'data:select' => 'source:id',
'value' => 'node',
));
$rule->integrityCheck()->save(); $rule->integrityCheck()->save();
// Set source file to import. // Set source file to import.
...@@ -116,4 +123,63 @@ class FeedsRulesTest extends FeedsWebTestCase { ...@@ -116,4 +123,63 @@ class FeedsRulesTest extends FeedsWebTestCase {
$node = node_load(2); $node = node_load(2);
$this->assertEqual('Ut wisi enim ad minim veniam', $node->title); $this->assertEqual('Ut wisi enim ad minim veniam', $node->title);
} }
/**
* Tests if the Rules event 'feeds_import_IMPORTER_ID' is invoked.
*/
public function testFeedsBeforeSavingItemEvent() {
$rule = $this->createTestRule('feeds_import_node');
// Act before saving the second node.
$rule->condition('data_is', array(
'data:select' => 'node:title',
'value' => 'Ut wisi enim ad minim veniam',
));
$rule->integrityCheck()->save();
// Set source file to import.
$source_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/content.csv';
$edit = array(
'feeds[FeedsHTTPFetcher][source]' => $source_url,
);
$this->drupalPost('import/node', $edit, t('Import'));
$this->assertText('Created 2 nodes');
// Assert that a test node was created before importing the second item.
$node = node_load(2);
$this->assertEqual('Test node', $node->title);
// Assert titles of imported nodes as well.
$node = node_load(1);
$this->assertEqual('Lorem ipsum', $node->title);
$node = node_load(3);
$this->assertEqual('Ut wisi enim ad minim veniam', $node->title);
}
/**
* Tests the Rules action 'feeds_skip_item'.
*/
public function testFeedsSkipItemAction() {
$rule = $this->createTestRule('feeds_import_node', FALSE);
// Setup rule to not save the first item (which title is 'Lorem Ipsum').
$rule->condition('data_is', array(
'data:select' => 'node:title',
'value' => 'Lorem ipsum',
));
$rule->action('feeds_skip_item', array(
'entity:select' => 'node',
));
$rule->integrityCheck()->save();
// Set source file to import.
$source_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/content.csv';
$edit = array(
'feeds[FeedsHTTPFetcher][source]' => $source_url,
);
$this->drupalPost('import/node', $edit, t('Import'));
$this->assertText('Created 1 node');
// Assert that only the second item was imported.
$node = node_load(1);
$this->assertEqual('Ut wisi enim ad minim veniam', $node->title);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment