1 |
ec2b0e7b
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Tests for hooks invoked by Feeds not related to mapping.
|
5 |
|
|
*/
|
6 |
|
|
class FeedsHooksTestCase extends FeedsWebTestCase {
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* {@inheritdoc}
|
10 |
|
|
*/
|
11 |
|
|
public static function getInfo() {
|
12 |
|
|
return array(
|
13 |
|
|
'name' => 'Hooks',
|
14 |
|
|
'description' => 'Tests for hooks invoked by Feeds not related to mapping.',
|
15 |
|
|
'group' => 'Feeds',
|
16 |
|
|
);
|
17 |
|
|
}
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* Tests the hook hook_config_defaults().
|
21 |
|
|
*/
|
22 |
|
|
public function testHookConfigDefaults() {
|
23 |
|
|
// Switch on hook implementations in the feeds_tests module.
|
24 |
|
|
variable_set('feeds_tests_hook_config_defaults', TRUE);
|
25 |
|
|
|
26 |
|
|
$this->createImporterConfiguration('Config defaults test', 'config_defaults_test');
|
27 |
|
|
|
28 |
|
|
// Load the importer and check the default value for
|
29 |
|
|
// 'feeds_tests_extra_setting'.
|
30 |
|
|
$importer = feeds_importer_load('config_defaults_test');
|
31 |
|
|
$importer_config = $importer->getConfig();
|
32 |
|
|
$this->assertFalse($importer_config['feeds_tests_extra_setting'], "Option 'Extra setting' is disabled.");
|
33 |
|
|
|
34 |
|
|
// Assert that other configurables do not have this setting.
|
35 |
|
|
$fetcher_config = $importer->fetcher->getConfig();
|
36 |
|
|
$parser_config = $importer->fetcher->getConfig();
|
37 |
|
|
$processor_config = $importer->fetcher->getConfig();
|
38 |
|
|
$this->assertFalse(isset($fetcher_config['feeds_tests_extra_setting']));
|
39 |
|
|
$this->assertFalse(isset($parser_config['feeds_tests_extra_setting']));
|
40 |
|
|
$this->assertFalse(isset($processor_config['feeds_tests_extra_setting']));
|
41 |
|
|
|
42 |
|
|
// Now change this setting.
|
43 |
|
|
$this->setSettings('config_defaults_test', NULL, array(
|
44 |
|
|
'feeds_tests_extra_setting' => TRUE,
|
45 |
|
|
));
|
46 |
|
|
|
47 |
|
|
// Reload the importer and assert that the configuration option changed.
|
48 |
|
|
drupal_static_reset();
|
49 |
|
|
$importer = feeds_importer_load('config_defaults_test');
|
50 |
|
|
$importer_config = $importer->getConfig();
|
51 |
|
|
$this->assertTrue($importer_config['feeds_tests_extra_setting'], "Option 'Extra setting' is enabled.");
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
/**
|
55 |
|
|
* Tests the hook hook_PLUGIN_TYPE_config_defaults().
|
56 |
|
|
*/
|
57 |
|
|
public function testHookPluginTypeConfigDefaults() {
|
58 |
|
|
// Switch on hook implementations in the feeds_tests module.
|
59 |
|
|
variable_set('feeds_tests_hook_config_defaults', TRUE);
|
60 |
|
|
|
61 |
|
|
$this->createImporterConfiguration('Config defaults test', 'config_defaults_test');
|
62 |
|
|
// Change parser plugin to CSV as the common syndication parser does not
|
63 |
|
|
// have a config form.
|
64 |
|
|
$this->setPlugin('config_defaults_test', 'FeedsCSVParser');
|
65 |
|
|
|
66 |
|
|
// Load the importer and check default values for each plugin.
|
67 |
|
|
$importer = feeds_importer_load('config_defaults_test');
|
68 |
|
|
$fetcher_config = $importer->fetcher->getConfig();
|
69 |
|
|
$parser_config = $importer->parser->getConfig();
|
70 |
|
|
$processor_config = $importer->processor->getConfig();
|
71 |
|
|
$this->assertFalse($fetcher_config['feeds_tests_fetcher_extra_setting'], "Option 'Extra setting' is disabled for the fetcher.");
|
72 |
|
|
$this->assertTrue($parser_config['feeds_tests_parser_extra_setting'], "Option 'Extra setting' is enabled for the parser.");
|
73 |
|
|
$this->assertEqual('', $processor_config['feeds_tests_processor_extra_setting'], "Setting 'Extra setting' is empty.");
|
74 |
|
|
|
75 |
|
|
// Assert that the setting for a particular plugin does not exists for other
|
76 |
|
|
// configurables.
|
77 |
|
|
$importer_config = $importer->getConfig();
|
78 |
|
|
$this->assertFalse(isset($importer_config['feeds_tests_fetcher_extra_setting']));
|
79 |
|
|
$this->assertFalse(isset($importer_config['feeds_tests_parser_extra_setting']));
|
80 |
|
|
$this->assertFalse(isset($importer_config['feeds_tests_processor_extra_setting']));
|
81 |
|
|
$this->assertFalse(isset($fetcher_config['feeds_tests_parser_extra_setting']));
|
82 |
|
|
$this->assertFalse(isset($fetcher_config['feeds_tests_processor_extra_setting']));
|
83 |
|
|
$this->assertFalse(isset($parser_config['feeds_tests_fetcher_extra_setting']));
|
84 |
|
|
$this->assertFalse(isset($parser_config['feeds_tests_processor_extra_setting']));
|
85 |
|
|
$this->assertFalse(isset($processor_config['feeds_tests_fetcher_extra_setting']));
|
86 |
|
|
$this->assertFalse(isset($processor_config['feeds_tests_parser_extra_setting']));
|
87 |
|
|
|
88 |
|
|
// Now change the settings for each plugin.
|
89 |
|
|
$this->setSettings('config_defaults_test', 'FeedsHTTPFetcher', array(
|
90 |
|
|
'feeds_tests_fetcher_extra_setting' => TRUE,
|
91 |
|
|
));
|
92 |
|
|
$this->setSettings('config_defaults_test', 'FeedsCSVParser', array(
|
93 |
|
|
'feeds_tests_parser_extra_setting' => FALSE,
|
94 |
|
|
));
|
95 |
|
|
$this->setSettings('config_defaults_test', 'FeedsNodeProcessor', array(
|
96 |
|
|
'feeds_tests_processor_extra_setting' => 'my setting',
|
97 |
|
|
));
|
98 |
|
|
|
99 |
|
|
// Reload the importer and assert that the configuration changed.
|
100 |
|
|
drupal_static_reset();
|
101 |
|
|
$importer = feeds_importer_load('config_defaults_test');
|
102 |
|
|
$fetcher_config = $importer->fetcher->getConfig();
|
103 |
|
|
$parser_config = $importer->parser->getConfig();
|
104 |
|
|
$processor_config = $importer->processor->getConfig();
|
105 |
|
|
$this->assertTrue($fetcher_config['feeds_tests_fetcher_extra_setting'], "Option 'Extra setting' is enabled for the fetcher.");
|
106 |
|
|
$this->assertFalse($parser_config['feeds_tests_parser_extra_setting'], "Option 'Extra setting' is disabled for the parser.");
|
107 |
|
|
$this->assertEqual('my setting', $processor_config['feeds_tests_processor_extra_setting'], "Setting 'Extra setting' is 'my setting'.");
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
} |