function RulesIntegrationTestCase::testPHPIntegration
Same name in other branches
- 7.x-2.x tests/rules.test \RulesIntegrationTestCase::testPHPIntegration()
Test integration for the php module.
File
-
d7-tests/
rules_integration_test_case.test, line 542
Class
- RulesIntegrationTestCase
- Tests provided module integration.
Code
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.');
}