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
88126bc4
Commit
88126bc4
authored
Oct 23, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit tests for \yii\email\swift have been improved.
Methods 'addText' and 'addHtml' added to \yii\email\BaseMessage.
parent
492f3562
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
17 deletions
+96
-17
BaseMessage.php
framework/yii/email/BaseMessage.php
+12
-0
Message.php
framework/yii/email/swift/Message.php
+18
-0
BaseMailerTest.php
tests/unit/framework/email/BaseMailerTest.php
+5
-0
MailerTest.php
tests/unit/framework/email/swift/MailerTest.php
+0
-17
MessageTest.php
tests/unit/framework/email/swift/MessageTest.php
+61
-0
No files found.
framework/yii/email/BaseMessage.php
View file @
88126bc4
...
@@ -94,6 +94,18 @@ abstract class BaseMessage extends Object
...
@@ -94,6 +94,18 @@ abstract class BaseMessage extends Object
abstract
public
function
setHtml
(
$html
);
abstract
public
function
setHtml
(
$html
);
/**
/**
* Add message plain text content part.
* @param string $text message plain text content.
*/
abstract
public
function
addText
(
$text
);
/**
* Add message HTML content part.
* @param string $html message HTML content.
*/
abstract
public
function
addHtml
(
$html
);
/**
* Create file attachment for the email message.
* Create file attachment for the email message.
* @param string $content attachment file content.
* @param string $content attachment file content.
* @param string $fileName attachment file name.
* @param string $fileName attachment file name.
...
...
framework/yii/email/swift/Message.php
View file @
88126bc4
...
@@ -100,6 +100,24 @@ class Message extends BaseMessage
...
@@ -100,6 +100,24 @@ class Message extends BaseMessage
}
}
/**
/**
* Add message plain text content part.
* @param string $text message plain text content.
*/
public
function
addText
(
$text
)
{
$this
->
getSwiftMessage
()
->
addPart
(
$text
,
'text/plain'
);
}
/**
* Add message HTML content part.
* @param string $html message HTML content.
*/
public
function
addHtml
(
$html
)
{
$this
->
getSwiftMessage
()
->
addPart
(
$html
,
'text/html'
);
}
/**
* Create file attachment for the email message.
* Create file attachment for the email message.
* @param string $content - attachment file content.
* @param string $content - attachment file content.
* @param string $fileName - attachment file name.
* @param string $fileName - attachment file name.
...
...
tests/unit/framework/email/BaseMailerTest.php
View file @
88126bc4
...
@@ -93,5 +93,9 @@ class Message extends BaseMessage
...
@@ -93,5 +93,9 @@ class Message extends BaseMessage
public
function
setHtml
(
$html
)
{}
public
function
setHtml
(
$html
)
{}
public
function
addText
(
$text
)
{}
public
function
addHtml
(
$html
)
{}
public
function
createAttachment
(
$content
,
$fileName
,
$contentType
=
'application/octet-stream'
)
{}
public
function
createAttachment
(
$content
,
$fileName
,
$contentType
=
'application/octet-stream'
)
{}
}
}
\ No newline at end of file
tests/unit/framework/email/swift/MailerTest.php
View file @
88126bc4
...
@@ -71,20 +71,4 @@ class MailerTest extends TestCase
...
@@ -71,20 +71,4 @@ class MailerTest extends TestCase
$message
=
$mailer
->
createSwiftMessage
();
$message
=
$mailer
->
createSwiftMessage
();
$this
->
assertTrue
(
is_object
(
$message
),
'Unable to create Swift message instance!'
);
$this
->
assertTrue
(
is_object
(
$message
),
'Unable to create Swift message instance!'
);
}
}
/**
* @depends testGetSwiftMailer
* @depends testCreateSwiftMessage
*/
public
function
testSend
()
{
$emailAddress
=
'someuser@somedomain.com'
;
$message
=
new
Message
();
$message
->
setTo
(
$emailAddress
);
$message
->
setFrom
(
$emailAddress
);
$message
->
setSubject
(
'Yii Swift Test'
);
$message
->
setText
(
'Yii Swift Test body'
);
$message
->
send
();
$this
->
assertTrue
(
true
);
}
}
}
\ No newline at end of file
tests/unit/framework/email/swift/MessageTest.php
View file @
88126bc4
...
@@ -13,6 +13,11 @@ use yiiunit\TestCase;
...
@@ -13,6 +13,11 @@ use yiiunit\TestCase;
*/
*/
class
MessageTest
extends
TestCase
class
MessageTest
extends
TestCase
{
{
/**
* @var string test email address, which will be used as receiver for the messages.
*/
protected
$testEmailReceiver
=
'someuser@somedomain.com'
;
public
function
setUp
()
public
function
setUp
()
{
{
$this
->
mockApplication
(
array
(
$this
->
mockApplication
(
array
(
...
@@ -37,4 +42,59 @@ class MessageTest extends TestCase
...
@@ -37,4 +42,59 @@ class MessageTest extends TestCase
$message
=
new
Message
();
$message
=
new
Message
();
$this
->
assertTrue
(
is_object
(
$message
->
getSwiftMessage
()),
'Unable to get Swift message!'
);
$this
->
assertTrue
(
is_object
(
$message
->
getSwiftMessage
()),
'Unable to get Swift message!'
);
}
}
/**
* @depends testGetSwiftMessage
*/
public
function
testSend
()
{
$message
=
new
Message
();
$message
->
setTo
(
$this
->
testEmailReceiver
);
$message
->
setFrom
(
'someuser@somedomain.com'
);
$message
->
setSubject
(
'Yii Swift Test'
);
$message
->
setText
(
'Yii Swift Test body'
);
$this
->
assertTrue
(
$message
->
send
());
}
/**
* @depends testSend
*/
public
function
testAttachFile
()
{
$message
=
new
Message
();
$message
->
setTo
(
$this
->
testEmailReceiver
);
$message
->
setFrom
(
'someuser@somedomain.com'
);
$message
->
setSubject
(
'Yii Swift Attach File Test'
);
$message
->
setText
(
'Yii Swift Attach File Test body'
);
$message
->
attachFile
(
__FILE__
);
$this
->
assertTrue
(
$message
->
send
());
}
/**
* @depends testSend
*/
public
function
testCreateAttachment
()
{
$message
=
new
Message
();
$message
->
setTo
(
$this
->
testEmailReceiver
);
$message
->
setFrom
(
'someuser@somedomain.com'
);
$message
->
setSubject
(
'Yii Swift Create Attachment Test'
);
$message
->
setText
(
'Yii Swift Create Attachment Test body'
);
$message
->
createAttachment
(
'Test attachment content'
,
'test.txt'
);
$this
->
assertTrue
(
$message
->
send
());
}
/**
* @depends testSend
*/
public
function
testSendAlternativeBody
()
{
$message
=
new
Message
();
$message
->
setTo
(
$this
->
testEmailReceiver
);
$message
->
setFrom
(
'someuser@somedomain.com'
);
$message
->
setSubject
(
'Yii Swift Alternative Body Test'
);
$message
->
addHtml
(
'<b>Yii Swift</b> test HTML body'
);
$message
->
addText
(
'Yii Swift test plain text body'
);
$this
->
assertTrue
(
$message
->
send
());
}
}
}
\ 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