function RulesTestCase::testVariableMapping

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

Test setting up a rule and mapping variables.

File

d7-tests/rules_test_case.test, line 175

Class

RulesTestCase
@file Rules 7.x tests.

Code

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