From b9fb97d68d561f03fcd1133d3147f856958097c9 Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Fri, 8 Nov 2013 16:34:35 +0200 Subject: [PATCH] Getters for 'yii\swiftmailer\Message' fixed. --- extensions/swiftmailer/Mailer.php | 2 +- extensions/swiftmailer/Message.php | 14 ++++----- tests/unit/extensions/swiftmailer/MessageTest.php | 36 +++++++++++++++++++++++ 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/extensions/swiftmailer/Mailer.php b/extensions/swiftmailer/Mailer.php index c00fad6..7c37a3f 100644 --- a/extensions/swiftmailer/Mailer.php +++ b/extensions/swiftmailer/Mailer.php @@ -108,7 +108,7 @@ class Mailer extends BaseMailer { $address = $message->getTo(); if (is_array($address)) { - $address = implode(', ', $address); + $address = implode(', ', array_keys($address)); } Yii::trace('Sending email "' . $message->getSubject() . '" to "' . $address . '"', __METHOD__); return $this->getSwiftMailer()->send($message->getSwiftMessage()) > 0; diff --git a/extensions/swiftmailer/Message.php b/extensions/swiftmailer/Message.php index 067b50e..bc9c14a 100644 --- a/extensions/swiftmailer/Message.php +++ b/extensions/swiftmailer/Message.php @@ -44,7 +44,7 @@ class Message extends BaseMessage */ public function getCharset() { - $this->getSwiftMessage()->getCharset(); + return $this->getSwiftMessage()->getCharset(); } /** @@ -61,7 +61,7 @@ class Message extends BaseMessage */ public function getFrom() { - $this->getSwiftMessage()->getFrom(); + return $this->getSwiftMessage()->getFrom(); } /** @@ -78,7 +78,7 @@ class Message extends BaseMessage */ public function getReplyTo() { - $this->getSwiftMessage()->getReplyTo(); + return $this->getSwiftMessage()->getReplyTo(); } /** @@ -95,7 +95,7 @@ class Message extends BaseMessage */ public function getTo() { - $this->getSwiftMessage()->getTo(); + return $this->getSwiftMessage()->getTo(); } /** @@ -112,7 +112,7 @@ class Message extends BaseMessage */ public function getCc() { - $this->getSwiftMessage()->getCc(); + return $this->getSwiftMessage()->getCc(); } /** @@ -129,7 +129,7 @@ class Message extends BaseMessage */ public function getBcc() { - $this->getSwiftMessage()->getBcc(); + return $this->getSwiftMessage()->getBcc(); } /** @@ -146,7 +146,7 @@ class Message extends BaseMessage */ public function getSubject() { - $this->getSwiftMessage()->getSubject(); + return $this->getSwiftMessage()->getSubject(); } /** diff --git a/tests/unit/extensions/swiftmailer/MessageTest.php b/tests/unit/extensions/swiftmailer/MessageTest.php index c46b43d..bbdb476 100644 --- a/tests/unit/extensions/swiftmailer/MessageTest.php +++ b/tests/unit/extensions/swiftmailer/MessageTest.php @@ -115,6 +115,42 @@ class MessageTest extends VendorTestCase /** * @depends testGetSwiftMessage */ + public function testSetGet() + { + $message = new Message(); + + $charset = 'utf-16'; + $message->setCharset($charset); + $this->assertEquals($charset, $message->getCharset(), 'Unable to set charset!'); + + $subject = 'Test Subject'; + $message->setSubject($subject); + $this->assertEquals($subject, $message->getSubject(), 'Unable to set subject!'); + + $from = 'from@somedomain.com'; + $message->setFrom($from); + $this->assertContains($from, array_keys($message->getFrom()), 'Unable to set from!'); + + $replyTo = 'reply-to@somedomain.com'; + $message->setReplyTo($replyTo); + $this->assertContains($replyTo, array_keys($message->getReplyTo()), 'Unable to set replyTo!'); + + $to = 'someuser@somedomain.com'; + $message->setTo($to); + $this->assertContains($to, array_keys($message->getTo()), 'Unable to set to!'); + + $cc = 'ccuser@somedomain.com'; + $message->setCc($cc); + $this->assertContains($cc, array_keys($message->getCc()), 'Unable to set cc!'); + + $bcc = 'bccuser@somedomain.com'; + $message->setBcc($bcc); + $this->assertContains($bcc, array_keys($message->getBcc()), 'Unable to set bcc!'); + } + + /** + * @depends testGetSwiftMessage + */ public function testSetupHeaders() { $charset = 'utf-16';