159 lines
5.4 KiB
Plaintext
159 lines
5.4 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Tests for Feedback module.
|
|
*/
|
|
|
|
/**
|
|
* Test basic Feedback functionality.
|
|
*/
|
|
class FeedbackTestCase extends DrupalWebTestCase {
|
|
protected $profile = 'testing';
|
|
|
|
public static function getInfo() {
|
|
return array(
|
|
'name' => 'Feedback functionality',
|
|
'description' => 'Tests basic Feedback module functionality.',
|
|
'group' => 'Feedback',
|
|
);
|
|
}
|
|
|
|
function setUp() {
|
|
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'));
|
|
$this->drupalLogin($this->web_user);
|
|
}
|
|
|
|
/**
|
|
* Test a basic feedback message.
|
|
*/
|
|
function testFeedbackMessage() {
|
|
$message = $this->randomString();
|
|
$edit = array(
|
|
'message' => $message,
|
|
);
|
|
$this->drupalPost('node', $edit, t('Send feedback'));
|
|
|
|
// Verify the message was recorded.
|
|
$this->drupalLogin($this->admin_user);
|
|
$this->drupalGet('admin/reports/feedback');
|
|
$this->assertRaw(check_plain($message), t('Message found.'));
|
|
$this->assertText('node', t('Originating system path found.'));
|
|
$this->assertLinkByHref(url('node', array('absolute' => TRUE)), 0, t('Originating absolute URL found.'));
|
|
|
|
// Verify that we can process the message.
|
|
$edit = array(
|
|
'feedback-messages[0][1]' => TRUE,
|
|
);
|
|
$this->drupalPost(NULL, $edit, t('Update'));
|
|
$this->assertFieldByName('feedback-messages[1][1]', 1, t('Processed message found.'));
|
|
}
|
|
|
|
/**
|
|
* Test visibility settings.
|
|
*/
|
|
function testFeedbackVisibility() {
|
|
$this->drupalLogin($this->admin_user);
|
|
$this->drupalGet('user');
|
|
$this->assertRaw('<span class="feedback-link">' . t('Feedback') . '</span>', t('Feedback form shown.'));
|
|
$edit = array(
|
|
'feedback_excluded_paths' => 'user*',
|
|
);
|
|
$this->drupalPost('admin/config/user-interface/feedback', $edit, t('Save configuration'));
|
|
$this->drupalGet('user');
|
|
$this->assertNoRaw('<span class="feedback-link">' . t('Feedback') . '</span>', t('Feedback form not shown.'));
|
|
}
|
|
|
|
/**
|
|
* Test feedback deletion.
|
|
*/
|
|
function testFeedbackDelete() {
|
|
$this->drupalLogin($this->admin_user);
|
|
$message = $this->randomString();
|
|
$edit = array(
|
|
'message' => $message,
|
|
);
|
|
$this->drupalPost('node', $edit, t('Send feedback'));
|
|
|
|
// Verify a delete link is shown.
|
|
$this->drupalGet('admin/reports/feedback');
|
|
$this->assertLinkByHref('admin/reports/feedback/1/delete');
|
|
|
|
// Verify deletion.
|
|
$this->drupalPost('admin/reports/feedback/1/delete', array(), t('Delete'));
|
|
$this->assertRaw(t('The feedback entry was deleted'), t('Feedback deletion message shown.'));
|
|
$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'));
|
|
}
|
|
} |