function RulesTestCase::testInputEvaluators

Same name in other branches
  1. 8.x-3.x d7-tests/rules_test_case.test \RulesTestCase::testInputEvaluators()

Tests using input evaluators.

File

tests/rules.test, line 796

Class

RulesTestCase
Rules test cases.

Code

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