You are here

public function RulesTestCase::testVariableMapping in Rules 7.2

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

Tests setting up a rule and mapping variables.

File

tests/rules.test, line 207
Rules tests.

Class

RulesTestCase
Rules test cases.

Code

public function testVariableMapping() {
  $rule = rule(array(
    'node' => array(
      'type' => 'node',
    ),
    'node_unchanged' => array(
      'type' => 'node',
    ),
  ));
  $rule
    ->condition(rules_condition('rules_condition_content_is_published')
    ->negate())
    ->condition('rules_condition_content_is_type', array(
    'type' => array(
      'page',
      'story',
    ),
  ))
    ->action('rules_node_publish_action', array(
    'node:select' => 'node_unchanged',
  ));
  $node1 = $this
    ->drupalCreateNode(array(
    'status' => 0,
    'type' => 'page',
  ));
  $node2 = $this
    ->drupalCreateNode(array(
    'status' => 0,
    'type' => 'page',
  ));
  $rule
    ->integrityCheck();
  $rule
    ->execute($node1, $node2);
  $this
    ->assertEqual($node2->status, 1, 'Action executed correctly on node2.');
  $this
    ->assertEqual($node1->status, 0, 'Action not executed on node1.');
  RulesLog::logger()
    ->checkLog();
}