summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/simpletest/drupal_web_test_case.php26
-rw-r--r--modules/simpletest/simpletest.info1
-rw-r--r--modules/simpletest/tests/mail.test51
-rw-r--r--modules/system/mail.sending.inc62
-rw-r--r--modules/system/system.info1
5 files changed, 120 insertions, 21 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 822a92a15..41abb195c 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -1103,9 +1103,8 @@ class DrupalWebTestCase extends DrupalTestCase {
unset($GLOBALS['conf']['language_default']);
$language = language_default();
- // Make sure our drupal_mail_wrapper function is called instead of the
- // default mail handler.
- variable_set('smtp_library', drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php');
+ // Use the test mail class instead of the default mail handler class.
+ variable_set('mail_sending_system', array('default-system' => 'TestingMailSystem'));
// Use temporary files directory with the same prefix as the database.
$public_files_directory = $this->originalFileDirectory . '/' . $db_prefix;
@@ -1165,7 +1164,7 @@ class DrupalWebTestCase extends DrupalTestCase {
simpletest_log_read($this->testId, $db_prefix, get_class($this), TRUE);
$db_prefix = $db_prefix_temp;
- $emailCount = count(variable_get('simpletest_emails', array()));
+ $emailCount = count(variable_get('drupal_test_email_collector', array()));
if ($emailCount) {
$message = format_plural($emailCount, t('!count e-mail was sent during this test.'), t('!count e-mails were sent during this test.'), array('!count' => $emailCount));
$this->pass($message, t('E-mail'));
@@ -1918,7 +1917,7 @@ class DrupalWebTestCase extends DrupalTestCase {
* An array containing e-mail messages captured during the current test.
*/
protected function drupalGetMails($filter = array()) {
- $captured_emails = variable_get('simpletest_emails', array());
+ $captured_emails = variable_get('drupal_test_email_collector', array());
$filtered_emails = array();
foreach ($captured_emails as $message) {
@@ -2475,7 +2474,7 @@ class DrupalWebTestCase extends DrupalTestCase {
* TRUE on pass, FALSE on fail.
*/
protected function assertMail($name, $value = '', $message = '') {
- $captured_emails = variable_get('simpletest_emails', array());
+ $captured_emails = variable_get('drupal_test_email_collector', array());
$email = end($captured_emails);
return $this->assertTrue($email && isset($email[$name]) && $email[$name] == $value, $message, t('E-mail'));
}
@@ -2495,22 +2494,7 @@ class DrupalWebTestCase extends DrupalTestCase {
$this->pass(l(t('Verbose message'), $this->originalFileDirectory . '/simpletest/verbose/' . get_class($this) . '-' . $id . '.html', array('attributes' => array('target' => '_blank'))), 'Debug');
}
}
-}
-
-/**
- * Wrapper function to override the default mail handler function.
- *
- * @param $message
- * An e-mail message. See drupal_mail() for information on how $message is composed.
- * @return
- * Returns TRUE to indicate that the e-mail was successfully accepted for delivery.
- */
-function drupal_mail_wrapper($message) {
- $captured_emails = variable_get('simpletest_emails', array());
- $captured_emails[] = $message;
- variable_set('simpletest_emails', $captured_emails);
- return TRUE;
}
/**
diff --git a/modules/simpletest/simpletest.info b/modules/simpletest/simpletest.info
index 9d307eb5b..ad42f17c4 100644
--- a/modules/simpletest/simpletest.info
+++ b/modules/simpletest/simpletest.info
@@ -25,6 +25,7 @@ files[] = tests/form.test
files[] = tests/graph.test
files[] = tests/image.test
files[] = tests/lock.test
+files[] = tests/mail.test
files[] = tests/menu.test
files[] = tests/module.test
files[] = tests/registry.test
diff --git a/modules/simpletest/tests/mail.test b/modules/simpletest/tests/mail.test
new file mode 100644
index 000000000..641d606ff
--- /dev/null
+++ b/modules/simpletest/tests/mail.test
@@ -0,0 +1,51 @@
+<?php
+// $Id$
+
+/**
+ * Test the Drupal mailing system.
+ */
+class MailTestCase extends DrupalWebTestCase implements MailSystemInterface {
+ /**
+ * The most recent message that was sent through the test case.
+ *
+ * We take advantage here of the fact that static variables are shared among
+ * all instance of the same class.
+ */
+ private static $sent_message;
+
+ function getInfo() {
+ return array(
+ 'name' => 'Mail system',
+ 'description' => 'Performs tests on the pluggable mailing framework.',
+ 'group' => 'System',
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+
+ // Set MailTestCase (i.e. this class) as the SMTP library
+ variable_set('mail_sending_system', array('default-system' => 'MailTestCase'));
+ }
+
+ /**
+ * Assert that the pluggable mail system is functional.
+ */
+ function testPluggableFramework() {
+ global $language;
+
+ // Use MailTestCase for sending a message.
+ $message = drupal_mail('simpletest', 'mail_test', 'testing@drupal.org', $language);
+
+ // Assert whether the message was sent through the send function.
+ $this->assertEqual(self::$sent_message['to'], 'testing@drupal.org', t('Pluggable mail system is extendable.'));
+ }
+
+ /**
+ * Send function that is called through the mail system.
+ */
+ public function mail(array $message) {
+ self::$sent_message = $message;
+ }
+}
+
diff --git a/modules/system/mail.sending.inc b/modules/system/mail.sending.inc
new file mode 100644
index 000000000..6533de07d
--- /dev/null
+++ b/modules/system/mail.sending.inc
@@ -0,0 +1,62 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Drupal core implementations of the DrupalMailSendingInterface.
+ */
+
+/**
+ * The default Drupal mail sending library using PHP's mail function.
+ */
+class DefaultMailSystem implements MailSystemInterface {
+ /**
+ * Send an e-mail message, using Drupal variables and default settings.
+ * @see http://php.net/manual/en/function.mail.php the PHP function reference
+ * for mail().
+ * @see drupal_mail() for information on how $message is composed.
+ *
+ * @param $message
+ * Message array as described by DrupalMailSendingInterface.
+ * @return
+ * TRUE if the mail was successfully accepted, otherwise FALSE.
+ */
+ public function mail(array $message) {
+ $mimeheaders = array();
+ foreach ($message['headers'] as $name => $value) {
+ $mimeheaders[] = $name . ': ' . mime_header_encode($value);
+ }
+ return mail(
+ $message['to'],
+ mime_header_encode($message['subject']),
+ // Note: e-mail uses CRLF for line-endings, but PHP's API requires LF.
+ // They will appear correctly in the actual e-mail that is sent.
+ str_replace("\r", '', $message['body']),
+ // For headers, PHP's API suggests that we use CRLF normally,
+ // but some MTAs incorrectly replace LF with CRLF. See #234403.
+ join("\n", $mimeheaders)
+ );
+ }
+}
+
+/**
+ * A mail sending implementation that captures sent messages to a variable.
+ *
+ * This class is for running tests or for development.
+ */
+class TestingMailSystem implements MailSystemInterface {
+
+ /**
+ * Accept an e-mail message and store it in a variable.
+ *
+ * @param $message
+ * An e-mail message.
+ */
+ public function mail(array $message) {
+ $captured_emails = variable_get('drupal_test_email_collector', array());
+ $captured_emails[] = $message;
+ variable_set('drupal_test_email_collector', $captured_emails);
+ return TRUE;
+ }
+}
+
diff --git a/modules/system/system.info b/modules/system/system.info
index 8eb7db900..fa9a77d59 100644
--- a/modules/system/system.info
+++ b/modules/system/system.info
@@ -12,4 +12,5 @@ files[] = system.install
files[] = system.test
files[] = system.tar.inc
files[] = system.tokens.inc
+files[] = mail.sending.inc
required = TRUE