123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?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'));
- }
- }
|