function RulesTestCase::testRuleSets
Same name in other branches
- 7.x-2.x tests/rules.test \RulesTestCase::testRuleSets()
Tests making use of rule sets.
File
-
d7-tests/
rules_test_case.test, line 490
Class
Code
function testRuleSets() {
$set = rules_rule_set(array(
'node' => array(
'type' => 'node',
'label' => 'node',
),
));
$set->rule(rule()->action('drupal_message', array(
'message:select' => 'node:title',
)))
->rule(rule()->condition('rules_condition_content_is_published')
->action('drupal_message', array(
'message' => 'Node is published.',
)));
$set->integrityCheck()
->save('rules_test_set_1');
$node = $this->drupalCreateNode(array(
'title' => 'The title.',
'status' => 1,
));
// Execute.
rules_invoke_component('rules_test_set_1', $node);
$msg = drupal_get_messages();
$this->assertEqual($msg['status'][0], 'The title.', 'First rule evaluated.');
$this->assertEqual($msg['status'][1], 'Node is published.', 'Second rule evaluated.');
// Test a condition set.
$set = rules_or(array(
'node' => array(
'type' => 'node',
'label' => 'node',
),
));
$set->condition('data_is', array(
'data:select' => 'node:author:name',
'value' => 'notthename',
))
->condition('data_is', array(
'data:select' => 'node:nid',
'value' => $node->nid,
))
->integrityCheck()
->save('test', 'rules_test');
// Load and execute condition set.
$set = rules_config_load('test');
$this->assertTrue($set->execute($node), 'Set has been correctly evaluated.');
RulesLog::logger()->checkLog();
}