You are here

public function RulesTestCase::testActionSaving in Rules 7.2

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

Tests automatic saving of variables.

File

tests/rules.test, line 312
Rules tests.

Class

RulesTestCase
Rules test cases.

Code

public function testActionSaving() {

  // Test saving a parameter.
  $action = rules_action('rules_node_publish_action_save');
  $node = $this
    ->drupalCreateNode(array(
    'status' => 0,
    'type' => 'page',
  ));
  $action
    ->executeByArgs(array(
    'node' => $node,
  ));
  $this
    ->assertEqual($node->status, 1, 'Action executed correctly on node.');

  // Sync node_load cache with node_save.
  entity_get_controller('node')
    ->resetCache();
  $node = node_load($node->nid);
  $this
    ->assertEqual($node->status, 1, 'Node has been saved.');

  // Now test saving a provided variable, which is renamed and modified before
  // it is saved.
  $title = $this
    ->randomName();
  $rule = rule();
  $rule
    ->action('entity_create', array(
    'type' => 'node',
    'param_type' => 'article',
    'param_author:select' => 'site:current-user',
    'param_title' => $title,
    'entity_created:var' => 'node',
  ));
  $rule
    ->action('data_set', array(
    'data:select' => 'node:body',
    'value' => array(
      'value' => 'body',
    ),
  ));
  $rule
    ->integrityCheck();
  $rule
    ->execute();
  $node = $this
    ->drupalGetNodeByTitle($title);
  $this
    ->assertTrue(!empty($node) && $node->body[LANGUAGE_NONE][0]['value'] == 'body', 'Saved a provided variable');
  RulesLog::logger()
    ->checkLog();
}