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
87af95f7
Commit
87af95f7
authored
Nov 05, 2013
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'yii\mail\MessageInterface' updated:
- setter methods renamed to have pure name - method 'createMessage' renamed to 'compose'
parent
c7e05478
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
160 additions
and
130 deletions
+160
-130
Mailer.php
extensions/swiftmailer/yii/swiftmailer/Mailer.php
+1
-1
Message.php
extensions/swiftmailer/yii/swiftmailer/Message.php
+7
-47
BaseMailer.php
framework/yii/mail/BaseMailer.php
+33
-4
BaseMessage.php
framework/yii/mail/BaseMessage.php
+3
-9
MailerInterface.php
framework/yii/mail/MailerInterface.php
+1
-1
MessageInterface.php
framework/yii/mail/MessageInterface.php
+11
-11
MessageTest.php
tests/unit/extensions/swiftmailer/MessageTest.php
+39
-33
BaseMailerTest.php
tests/unit/framework/mail/BaseMailerTest.php
+56
-15
BaseMessageTest.php
tests/unit/framework/mail/BaseMessageTest.php
+9
-9
No files found.
extensions/swiftmailer/yii/swiftmailer/Mailer.php
View file @
87af95f7
...
@@ -36,7 +36,7 @@ use Yii;
...
@@ -36,7 +36,7 @@ use Yii;
*
*
* @see http://swiftmailer.org
* @see http://swiftmailer.org
*
*
* @method Message c
reateMessag
e(array $config = []) creates new message instance from given configuration.
* @method Message c
ompos
e(array $config = []) creates new message instance from given configuration.
*
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
* @since 2.0
...
...
extensions/swiftmailer/yii/swiftmailer/Message.php
View file @
87af95f7
...
@@ -59,7 +59,7 @@ class Message extends BaseMessage
...
@@ -59,7 +59,7 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
setF
rom
(
$from
)
public
function
f
rom
(
$from
)
{
{
$this
->
getSwiftMessage
()
->
setFrom
(
$from
);
$this
->
getSwiftMessage
()
->
setFrom
(
$from
);
$this
->
getSwiftMessage
()
->
setReplyTo
(
$from
);
$this
->
getSwiftMessage
()
->
setReplyTo
(
$from
);
...
@@ -67,85 +67,45 @@ class Message extends BaseMessage
...
@@ -67,85 +67,45 @@ class Message extends BaseMessage
}
}
/**
/**
* @return string from address of this message.
*/
public
function
getFrom
()
{
return
$this
->
getSwiftMessage
()
->
getFrom
();
}
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
setT
o
(
$to
)
public
function
t
o
(
$to
)
{
{
$this
->
getSwiftMessage
()
->
setTo
(
$to
);
$this
->
getSwiftMessage
()
->
setTo
(
$to
);
return
$this
;
return
$this
;
}
}
/**
/**
* @return array To addresses of this message.
*/
public
function
getTo
()
{
return
$this
->
getSwiftMessage
()
->
getTo
();
}
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
setC
c
(
$cc
)
public
function
c
c
(
$cc
)
{
{
$this
->
getSwiftMessage
()
->
setCc
(
$cc
);
$this
->
getSwiftMessage
()
->
setCc
(
$cc
);
return
$this
;
return
$this
;
}
}
/**
/**
* @return array Cc address of this message.
*/
public
function
getCc
()
{
return
$this
->
getSwiftMessage
()
->
getCc
();
}
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
setB
cc
(
$bcc
)
public
function
b
cc
(
$bcc
)
{
{
$this
->
getSwiftMessage
()
->
setBcc
(
$bcc
);
$this
->
getSwiftMessage
()
->
setBcc
(
$bcc
);
return
$this
;
return
$this
;
}
}
/**
/**
* @return array Bcc addresses of this message.
*/
public
function
getBcc
()
{
return
$this
->
getSwiftMessage
()
->
getBcc
();
}
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
s
etS
ubject
(
$subject
)
public
function
subject
(
$subject
)
{
{
$this
->
getSwiftMessage
()
->
setSubject
(
$subject
);
$this
->
getSwiftMessage
()
->
setSubject
(
$subject
);
return
$this
;
return
$this
;
}
}
/**
/**
* @return string the subject of this message.
*/
public
function
getSubject
()
{
return
$this
->
getSwiftMessage
()
->
getSubject
();
}
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
setT
ext
(
$text
)
public
function
t
ext
(
$text
)
{
{
$this
->
setBody
(
$text
,
'text/plain'
);
$this
->
setBody
(
$text
,
'text/plain'
);
return
$this
;
return
$this
;
...
@@ -154,7 +114,7 @@ class Message extends BaseMessage
...
@@ -154,7 +114,7 @@ class Message extends BaseMessage
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
setH
tml
(
$html
)
public
function
h
tml
(
$html
)
{
{
$this
->
setBody
(
$html
,
'text/html'
);
$this
->
setBody
(
$html
,
'text/html'
);
return
$this
;
return
$this
;
...
...
framework/yii/mail/BaseMailer.php
View file @
87af95f7
...
@@ -45,10 +45,18 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
...
@@ -45,10 +45,18 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
/**
/**
* @var array configuration, which should be applied by default to any new created
* @var array configuration, which should be applied by default to any new created
* email message instance.
* email message instance.
* In addition to normal [[Yii::createObject()]] behavior extra config keys are available:
* - 'from' invokes [[MessageInterface::from()]]
* - 'to' invokes [[MessageInterface::to()]]
* - 'cc' invokes [[MessageInterface::cc()]]
* - 'bcc' invokes [[MessageInterface::bcc()]]
* - 'subject' invokes [[MessageInterface::subject()]]
* - 'text' invokes [[MessageInterface::text()]]
* - 'html' invokes [[MessageInterface::html()]]
* For example:
* For example:
* ~~~
* ~~~
* array(
* array(
* '
encoding
' => 'UTF-8',
* '
charset
' => 'UTF-8',
* 'from' => 'noreply@mydomain.com',
* 'from' => 'noreply@mydomain.com',
* 'bcc' => 'email.test@mydomain.com',
* 'bcc' => 'email.test@mydomain.com',
* )
* )
...
@@ -100,16 +108,37 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
...
@@ -100,16 +108,37 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
* Creates new message instance from given configuration.
* Creates new message instance from given configuration.
* Message configuration will be merged with [[messageConfig]].
* Message configuration will be merged with [[messageConfig]].
* If 'class' parameter is omitted [[messageClass]], will be used.
* If 'class' parameter is omitted [[messageClass]], will be used.
* @param array $config message configuration.
* @param array $config message configuration. See [[messageConfig]]
* for the configuration format details.
* @return MessageInterface message instance.
* @return MessageInterface message instance.
*/
*/
public
function
c
reateMessag
e
(
array
$config
=
[])
public
function
c
ompos
e
(
array
$config
=
[])
{
{
$config
=
array_merge
(
$this
->
messageConfig
,
$config
);
$config
=
array_merge
(
$this
->
messageConfig
,
$config
);
if
(
!
array_key_exists
(
'class'
,
$config
))
{
if
(
!
array_key_exists
(
'class'
,
$config
))
{
$config
[
'class'
]
=
$this
->
messageClass
;
$config
[
'class'
]
=
$this
->
messageClass
;
}
}
return
Yii
::
createObject
(
$config
);
$configMethodNames
=
[
'from'
,
'to'
,
'cc'
,
'bcc'
,
'subject'
,
'text'
,
'html'
,
];
$methodBasedConfig
=
[];
foreach
(
$config
as
$name
=>
$value
)
{
if
(
in_array
(
$name
,
$configMethodNames
,
true
))
{
$methodBasedConfig
[
$name
]
=
$value
;
unset
(
$config
[
$name
]);
}
}
$message
=
Yii
::
createObject
(
$config
);
foreach
(
$methodBasedConfig
as
$name
=>
$value
)
{
$message
->
$name
(
$value
);
}
return
$message
;
}
}
/**
/**
...
...
framework/yii/mail/BaseMessage.php
View file @
87af95f7
...
@@ -22,13 +22,6 @@ use Yii;
...
@@ -22,13 +22,6 @@ use Yii;
*
*
* @property \yii\mail\BaseMailer $mailer mailer component instance. This property is read-only.
* @property \yii\mail\BaseMailer $mailer mailer component instance. This property is read-only.
* @property string $charset the character set of this message.
* @property string $charset the character set of this message.
* @property string|array $from sender email address.
* @property string|array $to receiver email address.
* @property string|array $cc copy receiver email address.
* @property string|array $bcc hidden copy receiver email address.
* @property string $subject message subject.
* @property string $text message plain text content.
* @property string $html message HTML content.
*
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
* @since 2.0
...
@@ -56,7 +49,7 @@ abstract class BaseMessage extends Object implements MessageInterface
...
@@ -56,7 +49,7 @@ abstract class BaseMessage extends Object implements MessageInterface
*/
*/
public
function
renderHtml
(
$view
,
$params
=
[])
public
function
renderHtml
(
$view
,
$params
=
[])
{
{
$this
->
setH
tml
(
$this
->
getMailer
()
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
htmlLayout
));
$this
->
h
tml
(
$this
->
getMailer
()
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
htmlLayout
));
return
$this
;
return
$this
;
}
}
...
@@ -65,7 +58,7 @@ abstract class BaseMessage extends Object implements MessageInterface
...
@@ -65,7 +58,7 @@ abstract class BaseMessage extends Object implements MessageInterface
*/
*/
public
function
renderText
(
$view
,
$params
=
[])
public
function
renderText
(
$view
,
$params
=
[])
{
{
$this
->
setT
ext
(
$this
->
getMailer
()
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
textLayout
));
$this
->
t
ext
(
$this
->
getMailer
()
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
textLayout
));
return
$this
;
return
$this
;
}
}
}
}
\ No newline at end of file
framework/yii/mail/MailerInterface.php
View file @
87af95f7
...
@@ -22,7 +22,7 @@ interface MailerInterface
...
@@ -22,7 +22,7 @@ interface MailerInterface
* @param array $config message configuration.
* @param array $config message configuration.
* @return MessageInterface message instance.
* @return MessageInterface message instance.
*/
*/
public
function
c
reateMessag
e
(
array
$config
=
[]);
public
function
c
ompos
e
(
array
$config
=
[]);
/**
/**
* Sends the given email message.
* Sends the given email message.
...
...
framework/yii/mail/MessageInterface.php
View file @
87af95f7
...
@@ -12,10 +12,10 @@ namespace yii\mail;
...
@@ -12,10 +12,10 @@ namespace yii\mail;
* Together with application component, which matches the [[MailerInterface]],
* Together with application component, which matches the [[MailerInterface]],
* it introduces following mail sending syntax:
* it introduces following mail sending syntax:
* ~~~php
* ~~~php
* Yii::$app->mail->c
reateMessag
e()
* Yii::$app->mail->c
ompos
e()
* ->
setF
rom('from@domain.com')
* ->
f
rom('from@domain.com')
* ->
setT
o('to@domain.com')
* ->
t
o('to@domain.com')
* ->s
etS
ubject('Message Subject')
* ->subject('Message Subject')
* ->renderText('text/view')
* ->renderText('text/view')
* ->renderHtml('html/view')
* ->renderHtml('html/view')
* ->send();
* ->send();
...
@@ -43,7 +43,7 @@ interface MessageInterface
...
@@ -43,7 +43,7 @@ interface MessageInterface
* [email => name].
* [email => name].
* @return static self reference.
* @return static self reference.
*/
*/
public
function
setF
rom
(
$from
);
public
function
f
rom
(
$from
);
/**
/**
* Sets message receiver.
* Sets message receiver.
...
@@ -53,7 +53,7 @@ interface MessageInterface
...
@@ -53,7 +53,7 @@ interface MessageInterface
* [email => name].
* [email => name].
* @return static self reference.
* @return static self reference.
*/
*/
public
function
setT
o
(
$to
);
public
function
t
o
(
$to
);
/**
/**
* Set the Cc (additional copy receiver) addresses of this message.
* Set the Cc (additional copy receiver) addresses of this message.
...
@@ -63,7 +63,7 @@ interface MessageInterface
...
@@ -63,7 +63,7 @@ interface MessageInterface
* [email => name].
* [email => name].
* @return static self reference.
* @return static self reference.
*/
*/
public
function
setC
c
(
$cc
);
public
function
c
c
(
$cc
);
/**
/**
* Set the Bcc (hidden copy receiver) addresses of this message.
* Set the Bcc (hidden copy receiver) addresses of this message.
...
@@ -73,28 +73,28 @@ interface MessageInterface
...
@@ -73,28 +73,28 @@ interface MessageInterface
* [email => name].
* [email => name].
* @return static self reference.
* @return static self reference.
*/
*/
public
function
setB
cc
(
$bcc
);
public
function
b
cc
(
$bcc
);
/**
/**
* Sets message subject.
* Sets message subject.
* @param string $subject message subject
* @param string $subject message subject
* @return static self reference.
* @return static self reference.
*/
*/
public
function
s
etS
ubject
(
$subject
);
public
function
subject
(
$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
setT
ext
(
$text
);
public
function
t
ext
(
$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
setH
tml
(
$html
);
public
function
h
tml
(
$html
);
/**
/**
* Attach specified content as file for the email message.
* Attach specified content as file for the email message.
...
...
tests/unit/extensions/swiftmailer/MessageTest.php
View file @
87af95f7
...
@@ -63,7 +63,7 @@ class MessageTest extends VendorTestCase
...
@@ -63,7 +63,7 @@ class MessageTest extends VendorTestCase
*/
*/
protected
function
createTestMessage
()
protected
function
createTestMessage
()
{
{
return
Yii
::
$app
->
getComponent
(
'mail'
)
->
c
reateMessag
e
();
return
Yii
::
$app
->
getComponent
(
'mail'
)
->
c
ompos
e
();
}
}
/**
/**
...
@@ -120,16 +120,22 @@ class MessageTest extends VendorTestCase
...
@@ -120,16 +120,22 @@ class MessageTest extends VendorTestCase
$charset
=
'utf-16'
;
$charset
=
'utf-16'
;
$subject
=
'Test Subject'
;
$subject
=
'Test Subject'
;
$to
=
'someuser@somedomain.com'
;
$to
=
'someuser@somedomain.com'
;
$cc
=
'ccuser@somedomain.com'
;
$bcc
=
'bccuser@somedomain.com'
;
$messageString
=
$this
->
createTestMessage
()
$messageString
=
$this
->
createTestMessage
()
->
setCharset
(
$charset
)
->
setCharset
(
$charset
)
->
setSubject
(
$subject
)
->
subject
(
$subject
)
->
setTo
(
$to
)
->
to
(
$to
)
->
cc
(
$cc
)
->
bcc
(
$bcc
)
->
__toString
();
->
__toString
();
$this
->
assertContains
(
'charset='
.
$charset
,
$messageString
,
'Incorrect charset!'
);
$this
->
assertContains
(
'charset='
.
$charset
,
$messageString
,
'Incorrect charset!'
);
$this
->
assertContains
(
'Subject: '
.
$subject
,
$messageString
,
'Incorrect "Subject" header!'
);
$this
->
assertContains
(
'Subject: '
.
$subject
,
$messageString
,
'Incorrect "Subject" header!'
);
$this
->
assertContains
(
'To: '
.
$to
,
$messageString
,
'Incorrect "To" header!'
);
$this
->
assertContains
(
'To: '
.
$to
,
$messageString
,
'Incorrect "To" header!'
);
$this
->
assertContains
(
'Cc: '
.
$cc
,
$messageString
,
'Incorrect "Cc" header!'
);
$this
->
assertContains
(
'Bcc: '
.
$bcc
,
$messageString
,
'Incorrect "Bcc" header!'
);
}
}
/**
/**
...
@@ -139,7 +145,7 @@ class MessageTest extends VendorTestCase
...
@@ -139,7 +145,7 @@ class MessageTest extends VendorTestCase
{
{
$from
=
'someuser@somedomain.com'
;
$from
=
'someuser@somedomain.com'
;
$messageString
=
$this
->
createTestMessage
()
$messageString
=
$this
->
createTestMessage
()
->
setF
rom
(
$from
)
->
f
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!'
);
...
@@ -151,10 +157,10 @@ class MessageTest extends VendorTestCase
...
@@ -151,10 +157,10 @@ class MessageTest extends VendorTestCase
public
function
testSend
()
public
function
testSend
()
{
{
$message
=
$this
->
createTestMessage
();
$message
=
$this
->
createTestMessage
();
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
s
etS
ubject
(
'Yii Swift Test'
);
$message
->
subject
(
'Yii Swift Test'
);
$message
->
setT
ext
(
'Yii Swift Test body'
);
$message
->
t
ext
(
'Yii Swift Test body'
);
$this
->
assertTrue
(
$message
->
send
());
$this
->
assertTrue
(
$message
->
send
());
}
}
...
@@ -165,10 +171,10 @@ class MessageTest extends VendorTestCase
...
@@ -165,10 +171,10 @@ class MessageTest extends VendorTestCase
{
{
$message
=
$this
->
createTestMessage
();
$message
=
$this
->
createTestMessage
();
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
s
etS
ubject
(
'Yii Swift Attach File Test'
);
$message
->
subject
(
'Yii Swift Attach File Test'
);
$message
->
setT
ext
(
'Yii Swift Attach File Test body'
);
$message
->
t
ext
(
'Yii Swift Attach File Test body'
);
$fileName
=
__FILE__
;
$fileName
=
__FILE__
;
$message
->
attachFile
(
$fileName
);
$message
->
attachFile
(
$fileName
);
...
@@ -186,10 +192,10 @@ class MessageTest extends VendorTestCase
...
@@ -186,10 +192,10 @@ class MessageTest extends VendorTestCase
{
{
$message
=
$this
->
createTestMessage
();
$message
=
$this
->
createTestMessage
();
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
s
etS
ubject
(
'Yii Swift Create Attachment Test'
);
$message
->
subject
(
'Yii Swift Create Attachment Test'
);
$message
->
setT
ext
(
'Yii Swift Create Attachment Test body'
);
$message
->
t
ext
(
'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
]);
...
@@ -212,10 +218,10 @@ class MessageTest extends VendorTestCase
...
@@ -212,10 +218,10 @@ class MessageTest extends VendorTestCase
$cid
=
$message
->
embedFile
(
$fileName
);
$cid
=
$message
->
embedFile
(
$fileName
);
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
s
etS
ubject
(
'Yii Swift Embed File Test'
);
$message
->
subject
(
'Yii Swift Embed File Test'
);
$message
->
setH
tml
(
'Embed image: <img src="'
.
$cid
.
'" alt="pic">'
);
$message
->
h
tml
(
'Embed image: <img src="'
.
$cid
.
'" alt="pic">'
);
$this
->
assertTrue
(
$message
->
send
());
$this
->
assertTrue
(
$message
->
send
());
...
@@ -238,10 +244,10 @@ class MessageTest extends VendorTestCase
...
@@ -238,10 +244,10 @@ class MessageTest extends VendorTestCase
$cid
=
$message
->
embedContent
(
$fileContent
,
[
'fileName'
=>
$fileName
,
'contentType'
=>
$contentType
]);
$cid
=
$message
->
embedContent
(
$fileContent
,
[
'fileName'
=>
$fileName
,
'contentType'
=>
$contentType
]);
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
s
etS
ubject
(
'Yii Swift Embed File Test'
);
$message
->
subject
(
'Yii Swift Embed File Test'
);
$message
->
setH
tml
(
'Embed image: <img src="'
.
$cid
.
'" alt="pic">'
);
$message
->
h
tml
(
'Embed image: <img src="'
.
$cid
.
'" alt="pic">'
);
$this
->
assertTrue
(
$message
->
send
());
$this
->
assertTrue
(
$message
->
send
());
...
@@ -258,11 +264,11 @@ class MessageTest extends VendorTestCase
...
@@ -258,11 +264,11 @@ class MessageTest extends VendorTestCase
{
{
$message
=
$this
->
createTestMessage
();
$message
=
$this
->
createTestMessage
();
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
s
etS
ubject
(
'Yii Swift Alternative Body Test'
);
$message
->
subject
(
'Yii Swift Alternative Body Test'
);
$message
->
setH
tml
(
'<b>Yii Swift</b> test HTML body'
);
$message
->
h
tml
(
'<b>Yii Swift</b> test HTML body'
);
$message
->
setT
ext
(
'Yii Swift test plain text body'
);
$message
->
t
ext
(
'Yii Swift test plain text body'
);
$this
->
assertTrue
(
$message
->
send
());
$this
->
assertTrue
(
$message
->
send
());
...
@@ -291,10 +297,10 @@ class MessageTest extends VendorTestCase
...
@@ -291,10 +297,10 @@ class MessageTest extends VendorTestCase
{
{
$message
=
$this
->
createTestMessage
();
$message
=
$this
->
createTestMessage
();
$message
->
setT
o
(
$this
->
testEmailReceiver
);
$message
->
t
o
(
$this
->
testEmailReceiver
);
$message
->
setF
rom
(
'someuser@somedomain.com'
);
$message
->
f
rom
(
'someuser@somedomain.com'
);
$message
->
s
etS
ubject
(
'Yii Swift Alternative Body Test'
);
$message
->
subject
(
'Yii Swift Alternative Body Test'
);
$message
->
setT
ext
(
'Yii Swift test plain text body'
);
$message
->
t
ext
(
'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!'
);
...
...
tests/unit/framework/mail/BaseMailerTest.php
View file @
87af95f7
...
@@ -84,10 +84,10 @@ class BaseMailerTest extends TestCase
...
@@ -84,10 +84,10 @@ class BaseMailerTest extends TestCase
$this
->
assertTrue
(
is_object
(
$view
),
'Unable to get default view!'
);
$this
->
assertTrue
(
is_object
(
$view
),
'Unable to get default view!'
);
}
}
public
function
testC
reat
eMessage
()
public
function
testC
ompos
eMessage
()
{
{
$mailer
=
new
Mailer
();
$mailer
=
new
Mailer
();
$message
=
$mailer
->
c
reateMessag
e
();
$message
=
$mailer
->
c
ompos
e
();
$this
->
assertTrue
(
is_object
(
$message
),
'Unable to create message instance!'
);
$this
->
assertTrue
(
is_object
(
$message
),
'Unable to create message instance!'
);
$this
->
assertEquals
(
$mailer
->
messageClass
,
get_class
(
$message
),
'Invalid message class!'
);
$this
->
assertEquals
(
$mailer
->
messageClass
,
get_class
(
$message
),
'Invalid message class!'
);
...
@@ -95,7 +95,7 @@ class BaseMailerTest extends TestCase
...
@@ -95,7 +95,7 @@ class BaseMailerTest extends TestCase
'id'
=>
'test-id'
,
'id'
=>
'test-id'
,
'encoding'
=>
'test-encoding'
,
'encoding'
=>
'test-encoding'
,
);
);
$message
=
$mailer
->
c
reateMessag
e
(
$messageConfig
);
$message
=
$mailer
->
c
ompos
e
(
$messageConfig
);
foreach
(
$messageConfig
as
$name
=>
$value
)
{
foreach
(
$messageConfig
as
$name
=>
$value
)
{
$this
->
assertEquals
(
$value
,
$message
->
$name
,
'Unable to apply message config!'
);
$this
->
assertEquals
(
$value
,
$message
->
$name
,
'Unable to apply message config!'
);
...
@@ -103,21 +103,34 @@ class BaseMailerTest extends TestCase
...
@@ -103,21 +103,34 @@ class BaseMailerTest extends TestCase
}
}
/**
/**
* @depends testC
reat
eMessage
* @depends testC
ompos
eMessage
*/
*/
public
function
testDefaultMessageConfig
()
public
function
testDefaultMessageConfig
()
{
{
$mailer
=
new
Mailer
();
$mailer
=
new
Mailer
();
$messageConfig
=
array
(
$notPropertyConfig
=
[
'from'
=>
'from@domain.com'
,
'to'
=>
'to@domain.com'
,
'cc'
=>
'cc@domain.com'
,
'bcc'
=>
'bcc@domain.com'
,
'subject'
=>
'Test subject'
,
'text'
=>
'Test text body'
,
'html'
=>
'Test HTML body'
,
];
$propertyConfig
=
[
'id'
=>
'test-id'
,
'id'
=>
'test-id'
,
'encoding'
=>
'test-encoding'
,
'encoding'
=>
'test-encoding'
,
);
];
$messageConfig
=
array_merge
(
$notPropertyConfig
,
$propertyConfig
);
$mailer
->
messageConfig
=
$messageConfig
;
$mailer
->
messageConfig
=
$messageConfig
;
$message
=
$mailer
->
c
reateMessag
e
();
$message
=
$mailer
->
c
ompos
e
();
foreach
(
$messageConfig
as
$name
=>
$value
)
{
foreach
(
$notPropertyConfig
as
$name
=>
$value
)
{
$this
->
assertEquals
(
$value
,
$message
->
{
'_'
.
$name
});
}
foreach
(
$propertyConfig
as
$name
=>
$value
)
{
$this
->
assertEquals
(
$value
,
$message
->
$name
);
$this
->
assertEquals
(
$value
,
$message
->
$name
);
}
}
}
}
...
@@ -190,22 +203,50 @@ class Message extends BaseMessage
...
@@ -190,22 +203,50 @@ class Message extends BaseMessage
{
{
public
$id
;
public
$id
;
public
$encoding
;
public
$encoding
;
public
$_from
;
public
$_to
;
public
$_cc
;
public
$_bcc
;
public
$_subject
;
public
$_text
;
public
$_html
;
public
function
setCharset
(
$charset
)
{}
public
function
setCharset
(
$charset
)
{}
public
function
setFrom
(
$from
)
{}
public
function
from
(
$from
)
{
$this
->
_from
=
$from
;
return
$this
;
}
public
function
setTo
(
$to
)
{}
public
function
to
(
$to
)
{
$this
->
_to
=
$to
;
return
$this
;
}
public
function
setCc
(
$cc
)
{}
public
function
cc
(
$cc
)
{
$this
->
_cc
=
$cc
;
return
$this
;
}
public
function
setBcc
(
$bcc
)
{}
public
function
bcc
(
$bcc
)
{
$this
->
_bcc
=
$bcc
;
return
$this
;
}
public
function
setSubject
(
$subject
)
{}
public
function
subject
(
$subject
)
{
$this
->
_subject
=
$subject
;
return
$this
;
}
public
function
setText
(
$text
)
{}
public
function
text
(
$text
)
{
$this
->
_text
=
$text
;
return
$this
;
}
public
function
setHtml
(
$html
)
{}
public
function
html
(
$html
)
{
$this
->
_html
=
$html
;
return
$this
;
}
public
function
attachContent
(
$content
,
array
$options
=
[])
{}
public
function
attachContent
(
$content
,
array
$options
=
[])
{}
...
...
tests/unit/framework/mail/BaseMessageTest.php
View file @
87af95f7
...
@@ -43,7 +43,7 @@ class BaseMessageTest extends TestCase
...
@@ -43,7 +43,7 @@ class BaseMessageTest extends TestCase
public
function
testRender
()
public
function
testRender
()
{
{
$mailer
=
$this
->
getMailer
();
$mailer
=
$this
->
getMailer
();
$message
=
$mailer
->
c
reateMessag
e
();
$message
=
$mailer
->
c
ompos
e
();
$viewName
=
'test/text/view'
;
$viewName
=
'test/text/view'
;
$message
->
renderText
(
$viewName
);
$message
->
renderText
(
$viewName
);
...
@@ -59,7 +59,7 @@ class BaseMessageTest extends TestCase
...
@@ -59,7 +59,7 @@ class BaseMessageTest extends TestCase
public
function
testSend
()
public
function
testSend
()
{
{
$mailer
=
$this
->
getMailer
();
$mailer
=
$this
->
getMailer
();
$message
=
$mailer
->
c
reateMessag
e
();
$message
=
$mailer
->
c
ompos
e
();
$message
->
send
();
$message
->
send
();
$this
->
assertEquals
(
$message
,
$mailer
->
sentMessages
[
0
],
'Unable to send message!'
);
$this
->
assertEquals
(
$message
,
$mailer
->
sentMessages
[
0
],
'Unable to send message!'
);
}
}
...
@@ -94,21 +94,21 @@ class TestMessage extends BaseMessage
...
@@ -94,21 +94,21 @@ class TestMessage extends BaseMessage
public
function
setCharset
(
$charset
)
{}
public
function
setCharset
(
$charset
)
{}
public
function
setF
rom
(
$from
)
{}
public
function
f
rom
(
$from
)
{}
public
function
setT
o
(
$to
)
{}
public
function
t
o
(
$to
)
{}
public
function
setC
c
(
$cc
)
{}
public
function
c
c
(
$cc
)
{}
public
function
setB
cc
(
$bcc
)
{}
public
function
b
cc
(
$bcc
)
{}
public
function
s
etS
ubject
(
$subject
)
{}
public
function
subject
(
$subject
)
{}
public
function
setT
ext
(
$text
)
{
public
function
t
ext
(
$text
)
{
$this
->
text
=
$text
;
$this
->
text
=
$text
;
}
}
public
function
setH
tml
(
$html
)
{
public
function
h
tml
(
$html
)
{
$this
->
html
=
$html
;
$this
->
html
=
$html
;
}
}
...
...
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