function RulesIntegrationTestCase::testPHPIntegration

Same name in other branches
  1. 8.x-3.x d7-tests/rules_integration_test_case.test \RulesIntegrationTestCase::testPHPIntegration()

Tests integration for the php module.

File

tests/rules.test, line 1911

Class

RulesIntegrationTestCase
Tests provided module integration.

Code

public function testPHPIntegration() {
    $node = $this->drupalCreateNode(array(
        'title' => 'foo',
    ));
    $rule = rule(array(
        'var_name' => array(
            'type' => 'node',
        ),
    ));
    $rule->condition('php_eval', array(
        'code' => 'return TRUE;',
    ))
        ->action('php_eval', array(
        'code' => 'drupal_set_message("Executed-" . $var_name->title);',
    ))
        ->action('drupal_message', array(
        'message' => 'Title: <?php echo $var_name->title; ?> Token: [var_name:title]',
    ));
    $rule->execute($node);
    $rule->access();
    RulesLog::logger()->checkLog();
    $msg = drupal_get_messages();
    $this->assertEqual(array_pop($msg['status']), "Title: foo Token: foo", 'PHP input evaluation has been applied.');
    $this->assertEqual(array_pop($msg['status']), "Executed-foo", 'PHP code condition and action have been evaluated.');
    // Test PHP data processor.
    $rule = rule(array(
        'var_name' => array(
            'type' => 'node',
        ),
    ));
    $rule->action('drupal_message', array(
        'message:select' => 'var_name:title',
        'message:process' => array(
            'php' => array(
                'code' => 'return "Title: $value";',
            ),
        ),
    ));
    $rule->execute($node);
    $rule->access();
    RulesLog::logger()->checkLog();
    $msg = drupal_get_messages();
    $this->assertEqual(array_pop($msg['status']), "Title: foo", 'PHP data processor has been applied.');
}