function RulesTestCase::testVariableAdding

Same name in other branches
  1. 7.x-2.x tests/rules.test \RulesTestCase::testVariableAdding()

Test adding a variable and optional parameters.

File

d7-tests/rules_test_case.test, line 319

Class

RulesTestCase

Code

function testVariableAdding() {
    $node = $this->drupalCreateNode();
    $rule = rule(array(
        'nid' => array(
            'type' => 'integer',
        ),
    ));
    $rule->condition('rules_test_condition_true')
        ->action('rules_action_load_node')
        ->action('rules_action_delete_node', array(
        'node:select' => 'node_loaded',
    ))
        ->execute($node->nid);
    $this->assertEqual(FALSE, node_load($node->nid), 'Variable added and skipped optional parameter.');
    RulesLog::logger()->checkLog();
    $vars = $rule->conditions()
        ->offsetGet(0)
        ->availableVariables();
    $this->assertEqual(!isset($vars['node_loaded']), 'Loaded variable is not available to conditions.');
    // Test adding a variable with a custom variable name.
    $node = $this->drupalCreateNode();
    $rule = rule(array(
        'nid' => array(
            'type' => 'integer',
        ),
    ));
    $rule->action('rules_action_load_node', array(
        'node_loaded:var' => 'node',
    ))
        ->action('rules_action_delete_node')
        ->execute($node->nid);
    $this->assertEqual(FALSE, node_load($node->nid), 'Variable with custom name added.');
    RulesLog::logger()->checkLog();
}