Commit ef1fd488 authored by Dries's avatar Dries

- Patch #721086 by rfay, aspilicious, andypost: create tests for system...

- Patch #721086 by rfay, aspilicious, andypost: create tests for system actions, clean up token replacement, clean up triggers.
parent 7640e036
......@@ -1101,7 +1101,8 @@ protected function drupalLogout() {
// Make a request to the logout page, and redirect to the user page, the
// idea being if you were properly logged out you should be seeing a login
// screen.
$this->drupalGet('user/logout', array('query' => array('destination' => 'user')));
$this->drupalGet('user/logout');
$this->drupalGet('user');
$pass = $this->assertField('name', t('Username field found.'), t('Logout'));
$pass = $pass && $this->assertField('pass', t('Password field found.'), t('Logout'));
......@@ -2964,7 +2965,9 @@ protected function assertResponse($code, $message = '') {
}
/**
* Assert that the most recently sent e-mail message has a field with the given value.
* Asserts that the most recently sent e-mail message has the given value.
*
* The field in $name must have the content described in $value.
*
* @param $name
* Name of field or message property to assert. Examples: subject, body, id, ...
......@@ -2972,6 +2975,7 @@ protected function assertResponse($code, $message = '') {
* Value of the field to assert.
* @param $message
* Message to display.
*
* @return
* TRUE on pass, FALSE on fail.
*/
......@@ -2982,13 +2986,76 @@ protected function assertMail($name, $value = '', $message = '') {
}
/**
* Log verbose message in a text file.
* Asserts that the most recently sent e-mail message has the string in it.
*
* @param $field_name
* Name of field or message property to assert: subject, body, id, ...
* @param $string
* String to search for.
* @param $email_depth
* Number of emails to search for string, starting with most recent.
*
* @return
* TRUE on pass, FALSE on fail.
*/
protected function assertMailString($field_name, $string, $email_depth) {
$mails = $this->drupalGetMails();
$string_found = FALSE;
for ($i = sizeof($mails) -1; $i >= sizeof($mails) - $email_depth && $i >= 0; $i--) {
$mail = $mails[$i];
// Normalize whitespace, as we don't know what the mail system might have
// done. Any run of whitespace becomes a single space.
$normalized_mail = preg_replace('/\s+/', ' ', $mail[$field_name]);
$normalized_string = preg_replace('/\s+/', ' ', $string);
$string_found = (FALSE !== strpos($normalized_mail, $normalized_string));
if ($string_found) {
break;
}
}
return $this->assertTrue($string_found, t('Expected text found in @field of email message: "@expected".', array('@field' => $field_name, '@expected' => $string)));
}
/**
* Asserts that the most recently sent e-mail message has the pattern in it.
*
* @param $field_name
* Name of field or message property to assert: subject, body, id, ...
* @param $regex
* Pattern to search for.
*
* @return
* TRUE on pass, FALSE on fail.
*/
protected function assertMailPattern($field_name, $regex, $message) {
$mails = $this->drupalGetMails();
$mail = end($mails);
$regex_found = preg_match("/$regex/", $mail[$field_name]);
return $this->assertTrue($regex_found, t('Expected text found in @field of email message: "@expected".', array('@field' => $field_name, '@expected' => $regex)));
}
/**
* Outputs to verbose the most recent $count emails sent.
*
* @param $count
* Optional number of emails to output.
*/
protected function verboseEmail($count = 1) {
$mails = $this->drupalGetMails();
for ($i = sizeof($mails) -1; $i >= sizeof($mails) - $count && $i >= 0; $i--) {
$mail = $mails[$i];
$this->verbose(t('Email:') . '<pre>' . print_r($mail, TRUE) . '</pre>');
}
}
/**
* Logs verbose message in a text file.
*
* The a link to the vebose message will be placed in the test results via
* as a passing assertion with the text '[verbose message]'.
*
* @param $message
* The verbose message to be stored.
*
* @see simpletest_verbose()
*/
protected function verbose($message) {
......@@ -3001,7 +3068,7 @@ protected function verbose($message) {
}
/**
* Log verbose message in a text file.
* Logs verbose message in a text file.
*
* If verbose mode is enabled then page requests will be dumped to a file and
* presented on the test result screen. The messages will be placed in a file
......@@ -3013,8 +3080,10 @@ protected function verbose($message) {
* The original file directory, before it was changed for testing purposes.
* @param $test_class
* The active test case class.
*
* @return
* The ID of the message to be placed in related assertion messages.
*
* @see DrupalTestCase->originalFileDirectory
* @see DrupalWebTestCase->verbose()
*/
......
......@@ -2861,7 +2861,7 @@ function system_action_info() {
'type' => 'user',
'label' => t('Ban IP address of current user'),
'configurable' => FALSE,
'triggers' => array(),
'triggers' => array('any'),
),
'system_goto_action' => array(
'type' => 'system',
......
......@@ -35,7 +35,6 @@ function trigger_test_action_info() {
'comment_insert',
'comment_update',
'comment_delete',
'user_presave',
'user_insert',
'user_update',
'user_delete',
......
......@@ -145,9 +145,6 @@ function trigger_trigger_info() {
),
),
'user' => array(
'user_presave' => array(
'label' => t('When either creating a new user account or updating an existing'),
),
'user_insert' => array(
'label' => t('After creating a new user account'),
),
......@@ -488,17 +485,10 @@ function trigger_user_login(&$edit, $account, $category) {
* Implements hook_user_logout().
*/
function trigger_user_logout($account) {
$edit = NULL;
$edit = array();
_trigger_user('user_logout', $edit, $account);
}
/**
* Implements hook_user_presave().
*/
function trigger_user_presave(&$edit, $account, $category) {
_trigger_user('user_presave', $edit, $account, $category);
}
/**
* Implements hook_user_insert().
*/
......@@ -528,7 +518,8 @@ function trigger_user_cancel($edit, $account, $method) {
* Implements hook_user_delete().
*/
function trigger_user_delete($account) {
_trigger_user('user_delete', $edit, $account, $method);
$edit = array();
_trigger_user('user_delete', $edit, $account, NULL);
}
/**
......@@ -557,7 +548,7 @@ function _trigger_user($hook, &$edit, $account, $category = NULL) {
if (!isset($objects[$type])) {
$objects[$type] = _trigger_normalize_user_context($type, $account);
}
$context['account'] = $account;
$context['user'] = $account;
actions_do($aid, $objects[$type], $context);
}
else {
......
This diff is collapsed.
......@@ -3373,7 +3373,7 @@ function user_action_info() {
'label' => t('Block current user'),
'type' => 'user',
'configurable' => FALSE,
'triggers' => array(),
'triggers' => array('any'),
),
);
}
......@@ -3384,22 +3384,25 @@ function user_action_info() {
* @ingroup actions
*/
function user_block_user_action(&$entity, $context = array()) {
// First priority: If there is a $entity->uid, block that user.
// This is most likely a user object or the author if a node or comment.
if (isset($entity->uid)) {
$uid = $entity->uid;
}
elseif (isset($context['uid'])) {
$uid = $context['uid'];
}
// If neither of those are valid, then block the current user.
else {
global $user;
$uid = $user->uid;
$uid = $GLOBALS['user']->uid;
}
db_update('users')
->fields(array('status' => 0))
->condition('uid', $uid)
->execute();
drupal_session_destroy_uid($uid);
watchdog('action', 'Blocked user %name.', array('%name' => $user->name));
$account = user_load($uid);
watchdog('action', 'Blocked user %name.', array('%name' => $account->name));
}
/**
......
......@@ -81,7 +81,8 @@ function user_tokens($type, $tokens, array $data = array(), array $options = arr
switch ($name) {
// Basic user account information.
case 'uid':
$replacements[$original] = $account->uid;
// In the case of hook user_presave uid is not set yet.
$replacements[$original] = !empty($account->uid) ? $account->uid : t('not yet assigned');
break;
case 'name':
......@@ -94,20 +95,21 @@ function user_tokens($type, $tokens, array $data = array(), array $options = arr
break;
case 'url':
$replacements[$original] = url("user/$account->uid", $url_options);
$replacements[$original] = !empty($account->uid) ? url("user/$account->uid", $url_options) : t('not yet assigned');
break;
case 'edit-url':
$replacements[$original] = url("user/$account->uid/edit", $url_options);
$replacements[$original] = !empty($account->uid) ? url("user/$account->uid/edit", $url_options) : t('not yet assigned');
break;
// These tokens are default variations on the chained tokens handled below.
case 'last-login':
$replacements[$original] = format_date($account->login, 'medium', '', NULL, $language_code);
$replacements[$original] = !empty($account->login) ? format_date($account->login, 'medium', '', NULL, $language_code) : t('never');
break;
case 'created':
$replacements[$original] = format_date($account->created, 'medium', '', NULL, $language_code);
// In the case of user_presave the created date may not yet be set.
$replacements[$original] = !empty($account->created) ? format_date($account->created, 'medium', '', NULL, $language_code) : t('not yet created');
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment