Commit 88126bc4 by Paul Klimov

Unit tests for \yii\email\swift have been improved.

Methods 'addText' and 'addHtml' added to \yii\email\BaseMessage.
parent 492f3562
......@@ -94,6 +94,18 @@ abstract class BaseMessage extends Object
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.
* @param string $content attachment file content.
* @param string $fileName attachment file name.
......
......@@ -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.
* @param string $content - attachment file content.
* @param string $fileName - attachment file name.
......
......@@ -93,5 +93,9 @@ class Message extends BaseMessage
public function setHtml($html) {}
public function addText($text) {}
public function addHtml($html) {}
public function createAttachment($content, $fileName, $contentType = 'application/octet-stream') {}
}
\ No newline at end of file
......@@ -71,20 +71,4 @@ class MailerTest extends TestCase
$message = $mailer->createSwiftMessage();
$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
......@@ -13,6 +13,11 @@ use yiiunit\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()
{
$this->mockApplication(array(
......@@ -37,4 +42,59 @@ class MessageTest extends TestCase
$message = new 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment