本文整理汇总了PHP中phpunit_util::is_redirecting_phpmailer方法的典型用法代码示例。如果您正苦于以下问题:PHP phpunit_util::is_redirecting_phpmailer方法的具体用法?PHP phpunit_util::is_redirecting_phpmailer怎么用?PHP phpunit_util::is_redirecting_phpmailer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpunit_util
的用法示例。
在下文中一共展示了phpunit_util::is_redirecting_phpmailer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PostSend
protected function PostSend()
{
// Now ask phpunit if it wants to catch this message.
if (PHPUNIT_TEST) {
if (!phpunit_util::is_redirecting_phpmailer()) {
debugging('Unit tests must not send real emails! Use $this->start_phpmailer_redirection()');
return true;
}
$mail = new stdClass();
$mail->header = $this->MIMEHeader;
$mail->body = $this->MIMEBody;
$mail->subject = $this->Subject;
$mail->from = $this->From;
$mail->to = $this->to[0][0];
phpunit_util::phpmailer_sent($mail);
return true;
} else {
return parent::PostSend();
}
}
示例2: test_message_attachment_send
public function test_message_attachment_send()
{
global $CFG;
$this->preventResetByRollback();
$this->resetAfterTest();
// Set config setting to allow attachments.
$CFG->allowattachments = true;
unset_config('noemailever');
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
// Create a test file.
$fs = get_file_storage();
$filerecord = array('contextid' => $context->id, 'component' => 'core', 'filearea' => 'unittest', 'itemid' => 99999, 'filepath' => '/', 'filename' => 'emailtest.txt');
$file = $fs->create_file_from_string($filerecord, 'Test content');
$message = new stdClass();
$message->component = 'moodle';
$message->name = 'instantmessage';
$message->userfrom = get_admin();
$message->userto = $user;
$message->subject = 'message subject 1';
$message->fullmessage = 'message body';
$message->fullmessageformat = FORMAT_MARKDOWN;
$message->fullmessagehtml = '<p>message body</p>';
$message->smallmessage = 'small message';
$message->attachment = $file;
$message->attachname = 'emailtest.txt';
$message->notification = 0;
// Make sure we are redirecting emails.
$sink = $this->redirectEmails();
$this->assertTrue(phpunit_util::is_redirecting_phpmailer());
message_send($message);
// Get the email that we just sent.
$emails = $sink->get_messages();
$email = reset($emails);
$this->assertTrue(strpos($email->body, 'Content-Disposition: attachment;') !== false);
$this->assertTrue(strpos($email->body, 'emailtest.txt') !== false);
// Check if the stored file still exists after remove the temporary attachment.
$storedfileexists = $fs->file_exists($filerecord['contextid'], $filerecord['component'], $filerecord['filearea'], $filerecord['itemid'], $filerecord['filepath'], $filerecord['filename']);
$this->assertTrue($storedfileexists);
}