You are here

public function RulesTestCase::testVariableAdding in Rules 7.2

Same name and namespace in other branches
  1. 8.3 d7-tests/rules_test_case.test \RulesTestCase::testVariableAdding()

Tests adding a variable and optional parameters.

File

tests/rules.test, line 351
Rules tests.

Class

RulesTestCase
Rules test cases.

Code

public 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();
}