function RulesTestCase::testdependencies
Same name in other branches
- 7.x-2.x tests/rules.test \RulesTestCase::testDependencies()
Test handling dependencies.
File
-
d7-tests/
rules_test_case.test, line 62
Class
Code
function testdependencies() {
$action = rules_action('rules_node_publish_action');
$this->assertEqual($action->dependencies(), array(
'rules_test',
), 'Providing module is returned as dependency.');
$container = new RulesTestContainer();
$this->assertEqual($container->dependencies(), array(
'rules_test',
), 'Providing module for container plugin is returned as dependency.');
// Test handling unmet dependencies.
$rule = rules_config_load('rules_export_test');
$this->assertTrue(in_array('comment', $rule->dependencies) && !$rule->dirty, 'Dependencies have been imported.');
// Remove the required comment module and make sure the rule is dirty then.
module_disable(array(
'comment',
));
rules_clear_cache();
$rule = rules_config_load('rules_export_test');
$this->assertTrue($rule->dirty, 'Rule has been marked as dirty');
// Now try re-enabling.
module_enable(array(
'comment',
));
rules_clear_cache();
$rule = rules_config_load('rules_export_test');
$this->assertTrue(!$rule->dirty, 'Rule has been marked as not dirty again.');
// Test it with components.
module_enable(array(
'path',
));
$action_set = rules_action_set(array(
'node' => array(
'type' => 'node',
),
));
$action_set->action('node_path_alias');
$action_set->save('rules_test_alias');
$rule = rule(array(
'node' => array(
'type' => 'node',
),
));
$rule->action('component_rules_test_alias');
$rule->integrityCheck();
$rule->save('rules_test_rule');
$rule = rules_config_load('rules_test_rule');
$component = rules_config_load('rules_test_alias');
$this->assertTrue(in_array('path', $component->dependencies) && !$rule->dirty && !$component->dirty, 'Component has path module dependency.');
// Now disable path module and make sure both configs are marked as dirty.
module_disable(array(
'path',
));
rules_clear_cache();
$rule = rules_config_load('rules_test_rule');
$component = rules_config_load('rules_test_alias');
$this->assertTrue($component->dirty, 'Component has been marked as dirty');
$node = $this->drupalCreateNode();
$result = rules_invoke_component('rules_test_alias', $node);
$this->assertTrue($result === FALSE, 'Unable to execute a dirty component.');
// When the rule is evaluated, the broken component is detected and the
// rule should be marked as dirty too.
$rule->execute($node);
$this->assertTrue($rule->dirty, 'Rule has been marked as dirty');
module_enable(array(
'path',
));
rules_clear_cache();
// Trigger rebuilding the cache, so configs are checked again.
rules_get_cache();
$rule = rules_config_load('rules_test_rule');
$component = rules_config_load('rules_test_alias');
$this->assertTrue(!$component->dirty, 'Component has been marked as not dirty again.');
$this->assertTrue(!$rule->dirty, 'Rule has been marked as not dirty again.');
}