function RulesTestCase::testReturningVariables
Same name in other branches
- 7.x-2.x tests/rules.test \RulesTestCase::testReturningVariables()
Test returning provided variables.
File
-
d7-tests/
rules_test_case.test, line 712
Class
Code
function testReturningVariables() {
$node = $this->drupalCreateNode();
$action = rules_action('entity_fetch', array(
'type' => 'node',
'id' => $node->nid,
));
list($node2) = $action->execute();
$this->assertTrue($node2->nid == $node->nid, 'Action returned a variable.');
// Create a simple set that just passed through the given node.
$set = rules_rule_set(array(
'node' => array(
'type' => 'node',
),
), array(
'node',
));
$set->integrityCheck()
->save('rules_test_set_1');
$provides = $set->providesVariables();
$this->assertTrue($provides['node']['type'] == 'node', 'Rule set correctly passed through the node.');
list($node2) = $set->execute($node);
$this->assertTrue($node2->nid == $node->nid, 'Rule set returned a variable.');
// Create an action set returning a variable that is no parameter.
$set = rules_action_set(array(
'node' => array(
'type' => 'node',
'parameter' => FALSE,
),
), array(
'node',
));
$set->action('entity_fetch', array(
'type' => 'node',
'id' => $node->nid,
))
->action('data_set', array(
'data:select' => 'node',
'value:select' => 'entity_fetched',
));
$set->integrityCheck();
list($node3) = $set->execute();
$this->assertTrue($node3->nid == $node->nid, 'Action set returned a variable that has not been passed as parameter.');
// Test the same again with a variable holding a not wrapped data type.
$set = rules_action_set(array(
'number' => array(
'type' => 'integer',
'parameter' => FALSE,
),
), array(
'number',
));
$set->action('data_set', array(
'data:select' => 'number',
'value' => 3,
));
$set->integrityCheck();
list($number) = $set->execute();
$this->assertTrue($number == 3, 'Actions set returned a number.');
}