From 9f20330d179cf759692537edb3e75fdd3adcbf7b Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 5 Aug 2015 22:12:13 -0400 Subject: [PATCH] Fix fatal error on null subject. Refs #7176 --- .../Controller/Component/EmailComponent.php | 3 ++- .../Component/EmailComponentTest.php | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Controller/Component/EmailComponent.php b/lib/Cake/Controller/Component/EmailComponent.php index 799baaca8..d89099f7e 100644 --- a/lib/Cake/Controller/Component/EmailComponent.php +++ b/lib/Cake/Controller/Component/EmailComponent.php @@ -309,7 +309,8 @@ class EmailComponent extends Component { $lib->readReceipt($this->_formatAddresses((array)$this->readReceipt)); } - $lib->subject($this->subject)->messageID($this->messageId); + $lib->subject($this->subject); + $lib->messageID($this->messageId); $lib->helpers($this->_controller->helpers); $headers = array('X-Mailer' => $this->xMailer); diff --git a/lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php b/lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php index 7be4282b3..aee72160d 100644 --- a/lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php @@ -339,6 +339,32 @@ HTMLBLOC; $this->assertRegExp('/http\:\/\/example\.com/', $result); } +/** + * test send with null properties + * + * @return void + */ + public function testSendNullProperties() { + $this->Controller->EmailTest->to = 'test@example.com'; + $this->Controller->EmailTest->from = 'test@example.com'; + $this->Controller->EmailTest->subject = null; + $this->Controller->EmailTest->replyTo = null; + $this->Controller->EmailTest->messageId = null; + $this->Controller->EmailTest->template = null; + + $this->Controller->EmailTest->delivery = 'DebugComp'; + $this->assertTrue($this->Controller->EmailTest->send(null)); + $result = DebugCompTransport::$lastEmail; + + $this->assertRegExp('/To: test@example.com\n/', $result); + $this->assertRegExp('/Subject: \n/', $result); + $this->assertRegExp('/From: test@example.com\n/', $result); + $this->assertRegExp('/Date: ' . preg_quote(static::$sentDate) . '\n/', $result); + $this->assertRegExp('/X-Mailer: CakePHP Email Component\n/', $result); + $this->assertRegExp('/Content-Type: text\/plain; charset=UTF-8\n/', $result); + $this->assertRegExp('/Content-Transfer-Encoding: 8bitMessage:\n/', $result); + } + /** * testSendDebug method *