function RulesIntegrationTestCase::testSystemIntegration
Same name in other branches
- 7.x-2.x tests/rules.test \RulesIntegrationTestCase::testSystemIntegration()
Test site/system integration.
File
-
d7-tests/
rules_integration_test_case.test, line 645
Class
- RulesIntegrationTestCase
- Tests provided module integration.
Code
function testSystemIntegration() {
// Test using the 'site' variable.
$condition = rules_condition('data_is', array(
'data:select' => 'site:current-user:name',
'value' => $GLOBALS['user']->name,
));
$this->assertTrue($condition->execute(), 'Retrieved the current user\'s name.');
// Another test using a token replacement.
$condition = rules_condition('data_is', array(
'data:select' => 'site:current-user:name',
'value' => '[site:current-user:name]',
));
$this->assertTrue($condition->execute(), 'Replaced the token for the current user\'s name.');
// Test breadcrumbs and drupal set message.
$rule = rules_reaction_rule();
$rule->event('init')
->action('breadcrumb_set', array(
'titles' => array(
'foo',
),
'paths' => array(
'bar',
),
))
->action('drupal_message', array(
'message' => 'A message.',
));
$rule->save('test');
$this->drupalGet('node');
$this->assertLink('foo', 0, 'Breadcrumb has been set.');
$this->assertText('A message.', 'Drupal message has been shown.');
// Test the page redirect.
$node = $this->drupalCreateNode();
$rule = rules_reaction_rule();
$rule->event('node_view')
->action('redirect', array(
'url' => 'user',
));
$rule->save('test2');
$this->drupalGet('node/' . $node->nid);
$this->assertEqual($this->getUrl(), url('user', array(
'absolute' => TRUE,
)), 'Redirect has been issued.');
// Also test using a url including a fragment.
$actions = $rule->actions();
$actions[0]->settings['url'] = 'user#fragment';
$rule->save();
$this->drupalGet('node/' . $node->nid);
$this->assertEqual($this->getUrl(), url('user', array(
'absolute' => TRUE,
'fragment' => 'fragment',
)), 'Redirect has been issued.');
// Test sending mail.
$settings = array(
'to' => 'mail@example.com',
'subject' => 'subject',
'message' => 'hello.',
);
rules_action('mail', $settings)->execute();
$this->assertMail('to', 'mail@example.com', 'Mail has been sent.');
$this->assertMail('from', variable_get('site_mail', ini_get('sendmail_from')), 'Default from address has been used');
rules_action('mail', $settings + array(
'from' => 'sender@example.com',
))->execute();
$this->assertMail('from', 'sender@example.com', 'Specified from address has been used');
// Test sending mail to all users of a role. First make sure there is a
// custom role and a user for it.
$user = $this->drupalCreateUser(array(
'administer nodes',
));
$roles = $user->roles;
// Remove the authenticate role so we only use the new role created by
// drupalCreateUser().
unset($roles[DRUPAL_AUTHENTICATED_RID]);
rules_action('mail_to_users_of_role', $settings + array(
'roles' => array_keys($roles),
))->execute();
$this->assertMail('to', $user->mail, 'Mail to users of a role has been sent.');
// Test reacting on new log entries and make sure the log entry is usable.
$rule = rules_reaction_rule();
$rule->event('watchdog');
$rule->action('drupal_message', array(
'message:select' => 'log_entry:message',
));
$rule->integrityCheck()
->save('test_watchdog');
watchdog('php', 'test %message', array(
'%message' => 'message',
));
$msg = drupal_get_messages();
$this->assertEqual(array_pop($msg['status']), t('test %message', array(
'%message' => 'message',
)), 'Watchdog event occurred and log entry properties can be used.');
}