patched for email sending on each feedback creation https://drupal.org/node/353548#comment-7130746

This commit is contained in:
Bachir Soussi Chiadmi
2013-10-12 13:27:26 +02:00
parent ca63b9bbca
commit 235e57d8e9
4 changed files with 1231 additions and 4 deletions

75
tests/feedback.test Executable file → Normal file
View File

@@ -20,8 +20,7 @@ class FeedbackTestCase extends DrupalWebTestCase {
}
function setUp() {
// @todo Remove soft-dependency on Block.
parent::setUp(array('block', 'feedback'));
parent::setUp(array('feedback', 'trigger'));
$this->admin_user = $this->drupalCreateUser(array('access feedback form', 'view feedback messages', 'administer feedback'));
$this->web_user = $this->drupalCreateUser(array('access feedback form'));
@@ -49,7 +48,7 @@ class FeedbackTestCase extends DrupalWebTestCase {
$edit = array(
'feedback-messages[0][1]' => TRUE,
);
$this->drupalPost(NULL, $edit, t('Submit'));
$this->drupalPost(NULL, $edit, t('Update'));
$this->assertFieldByName('feedback-messages[1][1]', 1, t('Processed message found.'));
}
@@ -89,4 +88,72 @@ class FeedbackTestCase extends DrupalWebTestCase {
$this->assertNoLinkByHref('admin/reports/feedback/1/delete');
$this->assertNoRaw(check_plain($message), t('Message not found.'));
}
}
/**
* Test the feedback triggers and actions.
*/
function testFeedbackEmailAction() {
$test_user = $this->drupalCreateUser(array('administer actions', 'administer feedback', 'access feedback form'));
$this->drupalLogin($test_user);
$this->assignFeedbackEmailAction('feedback_insert', $test_user->mail);
// Insert a feedback entry.
$message = $this->randomString();
$edit = array(
'message' => $message,
);
$this->drupalPost('node', $edit, t('Send feedback'));
$this->assertFeedbackEmailTokenReplacement($test_user->mail, $message);
$this->assignFeedbackEmailAction('feedback_update', $test_user->mail);
// Update a feedback entry.
$fid = db_query("SELECT fid FROM {feedback} LIMIT 0,1")->fetchField();
$entry = feedback_load($fid);
feedback_save($entry);
$this->assertFeedbackEmailTokenReplacement($test_user->mail, $entry->message);
}
/**
* Assigns a system_send_email_action to the passed-in trigger.
*
* @param $trigger
* For example, 'user_login'
*/
function assignFeedbackEmailAction($trigger, $mail) {
$form_name = "trigger_{$trigger}_assign_form";
$form_html_id = strtr($form_name, '_', '-');
$edit = array(
'actions_label' => $trigger . "_feedback_send_email_action",
'recipients' => $mail,
'subject' => $this->randomName(),
'message' => '!message',
);
$hash = drupal_hash_base64('feedback_send_email_action');
$this->drupalPost("admin/config/system/actions/configure/$hash", $edit, t('Save'));
$this->assertText(t('The action has been successfully saved.'));
// Now we have to find out the action ID of what we created.
$aid = db_query('SELECT aid FROM {actions} WHERE callback = :callback AND label = :label', array(':callback' => 'feedback_send_email_action', ':label' => $edit['actions_label']))->fetchField();
$edit = array('aid' => drupal_hash_base64($aid));
$this->drupalPost('admin/structure/trigger/feedback', $edit, t('Assign'), array(), array(), $form_html_id);
}
/**
* Asserts correct token replacement for the given trigger and account.
*
* @param $account
* The user account which triggered the action.
* @param $email_depth
* Number of emails to scan, starting with most recent.
*/
function assertFeedbackEmailTokenReplacement($mail, $message, $email_depth = 1) {
$this->verboseEmail($email_depth);
$this->assertMailString('body', $message, $email_depth);
$this->assertMail('to', $mail, t('Mail sent to correct destination'));
}
}