public function RulesTestCase::testReturningVariables in Rules 7.2
Same name and namespace in other branches
- 8.3 d7-tests/rules_test_case.test \RulesTestCase::testReturningVariables()
Tests returning provided variables.
File
- tests/
rules.test, line 752 - Rules tests.
Class
- RulesTestCase
- Rules test cases.
Code
public 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.');
}