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
45d02d07
Commit
45d02d07
authored
Nov 05, 2013
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Method 'yii\mail\MessageInterface::body()' added.
parent
87af95f7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
1 deletion
+53
-1
BaseMessage.php
framework/yii/mail/BaseMessage.php
+17
-0
MessageInterface.php
framework/yii/mail/MessageInterface.php
+11
-0
BaseMessageTest.php
tests/unit/framework/mail/BaseMessageTest.php
+25
-1
No files found.
framework/yii/mail/BaseMessage.php
View file @
45d02d07
...
@@ -61,4 +61,20 @@ abstract class BaseMessage extends Object implements MessageInterface
...
@@ -61,4 +61,20 @@ abstract class BaseMessage extends Object implements MessageInterface
$this
->
text
(
$this
->
getMailer
()
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
textLayout
));
$this
->
text
(
$this
->
getMailer
()
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
textLayout
));
return
$this
;
return
$this
;
}
}
/**
* @inheritdoc
*/
public
function
body
(
$view
,
$params
=
[])
{
if
(
is_array
(
$view
))
{
$this
->
renderHtml
(
$view
[
'html'
],
$params
);
$this
->
renderText
(
$view
[
'text'
],
$params
);
}
else
{
$html
=
$this
->
getMailer
()
->
render
(
$view
,
$params
,
$this
->
getMailer
()
->
htmlLayout
);
$this
->
html
(
$html
);
$this
->
text
(
strip_tags
(
$html
));
}
return
$this
;
}
}
}
\ No newline at end of file
framework/yii/mail/MessageInterface.php
View file @
45d02d07
...
@@ -167,6 +167,17 @@ interface MessageInterface
...
@@ -167,6 +167,17 @@ interface MessageInterface
public
function
renderText
(
$view
,
$params
=
[]);
public
function
renderText
(
$view
,
$params
=
[]);
/**
/**
* Composes the message HTML and plain text body.
* @param string|array $view varies method behavior depending on type:
* - string - the view name or the path alias of the HTML body view file, in this case
* text body will be composed from html one using [[strip_tags()]] function.
* - array - list of views for each body type in format: ['html' => 'htmlView', 'text' => 'textView']
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return static self reference.
*/
public
function
body
(
$view
,
$params
=
[]);
/**
* String output.
* String output.
* This is PHP magic method that returns string representation of an object.
* This is PHP magic method that returns string representation of an object.
* @return string the string representation of the object
* @return string the string representation of the object
...
...
tests/unit/framework/mail/BaseMessageTest.php
View file @
45d02d07
...
@@ -53,7 +53,31 @@ class BaseMessageTest extends TestCase
...
@@ -53,7 +53,31 @@ class BaseMessageTest extends TestCase
$viewName
=
'test/html/view'
;
$viewName
=
'test/html/view'
;
$message
->
renderHtml
(
$viewName
);
$message
->
renderHtml
(
$viewName
);
$expectedHtml
=
'view='
.
$viewName
.
' layout='
.
$mailer
->
htmlLayout
;
$expectedHtml
=
'view='
.
$viewName
.
' layout='
.
$mailer
->
htmlLayout
;
$this
->
assertEquals
(
$expectedHtml
,
$message
->
html
,
'Unable to render text!'
);
$this
->
assertEquals
(
$expectedHtml
,
$message
->
html
,
'Unable to render html!'
);
}
/**
* @depends testRender
*/
public
function
testComposeBody
()
{
$mailer
=
$this
->
getMailer
();
$message
=
$mailer
->
compose
();
$viewName
=
'test/html/view'
;
$message
->
body
(
$viewName
);
$expectedHtml
=
'view='
.
$viewName
.
' layout='
.
$mailer
->
htmlLayout
;
$this
->
assertEquals
(
$expectedHtml
,
$message
->
html
,
'Unable to compose html!'
);
$expectedText
=
strip_tags
(
$expectedHtml
);
$this
->
assertEquals
(
$expectedText
,
$message
->
text
,
'Unable to compose text from html!'
);
$textViewName
=
'test/text/view'
;
$htmlViewName
=
'test/html/view'
;
$message
->
body
([
'text'
=>
$textViewName
,
'html'
=>
$htmlViewName
]);
$expectedHtml
=
'view='
.
$htmlViewName
.
' layout='
.
$mailer
->
htmlLayout
;
$this
->
assertEquals
(
$expectedHtml
,
$message
->
html
,
'Unable to compose html from separated view!'
);
$expectedText
=
'view='
.
$textViewName
.
' layout='
.
$mailer
->
textLayout
;
$this
->
assertEquals
(
$expectedText
,
$message
->
text
,
'Unable to compose text from separated view!'
);
}
}
public
function
testSend
()
public
function
testSend
()
...
...
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