diff options
-rw-r--r-- | core/libraries/Sendmail.php | 25 | ||||
-rw-r--r-- | core/tests/Sendmail_Test.php | 30 |
2 files changed, 30 insertions, 25 deletions
diff --git a/core/libraries/Sendmail.php b/core/libraries/Sendmail.php index 40fbdddf..4e5134ba 100644 --- a/core/libraries/Sendmail.php +++ b/core/libraries/Sendmail.php @@ -26,11 +26,6 @@ class Sendmail_Core { protected $header_separator = "\r\n"; /** - * In test mode this gets the message that would have been set - */ - private $_send_text; - - /** * Return an instance of a Menu_Element * @chainable */ @@ -47,9 +42,6 @@ class Sendmail_Core { } public function __get($key) { - if (TEST_MODE && $key == "send_text") { - return $this->_send_text; - } return null; } @@ -91,16 +83,15 @@ class Sendmail_Core { // need to use a single \n. This can be set in config/sendmail.php $headers = implode($this->header_separator, $headers); $message = wordwrap($this->message, $this->line_length, "\n"); - - if (!TEST_MODE) { - if (!mail($to, $this->subject, $this->message, $headers)) { - Kohana::log("error", wordwrap("Sending mail failed:\nTo: $to\n $this->subject\n" . - "Headers: $headers\n $this->message")); - throw new Exception("@todo SEND MAIL FAILED"); - } - } else { - $this->_send_text = "To: $to\r\n{$headers}\r\nSubject: $this->subject\r\n\r\n$message"; + if ($this->mail($to, $this->subject, $message, $headers)) { + Kohana::log("error", wordwrap("Sending mail failed:\nTo: $to\n $this->subject\n" . + "Headers: $headers\n $this->message")); + throw new Exception("@todo SEND MAIL FAILED"); } return $this; } + + public function mail($to, $subject, $message, $headers) { + return mail($to, $subject, $message, $headers); + } } diff --git a/core/tests/Sendmail_Test.php b/core/tests/Sendmail_Test.php index d3800a26..4e813b16 100644 --- a/core/tests/Sendmail_Test.php +++ b/core/tests/Sendmail_Test.php @@ -30,7 +30,7 @@ class Sendmail_Test extends Unit_Test_Case { "Reply-To: public@gallery3.com\r\n" . "Subject: Test Email Unit test\r\n\r\n" . "The mail message body"; - $result = Sendmail::factory() + $result = Sendmail_For_Test::factory() ->to("receiver@someemail.com") /* * @todo figure out why this test fails so badly, when the following @@ -40,7 +40,8 @@ class Sendmail_Test extends Unit_Test_Case { ->from("from@gallery3.com") ->subject("Test Email Unit test") ->message("The mail message body") - ->send()->send_text; + ->send() + ->send_text; $this->assert_equal($expected, $result); } @@ -51,12 +52,13 @@ class Sendmail_Test extends Unit_Test_Case { "Reply-To: reply-to@gallery3.com\r\n" . "Subject: Test Email Unit test\r\n\r\n" . "The mail message body"; - $result = Sendmail::factory() + $result = Sendmail_For_Test::factory() ->to("receiver@someemail.com") ->subject("Test Email Unit test") ->reply_to("reply-to@gallery3.com") ->message("The mail message body") - ->send()->send_text; + ->send() + ->send_text; $this->assert_equal($expected, $result); } @@ -68,13 +70,14 @@ class Sendmail_Test extends Unit_Test_Case { "Content-type: text/html; charset=iso-8859-1\r\n" . "Subject: Test Email Unit test\r\n\r\n" . "<html><body><p>This is an html msg</p></body></html>"; - $result = Sendmail::factory() + $result = Sendmail_For_Test::factory() ->to("receiver@someemail.com") ->subject("Test Email Unit test") ->header("MIME-Version", "1.0") ->header("Content-type", "text/html; charset=iso-8859-1") ->message("<html><body><p>This is an html msg</p></body></html>") - ->send()->send_text; + ->send() + ->send_text; $this->assert_equal($expected, $result); } @@ -87,14 +90,25 @@ class Sendmail_Test extends Unit_Test_Case { "over forty characters If we get lucky we\n" . "might make it long enought to wrap a\n" . "couple of times."; - $result = Sendmail::factory() + $result = Sendmail_For_Test::factory() ->to("receiver@someemail.com") ->subject("Test Email Unit test") ->line_length(40) ->message("This is a long message that needs to go over forty characters " . "If we get lucky we might make it long enought to wrap a couple " . "of times.") - ->send()->send_text; + ->send() + ->send_text; $this->assert_equal($expected, $result); } +} + +class Sendmail_For_Test extends Sendmail { + static function factory() { + return new Sendmail_For_Test(); + } + + public function mail($to, $subject, $message, $headers) { + $this->send_text = "To: $to\r\n{$headers}\r\nSubject: $this->subject\r\n\r\n$message"; + } }
\ No newline at end of file |