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

Issue #1886230 by MegaChriz, generalredneck: fixed invoking rules events...

Issue #1886230 by MegaChriz, generalredneck: fixed invoking rules events "feeds_before_import" and "feeds_after_import".
parent 078346c5
No related branches found
No related tags found
No related merge requests found
......@@ -67,6 +67,7 @@ files[] = tests/feeds_processor_node.test
files[] = tests/feeds_processor_term.test
files[] = tests/feeds_processor_user.test
files[] = tests/feeds_push.test
files[] = tests/feeds_rules.test
files[] = tests/feeds_scheduler.test
files[] = tests/feeds_mapper_link.test
files[] = tests/feeds_mapper_summary.test
......
......@@ -381,6 +381,9 @@ class FeedsSource extends FeedsConfigurable {
// If fetcher result is empty, we are starting a new import, log.
if (empty($this->fetcher_result)) {
module_invoke_all('feeds_before_import', $this);
if (module_exists('rules')) {
rules_invoke_event('feeds_before_import', $this);
}
$this->state[FEEDS_START] = time();
}
......@@ -416,6 +419,9 @@ class FeedsSource extends FeedsConfigurable {
$this->log('import', 'Imported in @s seconds.', array('@s' => $this->imported - $this->state[FEEDS_START]), WATCHDOG_INFO);
$this->importer->fetcher->afterImport($this);
module_invoke_all('feeds_after_import', $this);
if (module_exists('rules')) {
rules_invoke_event('feeds_after_import', $this);
}
unset($this->fetcher_result, $this->state);
}
$this->save();
......
<?php
/**
* Tests for Rules integration.
*/
class FeedsRulesTest extends FeedsWebTestCase {
public static function getInfo() {
return array(
'name' => 'Rules integration',
'description' => 'Tests for Rules integration.',
'group' => 'Feeds',
'dependencies' => array('rules'),
);
}
/**
* Set up test.
*/
public function setUp() {
parent::setUp(array('rules'));
// Create an importer configuration.
$this->createImporterConfiguration('Node import', 'node');
$this->setSettings('node', NULL, array('content_type' => ''));
$this->setPlugin('node', 'FeedsHTTPFetcher');
$this->setPlugin('node', 'FeedsCSVParser');
$this->addMappings('node',
array(
0 => array(
'source' => 'title',
'target' => 'title',
'unique' => FALSE,
),
1 => array(
'source' => 'guid',
'target' => 'guid',
'unique' => TRUE,
),
)
);
}
/**
* Creates a test rule.
*
* @param string $event
* The event to react on.
* @param bool $action
* If a dummy action should be executed.
*
* @return RulesReactionRule
* An instance of RulesReactionRule.
*/
protected function createTestRule($event, $action = TRUE) {
$rule = rules_reaction_rule();
$rule->event($event)
->condition('data_is', array(
'data:select' => 'source:id',
'value' => 'node'
));
if ($action) {
$rule->action('feeds_tests_create_node');
}
return $rule;
}
/**
* Tests if the Rules event 'feeds_before_import' is invoked.
*/
public function testFeedsBeforeImportEvent() {
$rule = $this->createTestRule('feeds_before_import');
$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* the import.
$node = node_load(1);
$this->assertEqual('Test node', $node->title);
// Assert titles of imported nodes as well.
$node = node_load(2);
$this->assertEqual('Lorem ipsum', $node->title);
$node = node_load(3);
$this->assertEqual('Ut wisi enim ad minim veniam', $node->title);
}
/**
* Tests if the Rules event 'feeds_after_import' is invoked.
*/
public function testFeedsAfterImportEvent() {
$rule = $this->createTestRule('feeds_after_import');
$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 *after* the import.
$node = node_load(3);
$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(2);
$this->assertEqual('Ut wisi enim ad minim veniam', $node->title);
}
}
<?php
/**
* @file
* Includes any rules integration provided by the module.
*/
/**
* Implements hook_rules_action_info().
*/
function feeds_tests_rules_action_info() {
$items['feeds_tests_create_node'] = array(
'label' => t('Create a node'),
'group' => t('Rules test'),
);
return $items;
}
/**
* Rules action callback: creates a node.
*/
function feeds_tests_create_node() {
$node = new stdClass();
$node->title = 'Test node';
$node->type = 'page';
$node->status = 1;
$node->uid = 0;
node_object_prepare($node);
node_save($node);
}
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