You are here

function RulesTestCase::testInputEvaluators in Rules 8.3

Same name and namespace in other branches
  1. 7.2 tests/rules.test \RulesTestCase::testInputEvaluators()

Tests using input evaluators.

File

d7-tests/rules_test_case.test, line 755
Rules 7.x tests.

Class

RulesTestCase

Code

function testInputEvaluators() {
  $node = $this
    ->drupalCreateNode(array(
    'title' => '<b>The body & nothing.</b>',
    'type' => 'page',
  ));
  $rule = rule(array(
    'nid' => array(
      'type' => 'integer',
    ),
  ));
  $rule
    ->action('rules_action_load_node')
    ->action('drupal_message', array(
    'message' => 'Title: [node_loaded:title]',
  ))
    ->execute($node->nid);
  RulesLog::logger()
    ->checkLog();
  $msg = drupal_get_messages();
  $this
    ->assertEqual(array_pop($msg['status']), 'Title: ' . check_plain('<b>The body & nothing.</b>'), 'Token input evaluator applied.');

  // Test token replacements on a list of text values.
  $component = rules_action_set(array(
    'var' => array(
      'type' => 'list<text>',
      'label' => 'var',
    ),
  ), array(
    'var',
  ));
  $component
    ->save('rules_test_input');
  $action = rules_action('component_rules_test_input', array(
    'var' => array(
      'uid: [site:current-user:uid]',
    ),
  ));
  list($var) = $action
    ->execute();
  $uid = $GLOBALS['user']->uid;
  $this
    ->assertEqual(array(
    "uid: {$uid}",
  ), $var, 'Token replacements on a list of values applied.');
}