Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
90a5bcc6
Commit
90a5bcc6
authored
Nov 07, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored mail.
parent
ed0e44d2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
338 additions
and
199 deletions
+338
-199
Mailer.php
extensions/swiftmailer/Mailer.php
+23
-8
Message.php
extensions/swiftmailer/Message.php
+76
-13
BaseMailer.php
framework/yii/mail/BaseMailer.php
+73
-65
BaseMessage.php
framework/yii/mail/BaseMessage.php
+6
-6
MailerInterface.php
framework/yii/mail/MailerInterface.php
+23
-22
MessageInterface.php
framework/yii/mail/MessageInterface.php
+83
-28
MessageTest.php
tests/unit/extensions/swiftmailer/MessageTest.php
+36
-37
BaseMailerTest.php
tests/unit/framework/mail/BaseMailerTest.php
+9
-10
BaseMessageTest.php
tests/unit/framework/mail/BaseMessageTest.php
+9
-10
No files found.
extensions/swiftmailer/Mailer.php
View file @
90a5bcc6
...
@@ -12,10 +12,10 @@ use yii\base\InvalidConfigException;
...
@@ -12,10 +12,10 @@ use yii\base\InvalidConfigException;
use
yii\mail\BaseMailer
;
use
yii\mail\BaseMailer
;
/**
/**
* Mailer based on SwiftMailer library.
* Mailer implements a mailer based on SwiftMailer.
*
* To use Mailer, you should configure it in the application configuration like the following,
*
*
* By default PHP 'mail' function will be used as default email transport.
* You can setup different email transport via [[vendorMailer]] property:
* ~~~
* ~~~
* 'components' => array(
* 'components' => array(
* ...
* ...
...
@@ -34,9 +34,20 @@ use yii\mail\BaseMailer;
...
@@ -34,9 +34,20 @@ use yii\mail\BaseMailer;
* ),
* ),
* ~~~
* ~~~
*
*
* @see http://swiftmailer.org
* You may also skip the configuration of the [[transport]] property. In that case, the default
* PHP `mail()` function will be used to send emails.
*
* To send an email, you may use the following code:
*
* ~~~
* Yii::$app->mail->compose('contact/html', ['contactForm' => $form])
* ->setFrom('from@domain.com')
* ->setTo($form->email)
* ->setSubject($form->subject)
* ->send();
* ~~~
*
*
* @
method Message compose($view = null, array $params = []) creates new message optionally filling up its body via view rendering.
* @
see http://swiftmailer.org
*
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
* @since 2.0
...
@@ -69,7 +80,7 @@ class Mailer extends BaseMailer
...
@@ -69,7 +80,7 @@ class Mailer extends BaseMailer
/**
/**
* @param array|\Swift_Transport $transport
* @param array|\Swift_Transport $transport
* @throws
\yii\base\
InvalidConfigException on invalid argument.
* @throws InvalidConfigException on invalid argument.
*/
*/
public
function
setTransport
(
$transport
)
public
function
setTransport
(
$transport
)
{
{
...
@@ -95,8 +106,12 @@ class Mailer extends BaseMailer
...
@@ -95,8 +106,12 @@ class Mailer extends BaseMailer
*/
*/
public
function
send
(
$message
)
public
function
send
(
$message
)
{
{
Yii
::
trace
(
'Sending email message'
,
__METHOD__
);
$address
=
$message
->
getTo
();
return
(
$this
->
getSwiftMailer
()
->
send
(
$message
->
getSwiftMessage
())
>
0
);
if
(
is_array
(
$address
))
{
$address
=
implode
(
', '
,
$address
);
}
Yii
::
trace
(
'Sending email "'
.
$message
->
getSubject
()
.
'" to "'
.
$address
.
'"'
,
__METHOD__
);
return
$this
->
getSwiftMailer
()
->
send
(
$message
->
getSwiftMessage
())
>
0
;
}
}
/**
/**
...
...
extensions/swiftmailer/Message.php
View file @
90a5bcc6
...
@@ -10,10 +10,10 @@ namespace yii\swiftmailer;
...
@@ -10,10 +10,10 @@ namespace yii\swiftmailer;
use
yii\mail\BaseMessage
;
use
yii\mail\BaseMessage
;
/**
/**
*
Email message based on SwiftMailer library
.
*
Message implements a message class based on SwiftMailer
.
*
*
* @see http://swiftmailer.org/docs/messages.html
* @see http://swiftmailer.org/docs/messages.html
* @see
\yii\swiftmailer\
Mailer
* @see Mailer
*
*
* @method Mailer getMailer() returns mailer instance.
* @method Mailer getMailer() returns mailer instance.
* @property \Swift_Message $swiftMessage vendor message instance.
* @property \Swift_Message $swiftMessage vendor message instance.
...
@@ -42,7 +42,15 @@ class Message extends BaseMessage
...
@@ -42,7 +42,15 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
charset
(
$charset
)
public
function
getCharset
()
{
$this
->
getSwiftMessage
()
->
getCharset
();
}
/**
* @inheritdoc
*/
public
function
setCharset
(
$charset
)
{
{
$this
->
getSwiftMessage
()
->
setCharset
(
$charset
);
$this
->
getSwiftMessage
()
->
setCharset
(
$charset
);
return
$this
;
return
$this
;
...
@@ -51,17 +59,49 @@ class Message extends BaseMessage
...
@@ -51,17 +59,49 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
from
(
$from
)
public
function
getFrom
()
{
$this
->
getSwiftMessage
()
->
getFrom
();
}
/**
* @inheritdoc
*/
public
function
setFrom
(
$from
)
{
{
$this
->
getSwiftMessage
()
->
setFrom
(
$from
);
$this
->
getSwiftMessage
()
->
setFrom
(
$from
);
$this
->
getSwiftMessage
()
->
setReplyTo
(
$from
);
return
$this
;
return
$this
;
}
}
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
to
(
$to
)
public
function
getReplyTo
()
{
$this
->
getSwiftMessage
()
->
getReplyTo
();
}
/**
* @inheritdoc
*/
public
function
setReplyTo
(
$replyTo
)
{
$this
->
getSwiftMessage
()
->
setReplyTo
(
$replyTo
);
return
$this
;
}
/**
* @inheritdoc
*/
public
function
getTo
()
{
$this
->
getSwiftMessage
()
->
getTo
();
}
/**
* @inheritdoc
*/
public
function
setTo
(
$to
)
{
{
$this
->
getSwiftMessage
()
->
setTo
(
$to
);
$this
->
getSwiftMessage
()
->
setTo
(
$to
);
return
$this
;
return
$this
;
...
@@ -70,7 +110,15 @@ class Message extends BaseMessage
...
@@ -70,7 +110,15 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
cc
(
$cc
)
public
function
getCc
()
{
$this
->
getSwiftMessage
()
->
getCc
();
}
/**
* @inheritdoc
*/
public
function
setCc
(
$cc
)
{
{
$this
->
getSwiftMessage
()
->
setCc
(
$cc
);
$this
->
getSwiftMessage
()
->
setCc
(
$cc
);
return
$this
;
return
$this
;
...
@@ -79,7 +127,15 @@ class Message extends BaseMessage
...
@@ -79,7 +127,15 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
bcc
(
$bcc
)
public
function
getBcc
()
{
$this
->
getSwiftMessage
()
->
getBcc
();
}
/**
* @inheritdoc
*/
public
function
setBcc
(
$bcc
)
{
{
$this
->
getSwiftMessage
()
->
setBcc
(
$bcc
);
$this
->
getSwiftMessage
()
->
setBcc
(
$bcc
);
return
$this
;
return
$this
;
...
@@ -88,7 +144,15 @@ class Message extends BaseMessage
...
@@ -88,7 +144,15 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
subject
(
$subject
)
public
function
getSubject
()
{
$this
->
getSwiftMessage
()
->
getSubject
();
}
/**
* @inheritdoc
*/
public
function
setSubject
(
$subject
)
{
{
$this
->
getSwiftMessage
()
->
setSubject
(
$subject
);
$this
->
getSwiftMessage
()
->
setSubject
(
$subject
);
return
$this
;
return
$this
;
...
@@ -97,7 +161,7 @@ class Message extends BaseMessage
...
@@ -97,7 +161,7 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
t
extBody
(
$text
)
public
function
setT
extBody
(
$text
)
{
{
$this
->
setBody
(
$text
,
'text/plain'
);
$this
->
setBody
(
$text
,
'text/plain'
);
return
$this
;
return
$this
;
...
@@ -106,7 +170,7 @@ class Message extends BaseMessage
...
@@ -106,7 +170,7 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
h
tmlBody
(
$html
)
public
function
setH
tmlBody
(
$html
)
{
{
$this
->
setBody
(
$html
,
'text/html'
);
$this
->
setBody
(
$html
,
'text/html'
);
return
$this
;
return
$this
;
...
@@ -234,4 +298,4 @@ class Message extends BaseMessage
...
@@ -234,4 +298,4 @@ class Message extends BaseMessage
{
{
return
new
\Swift_Message
();
return
new
\Swift_Message
();
}
}
}
}
\ No newline at end of file
framework/yii/mail/BaseMailer.php
View file @
90a5bcc6
This diff is collapsed.
Click to expand it.
framework/yii/mail/BaseMessage.php
View file @
90a5bcc6
...
@@ -11,14 +11,14 @@ use yii\base\Object;
...
@@ -11,14 +11,14 @@ use yii\base\Object;
use
Yii
;
use
Yii
;
/**
/**
* BaseMessage
represent the single email message
.
* BaseMessage
serves as a base class that implements the [[send()]] method required by [[MessageInterface]]
.
*
It functionality depends on application component 'email',
*
*
which should provide the actual email sending functionality as well as
*
By default, [[send()]] will use the "mail" application component to send the current message.
*
default message configuration
.
*
The "mail" application component should be a mailer instance implementing [[MailerInterface]]
.
*
*
* @see BaseMailer
* @see BaseMailer
*
*
* @property
\yii\mail\
BaseMailer $mailer mailer component instance. This property is read-only.
* @property BaseMailer $mailer mailer component instance. This property is read-only.
*
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
* @since 2.0
...
@@ -26,7 +26,7 @@ use Yii;
...
@@ -26,7 +26,7 @@ use Yii;
abstract
class
BaseMessage
extends
Object
implements
MessageInterface
abstract
class
BaseMessage
extends
Object
implements
MessageInterface
{
{
/**
/**
* @return
\yii\mail\BaseMailer mailer component instance.
* @return
MailerInterface the mailer component
*/
*/
public
function
getMailer
()
public
function
getMailer
()
{
{
...
...
framework/yii/mail/MailerInterface.php
View file @
90a5bcc6
...
@@ -8,15 +8,16 @@
...
@@ -8,15 +8,16 @@
namespace
yii\mail
;
namespace
yii\mail
;
/**
/**
* MailerInterface is an interface, which any mailer should apply.
* MailerInterface is the interface that should be implemented by mailer classes.
* Mailer creates and sends messages. Also it allows composition of the message
* body via view rendering:
*
*
* ~~~php
* A mailer should mainly support creating and sending [[MessageInterface|mail messages]]. It should
* also support composition of the message body through the view rendering mechanism. For example,
*
* ~~~
* Yii::$app->mail->compose('contact/html', ['contactForm' => $form])
* Yii::$app->mail->compose('contact/html', ['contactForm' => $form])
* ->
f
rom('from@domain.com')
* ->
setF
rom('from@domain.com')
* ->
t
o($form->email)
* ->
setT
o($form->email)
* ->subject($form->subject)
* ->s
etS
ubject($form->subject)
* ->send();
* ->send();
* ~~~
* ~~~
*
*
...
@@ -28,17 +29,16 @@ namespace yii\mail;
...
@@ -28,17 +29,16 @@ namespace yii\mail;
interface
MailerInterface
interface
MailerInterface
{
{
/**
/**
* Creates new message optionally filling up its body via view rendering.
* Creates a new message instance and optionally composes its body content via view rendering.
* The view to be rendered can be specified in one of the following formats:
*
* - path alias (e.g. "@app/mails/contact/body");
* - relative path (e.g. "contact"): the actual view file will be resolved by [[\yii\base\ViewContextInterface]].
*
*
* @param string|array $view
view, which should be used to render message body
* @param string|array $view
the view to be used for rendering the message body. This can be:
*
*
* - if string - the view name or the path alias of the HTML body view file, in this case
* - a string, which represents the view name or path alias for rendering the HTML body of the email.
* text body will be composed automatically from html one.
* In this case, the text body will be generated by applying `strip_tags()` to the HTML body.
* - if array - list of views for each body type in format: ['html' => 'htmlView', 'text' => 'textView']
* - an array with 'html' and/or 'text' elements. The 'html' element refers to the view name or path alias
* for rendering the HTML body, while 'text' element is for rendering the text body. For example,
* `['html' => 'contact-html', 'text' => 'contact-text']`.
* - null, meaning the message instance will be returned without body content.
*
*
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return MessageInterface message instance.
* @return MessageInterface message instance.
...
@@ -47,17 +47,18 @@ interface MailerInterface
...
@@ -47,17 +47,18 @@ interface MailerInterface
/**
/**
* Sends the given email message.
* Sends the given email message.
* @param
object $message email message instance
* @param
MessageInterface $message email message instance to be sent
* @return boolean whether the message has been sent
.
* @return boolean whether the message has been sent
successfully
*/
*/
public
function
send
(
$message
);
public
function
send
(
$message
);
/**
/**
* Sends a couple of messages at once.
* Sends multiple messages at once.
* Note: some particular mailers may benefit from sending messages as batch,
*
* saving resources, for example on open/close connection operations.
* This method may be implemented by some mailers which support more efficient way of sending multiple messages in the same batch.
*
* @param array $messages list of email messages, which should be sent.
* @param array $messages list of email messages, which should be sent.
* @return integer number of
successful sends
.
* @return integer number of
messages that are successfully sent
.
*/
*/
public
function
sendMultiple
(
array
$messages
);
public
function
sendMultiple
(
array
$messages
);
}
}
framework/yii/mail/MessageInterface.php
View file @
90a5bcc6
...
@@ -8,17 +8,20 @@
...
@@ -8,17 +8,20 @@
namespace
yii\mail
;
namespace
yii\mail
;
/**
/**
* MessageInterface is an interface, which email message should apply.
* MessageInterface is the interface that should be implemented by mail message classes.
* Together with application component, which matches the [[MailerInterface]],
* it introduces following mail sending syntax:
*
*
* ~~~php
* A message represents the settings and content of an email, such as the sender, recipient,
* subject, body, etc.
*
* Messages are sent by a [[MailerInterface||mailer]], like the following,
*
* ~~~
* Yii::$app->mail->compose()
* Yii::$app->mail->compose()
* ->
f
rom('from@domain.com')
* ->
setF
rom('from@domain.com')
* ->
to('to@domain.com'
)
* ->
setTo($form->email
)
* ->s
ubject('Message Subject'
)
* ->s
etSubject($form->subject
)
* ->
t
extBody('Plain text content')
* ->
setT
extBody('Plain text content')
* ->
h
tmlBody('<b>HTML content</b>')
* ->
setH
tmlBody('<b>HTML content</b>')
* ->send();
* ->send();
* ~~~
* ~~~
*
*
...
@@ -30,72 +33,124 @@ namespace yii\mail;
...
@@ -30,72 +33,124 @@ namespace yii\mail;
interface
MessageInterface
interface
MessageInterface
{
{
/**
/**
* Set the character set of this message.
* Returns the character set of this message.
* @return string the character set of this message.
*/
public
function
getCharset
();
/**
* Sets the character set of this message.
* @param string $charset character set name.
* @param string $charset character set name.
* @return static self reference.
* @return static self reference.
*/
*/
public
function
charset
(
$charset
);
public
function
setCharset
(
$charset
);
/**
* Returns the message sender.
* @return string the sender
*/
public
function
getFrom
();
/**
/**
* Sets message sender.
* Sets
the
message sender.
* @param string|array $from sender email address.
* @param string|array $from sender email address.
* You may pass an array of addresses if this message is from multiple people.
* You may pass an array of addresses if this message is from multiple people.
* You may also specify sender name in addition to email address using format:
* You may also specify sender name in addition to email address using format:
*
[email => name]
.
*
`[email => name]`
.
* @return static self reference.
* @return static self reference.
*/
*/
public
function
f
rom
(
$from
);
public
function
setF
rom
(
$from
);
/**
/**
* Sets message receiver.
* Returns the message recipient(s).
* @return array the message recipients
*/
public
function
getTo
();
/**
* Sets the message recipient(s).
* @param string|array $to receiver email address.
* @param string|array $to receiver email address.
* You may pass an array of addresses if multiple recipients should receive this message.
* You may pass an array of addresses if multiple recipients should receive this message.
* You may also specify receiver name in addition to email address using format:
* You may also specify receiver name in addition to email address using format:
* [email => name].
* `[email => name]`.
* @return static self reference.
*/
public
function
setTo
(
$to
);
/**
* Returns the reply-to address of this message.
* @return string the reply-to address of this message.
*/
public
function
getReplyTo
();
/**
* Sets the reply-to address of this message.
* @param string|array $replyTo the reply-to address.
* You may pass an array of addresses if this message should be replied to multiple people.
* You may also specify reply-to name in addition to email address using format:
* `[email => name]`.
* @return static self reference.
* @return static self reference.
*/
*/
public
function
to
(
$to
);
public
function
setReplyTo
(
$replyTo
);
/**
* Returns the Cc (additional copy receiver) addresses of this message.
* @return array the Cc (additional copy receiver) addresses of this message.
*/
public
function
getCc
();
/**
/**
* Set the Cc (additional copy receiver) addresses of this message.
* Set
s
the Cc (additional copy receiver) addresses of this message.
* @param string|array $cc copy receiver email address.
* @param string|array $cc copy receiver email address.
* You may pass an array of addresses if multiple recipients should receive this message.
* You may pass an array of addresses if multiple recipients should receive this message.
* You may also specify receiver name in addition to email address using format:
* You may also specify receiver name in addition to email address using format:
*
[email => name]
.
*
`[email => name]`
.
* @return static self reference.
* @return static self reference.
*/
*/
public
function
cc
(
$cc
);
public
function
setCc
(
$cc
);
/**
* Returns the Bcc (hidden copy receiver) addresses of this message.
* @return array the Bcc (hidden copy receiver) addresses of this message.
*/
public
function
getBcc
();
/**
/**
* Set the Bcc (hidden copy receiver) addresses of this message.
* Set
s
the Bcc (hidden copy receiver) addresses of this message.
* @param string|array $bcc hidden copy receiver email address.
* @param string|array $bcc hidden copy receiver email address.
* You may pass an array of addresses if multiple recipients should receive this message.
* You may pass an array of addresses if multiple recipients should receive this message.
* You may also specify receiver name in addition to email address using format:
* You may also specify receiver name in addition to email address using format:
*
[email => name]
.
*
`[email => name]`
.
* @return static self reference.
* @return static self reference.
*/
*/
public
function
bcc
(
$bcc
);
public
function
setBcc
(
$bcc
);
/**
* Returns the message subject.
* @return string the message subject
*/
public
function
getSubject
();
/**
/**
* Sets message subject.
* Sets
the
message subject.
* @param string $subject message subject
* @param string $subject message subject
* @return static self reference.
* @return static self reference.
*/
*/
public
function
subject
(
$subject
);
public
function
s
etS
ubject
(
$subject
);
/**
/**
* Sets message plain text content.
* Sets message plain text content.
* @param string $text message plain text content.
* @param string $text message plain text content.
* @return static self reference.
* @return static self reference.
*/
*/
public
function
t
extBody
(
$text
);
public
function
setT
extBody
(
$text
);
/**
/**
* Sets message HTML content.
* Sets message HTML content.
* @param string $html message HTML content.
* @param string $html message HTML content.
* @return static self reference.
* @return static self reference.
*/
*/
public
function
h
tmlBody
(
$html
);
public
function
setH
tmlBody
(
$html
);
/**
/**
* Attaches existing file to the email message.
* Attaches existing file to the email message.
...
@@ -149,7 +204,7 @@ interface MessageInterface
...
@@ -149,7 +204,7 @@ interface MessageInterface
/**
/**
* Sends this email message.
* Sends this email message.
* @return boolean
success
.
* @return boolean
whether this message is sent successfully
.
*/
*/
public
function
send
();
public
function
send
();
...
...
tests/unit/extensions/swiftmailer/MessageTest.php
View file @
90a5bcc6
...
@@ -124,11 +124,11 @@ class MessageTest extends VendorTestCase
...
@@ -124,11 +124,11 @@ class MessageTest extends VendorTestCase
$bcc
=
'bccuser@somedomain.com'
;
$bcc
=
'bccuser@somedomain.com'
;
$messageString
=
$this
->
createTestMessage
()
$messageString
=
$this
->
createTestMessage
()
->
c
harset
(
$charset
)
->
setC
harset
(
$charset
)
->
subject
(
$subject
)
->
s
etS
ubject
(
$subject
)
->
t
o
(
$to
)
->
setT
o
(
$to
)
->
c
c
(
$cc
)
->
setC
c
(
$cc
)
->
b
cc
(
$bcc
)
->
setB
cc
(
$bcc
)
->
toString
();
->
toString
();
$this
->
assertContains
(
'charset='
.
$charset
,
$messageString
,
'Incorrect charset!'
);
$this
->
assertContains
(
'charset='
.
$charset
,
$messageString
,
'Incorrect charset!'
);
...
@@ -145,7 +145,7 @@ class MessageTest extends VendorTestCase
...
@@ -145,7 +145,7 @@ class MessageTest extends VendorTestCase
{
{
$from
=
'someuser@somedomain.com'
;
$from
=
'someuser@somedomain.com'
;
$messageString
=
$this
->
createTestMessage
()
$messageString
=
$this
->
createTestMessage
()
->
f
rom
(
$from
)
->
setF
rom
(
$from
)
->
toString
();
->
toString
();
$this
->
assertContains
(
'From: '
.
$from
,
$messageString
,
'Incorrect "From" header!'
);
$this
->
assertContains
(
'From: '
.
$from
,
$messageString
,
'Incorrect "From" header!'
);
$this
->
assertContains
(
'Reply-To: '
.
$from
,
$messageString
,
'Incorrect "Reply-To" header!'
);
$this
->
assertContains
(
'Reply-To: '
.
$from
,
$messageString
,
'Incorrect "Reply-To" header!'
);
...
@@ -157,10 +157,10 @@ class MessageTest extends VendorTestCase
...
@@ -157,10 +157,10 @@ class MessageTest extends VendorTestCase
public
function
testSend
()
public
function
testSend
()
{
{
$message
=
$this
->
createTestMessage
();
$message
=
$this
->
createTestMessage
();
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
subject
(
'Yii Swift Test'
);
$message
->
s
etS
ubject
(
'Yii Swift Test'
);
$message
->
t
extBody
(
'Yii Swift Test body'
);
$message
->
setT
extBody
(
'Yii Swift Test body'
);
$this
->
assertTrue
(
$message
->
send
());
$this
->
assertTrue
(
$message
->
send
());
}
}
...
@@ -171,10 +171,10 @@ class MessageTest extends VendorTestCase
...
@@ -171,10 +171,10 @@ class MessageTest extends VendorTestCase
{
{
$message
=
$this
->
createTestMessage
();
$message
=
$this
->
createTestMessage
();
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
subject
(
'Yii Swift Attach File Test'
);
$message
->
s
etS
ubject
(
'Yii Swift Attach File Test'
);
$message
->
t
extBody
(
'Yii Swift Attach File Test body'
);
$message
->
setT
extBody
(
'Yii Swift Attach File Test body'
);
$fileName
=
__FILE__
;
$fileName
=
__FILE__
;
$message
->
attach
(
$fileName
);
$message
->
attach
(
$fileName
);
...
@@ -192,10 +192,10 @@ class MessageTest extends VendorTestCase
...
@@ -192,10 +192,10 @@ class MessageTest extends VendorTestCase
{
{
$message
=
$this
->
createTestMessage
();
$message
=
$this
->
createTestMessage
();
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
subject
(
'Yii Swift Create Attachment Test'
);
$message
->
s
etS
ubject
(
'Yii Swift Create Attachment Test'
);
$message
->
t
extBody
(
'Yii Swift Create Attachment Test body'
);
$message
->
setT
extBody
(
'Yii Swift Create Attachment Test body'
);
$fileName
=
'test.txt'
;
$fileName
=
'test.txt'
;
$fileContent
=
'Test attachment content'
;
$fileContent
=
'Test attachment content'
;
$message
->
attachContent
(
$fileContent
,
[
'fileName'
=>
$fileName
]);
$message
->
attachContent
(
$fileContent
,
[
'fileName'
=>
$fileName
]);
...
@@ -218,10 +218,10 @@ class MessageTest extends VendorTestCase
...
@@ -218,10 +218,10 @@ class MessageTest extends VendorTestCase
$cid
=
$message
->
embed
(
$fileName
);
$cid
=
$message
->
embed
(
$fileName
);
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
subject
(
'Yii Swift Embed File Test'
);
$message
->
s
etS
ubject
(
'Yii Swift Embed File Test'
);
$message
->
h
tmlBody
(
'Embed image: <img src="'
.
$cid
.
'" alt="pic">'
);
$message
->
setH
tmlBody
(
'Embed image: <img src="'
.
$cid
.
'" alt="pic">'
);
$this
->
assertTrue
(
$message
->
send
());
$this
->
assertTrue
(
$message
->
send
());
...
@@ -244,10 +244,10 @@ class MessageTest extends VendorTestCase
...
@@ -244,10 +244,10 @@ class MessageTest extends VendorTestCase
$cid
=
$message
->
embedContent
(
$fileContent
,
[
'fileName'
=>
$fileName
,
'contentType'
=>
$contentType
]);
$cid
=
$message
->
embedContent
(
$fileContent
,
[
'fileName'
=>
$fileName
,
'contentType'
=>
$contentType
]);
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
subject
(
'Yii Swift Embed File Test'
);
$message
->
s
etS
ubject
(
'Yii Swift Embed File Test'
);
$message
->
h
tmlBody
(
'Embed image: <img src="'
.
$cid
.
'" alt="pic">'
);
$message
->
setH
tmlBody
(
'Embed image: <img src="'
.
$cid
.
'" alt="pic">'
);
$this
->
assertTrue
(
$message
->
send
());
$this
->
assertTrue
(
$message
->
send
());
...
@@ -264,11 +264,11 @@ class MessageTest extends VendorTestCase
...
@@ -264,11 +264,11 @@ class MessageTest extends VendorTestCase
{
{
$message
=
$this
->
createTestMessage
();
$message
=
$this
->
createTestMessage
();
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
subject
(
'Yii Swift Alternative Body Test'
);
$message
->
s
etS
ubject
(
'Yii Swift Alternative Body Test'
);
$message
->
h
tmlBody
(
'<b>Yii Swift</b> test HTML body'
);
$message
->
setH
tmlBody
(
'<b>Yii Swift</b> test HTML body'
);
$message
->
t
extBody
(
'Yii Swift test plain text body'
);
$message
->
setT
extBody
(
'Yii Swift test plain text body'
);
$this
->
assertTrue
(
$message
->
send
());
$this
->
assertTrue
(
$message
->
send
());
...
@@ -297,10 +297,10 @@ class MessageTest extends VendorTestCase
...
@@ -297,10 +297,10 @@ class MessageTest extends VendorTestCase
{
{
$message
=
$this
->
createTestMessage
();
$message
=
$this
->
createTestMessage
();
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
subject
(
'Yii Swift Alternative Body Test'
);
$message
->
s
etS
ubject
(
'Yii Swift Alternative Body Test'
);
$message
->
t
extBody
(
'Yii Swift test plain text body'
);
$message
->
setT
extBody
(
'Yii Swift test plain text body'
);
$serializedMessage
=
serialize
(
$message
);
$serializedMessage
=
serialize
(
$message
);
$this
->
assertNotEmpty
(
$serializedMessage
,
'Unable to serialize message!'
);
$this
->
assertNotEmpty
(
$serializedMessage
,
'Unable to serialize message!'
);
...
@@ -308,4 +308,4 @@ class MessageTest extends VendorTestCase
...
@@ -308,4 +308,4 @@ class MessageTest extends VendorTestCase
$unserializedMessaage
=
unserialize
(
$serializedMessage
);
$unserializedMessaage
=
unserialize
(
$serializedMessage
);
$this
->
assertEquals
(
$message
,
$unserializedMessaage
,
'Unable to unserialize message!'
);
$this
->
assertEquals
(
$message
,
$unserializedMessaage
,
'Unable to unserialize message!'
);
}
}
}
}
\ No newline at end of file
tests/unit/framework/mail/BaseMailerTest.php
View file @
90a5bcc6
...
@@ -240,49 +240,49 @@ class Message extends BaseMessage
...
@@ -240,49 +240,49 @@ class Message extends BaseMessage
public
$_textBody
;
public
$_textBody
;
public
$_htmlBody
;
public
$_htmlBody
;
public
function
c
harset
(
$charset
)
public
function
setC
harset
(
$charset
)
{
{
$this
->
_charset
=
$charset
;
$this
->
_charset
=
$charset
;
return
$this
;
return
$this
;
}
}
public
function
f
rom
(
$from
)
public
function
setF
rom
(
$from
)
{
{
$this
->
_from
=
$from
;
$this
->
_from
=
$from
;
return
$this
;
return
$this
;
}
}
public
function
t
o
(
$to
)
public
function
setT
o
(
$to
)
{
{
$this
->
_to
=
$to
;
$this
->
_to
=
$to
;
return
$this
;
return
$this
;
}
}
public
function
c
c
(
$cc
)
public
function
setC
c
(
$cc
)
{
{
$this
->
_cc
=
$cc
;
$this
->
_cc
=
$cc
;
return
$this
;
return
$this
;
}
}
public
function
b
cc
(
$bcc
)
public
function
setB
cc
(
$bcc
)
{
{
$this
->
_bcc
=
$bcc
;
$this
->
_bcc
=
$bcc
;
return
$this
;
return
$this
;
}
}
public
function
subject
(
$subject
)
public
function
s
etS
ubject
(
$subject
)
{
{
$this
->
_subject
=
$subject
;
$this
->
_subject
=
$subject
;
return
$this
;
return
$this
;
}
}
public
function
t
extBody
(
$text
)
public
function
setT
extBody
(
$text
)
{
{
$this
->
_textBody
=
$text
;
$this
->
_textBody
=
$text
;
return
$this
;
return
$this
;
}
}
public
function
h
tmlBody
(
$html
)
public
function
setH
tmlBody
(
$html
)
{
{
$this
->
_htmlBody
=
$html
;
$this
->
_htmlBody
=
$html
;
return
$this
;
return
$this
;
...
@@ -300,4 +300,4 @@ class Message extends BaseMessage
...
@@ -300,4 +300,4 @@ class Message extends BaseMessage
{
{
return
get_class
(
$this
);
return
get_class
(
$this
);
}
}
}
}
\ No newline at end of file
tests/unit/framework/mail/BaseMessageTest.php
View file @
90a5bcc6
...
@@ -85,23 +85,23 @@ class TestMessage extends BaseMessage
...
@@ -85,23 +85,23 @@ class TestMessage extends BaseMessage
public
$text
;
public
$text
;
public
$html
;
public
$html
;
public
function
c
harset
(
$charset
)
{}
public
function
setC
harset
(
$charset
)
{}
public
function
f
rom
(
$from
)
{}
public
function
setF
rom
(
$from
)
{}
public
function
t
o
(
$to
)
{}
public
function
setT
o
(
$to
)
{}
public
function
c
c
(
$cc
)
{}
public
function
setC
c
(
$cc
)
{}
public
function
b
cc
(
$bcc
)
{}
public
function
setB
cc
(
$bcc
)
{}
public
function
subject
(
$subject
)
{}
public
function
s
etS
ubject
(
$subject
)
{}
public
function
t
extBody
(
$text
)
{
public
function
setT
extBody
(
$text
)
{
$this
->
text
=
$text
;
$this
->
text
=
$text
;
}
}
public
function
h
tmlBody
(
$html
)
{
public
function
setH
tmlBody
(
$html
)
{
$this
->
html
=
$html
;
$this
->
html
=
$html
;
}
}
...
@@ -117,4 +117,4 @@ class TestMessage extends BaseMessage
...
@@ -117,4 +117,4 @@ class TestMessage extends BaseMessage
{
{
return
get_class
(
$this
);
return
get_class
(
$this
);
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment