Révision ed9a13f1
Ajouté par Assos Assos il y a presque 4 ans
drupal7/sites/all/modules/feeds/tests/feeds_hooks.test | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
/** |
|
4 |
* @file |
|
5 |
* Contains FeedsHooksTestCase. |
|
6 |
*/ |
|
7 |
|
|
3 | 8 |
/** |
4 | 9 |
* Tests for hooks invoked by Feeds not related to mapping. |
5 | 10 |
*/ |
... | ... | |
16 | 21 |
); |
17 | 22 |
} |
18 | 23 |
|
24 |
/** |
|
25 |
* Ensure that the prevalidate hook is invoked. |
|
26 |
* |
|
27 |
* @see feeds_tests_feeds_prevalidate() |
|
28 |
*/ |
|
29 |
public function testPrevalidateHook() { |
|
30 |
// Include FeedsProcessor.inc to make its constants available. |
|
31 |
module_load_include('inc', 'feeds', 'plugins/FeedsProcessor'); |
|
32 |
|
|
33 |
// Set flag to test prevalidate hook. |
|
34 |
variable_set('feeds_tests_hook_feeds_prevalidate', TRUE); |
|
35 |
|
|
36 |
// Create CSV importer. |
|
37 |
$this->createImporterConfiguration('Content CSV', 'csv'); |
|
38 |
$this->setSettings('csv', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER)); |
|
39 |
$this->setPlugin('csv', 'FeedsFileFetcher'); |
|
40 |
$this->setPlugin('csv', 'FeedsCSVParser'); |
|
41 |
$this->setSettings('csv', 'FeedsNodeProcessor', array( |
|
42 |
'bundle' => 'article', |
|
43 |
'update_existing' => FEEDS_UPDATE_EXISTING, |
|
44 |
)); |
|
45 |
$this->addMappings('csv', array( |
|
46 |
0 => array( |
|
47 |
'source' => 'title', |
|
48 |
'target' => 'title', |
|
49 |
'unique' => TRUE, |
|
50 |
), |
|
51 |
)); |
|
52 |
|
|
53 |
// Create an article node that gets updated. |
|
54 |
$node = $this->drupalCreateNode(array( |
|
55 |
'type' => 'article', |
|
56 |
'title' => 'Lorem ipsum', |
|
57 |
)); |
|
58 |
|
|
59 |
// Import CSV file. |
|
60 |
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv'); |
|
61 |
$this->assertText('Created 1 node'); |
|
62 |
$this->assertText('Updated 1 node'); |
|
63 |
|
|
64 |
$expected_result = array( |
|
65 |
array( |
|
66 |
'importer_id' => 'csv', |
|
67 |
'title' => 'Lorem ipsum', |
|
68 |
'item_guid' => 1, |
|
69 |
'entity_id' => $node->nid, |
|
70 |
), |
|
71 |
array( |
|
72 |
'importer_id' => 'csv', |
|
73 |
'title' => 'Ut wisi enim ad minim veniam', |
|
74 |
'item_guid' => 2, |
|
75 |
'entity_id' => NULL, |
|
76 |
), |
|
77 |
); |
|
78 |
|
|
79 |
// Assert that the hook was invoked. The variable should have been set in |
|
80 |
// feeds_tests_feeds_prevalidate(). |
|
81 |
$this->assertEqual($expected_result, variable_get('feeds_tests_hook_feeds_prevalidate_results')); |
|
82 |
} |
|
83 |
|
|
19 | 84 |
/** |
20 | 85 |
* Tests the hook hook_config_defaults(). |
21 | 86 |
*/ |
Formats disponibles : Unified diff
Weekly update of contrib modules