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
ef6fea96
Commit
ef6fea96
authored
Nov 04, 2013
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit test 'BaseMessageTest' created
parent
368c2447
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
3 deletions
+131
-3
BaseMessage.php
framework/yii/mail/BaseMessage.php
+3
-2
BaseMailerTest.php
tests/unit/framework/mail/BaseMailerTest.php
+0
-1
BaseMessageTest.php
tests/unit/framework/mail/BaseMessageTest.php
+128
-0
No files found.
framework/yii/mail/BaseMessage.php
View file @
ef6fea96
...
...
@@ -56,7 +56,7 @@ abstract class BaseMessage extends Object implements MessageInterface
*/
public
function
renderHtml
(
$view
,
$params
=
[])
{
$this
->
setHtml
(
$this
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
htmlLayout
));
$this
->
setHtml
(
$this
->
getMailer
()
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
htmlLayout
));
return
$this
;
}
...
...
@@ -65,7 +65,7 @@ abstract class BaseMessage extends Object implements MessageInterface
*/
public
function
renderText
(
$view
,
$params
=
[])
{
$this
->
setText
(
$this
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
textLayout
));
$this
->
setText
(
$this
->
getMailer
()
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
textLayout
));
return
$this
;
}
}
\ No newline at end of file
tests/unit/framework/mail/BaseMailerTest.php
View file @
ef6fea96
...
...
@@ -6,7 +6,6 @@ use Yii;
use
yii\base\View
;
use
yii\mail\BaseMailer
;
use
yii\mail\BaseMessage
;
use
yii\mail\ViewResolver
;
use
yii\helpers\FileHelper
;
use
yiiunit\TestCase
;
...
...
tests/unit/framework/mail/BaseMessageTest.php
0 → 100644
View file @
ef6fea96
<?php
namespace
yiiunit\framework\mail
;
use
Yii
;
use
yii\mail\BaseMailer
;
use
yii\mail\BaseMessage
;
use
yiiunit\TestCase
;
/**
* @group mail
*/
class
BaseMessageTest
extends
TestCase
{
public
function
setUp
()
{
$this
->
mockApplication
([
'components'
=>
[
'mail'
=>
$this
->
createTestEmailComponent
()
]
]);
}
/**
* @return Mailer test email component instance.
*/
protected
function
createTestEmailComponent
()
{
$component
=
new
TestMailer
();
return
$component
;
}
/**
* @return TestMailer mailer instance.
*/
protected
function
getMailer
()
{
return
Yii
::
$app
->
getComponent
(
'mail'
);
}
// Tests :
public
function
testRender
()
{
$mailer
=
$this
->
getMailer
();
$message
=
$mailer
->
createMessage
();
$viewName
=
'test/text/view'
;
$message
->
renderText
(
$viewName
);
$expectedText
=
'view='
.
$viewName
.
' layout='
.
$mailer
->
textLayout
;
$this
->
assertEquals
(
$expectedText
,
$message
->
text
,
'Unable to render text!'
);
$viewName
=
'test/html/view'
;
$message
->
renderHtml
(
$viewName
);
$expectedHtml
=
'view='
.
$viewName
.
' layout='
.
$mailer
->
htmlLayout
;
$this
->
assertEquals
(
$expectedHtml
,
$message
->
html
,
'Unable to render text!'
);
}
public
function
testSend
()
{
$mailer
=
$this
->
getMailer
();
$message
=
$mailer
->
createMessage
();
$message
->
send
();
$this
->
assertEquals
(
$message
,
$mailer
->
sentMessages
[
0
],
'Unable to send message!'
);
}
}
/**
* Test Mailer class
*/
class
TestMailer
extends
BaseMailer
{
public
$messageClass
=
'yiiunit\framework\mail\TestMessage'
;
public
$sentMessages
=
array
();
public
function
render
(
$view
,
$params
=
[],
$layout
=
false
)
{
return
'view='
.
$view
.
' layout='
.
$layout
;
}
public
function
send
(
$message
)
{
$this
->
sentMessages
[]
=
$message
;
}
}
/**
* Test Message class
*/
class
TestMessage
extends
BaseMessage
{
public
$text
;
public
$html
;
public
function
setCharset
(
$charset
)
{}
public
function
setFrom
(
$from
)
{}
public
function
setTo
(
$to
)
{}
public
function
setCc
(
$cc
)
{}
public
function
setBcc
(
$bcc
)
{}
public
function
setSubject
(
$subject
)
{}
public
function
setText
(
$text
)
{
$this
->
text
=
$text
;
}
public
function
setHtml
(
$html
)
{
$this
->
html
=
$html
;
}
public
function
attachContent
(
$content
,
array
$options
=
[])
{}
public
function
attachFile
(
$fileName
,
array
$options
=
[])
{}
public
function
embedFile
(
$fileName
,
array
$options
=
[])
{}
public
function
embedContent
(
$content
,
array
$options
=
[])
{}
public
function
__toString
()
{
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