Browse Source

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

Methods 'addText' and 'addHtml' added to \yii\email\BaseMessage.
tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
88126bc4d3
  1. 12
      framework/yii/email/BaseMessage.php
  2. 18
      framework/yii/email/swift/Message.php
  3. 4
      tests/unit/framework/email/BaseMailerTest.php
  4. 16
      tests/unit/framework/email/swift/MailerTest.php
  5. 60
      tests/unit/framework/email/swift/MessageTest.php

12
framework/yii/email/BaseMessage.php

@ -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.

18
framework/yii/email/swift/Message.php

@ -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.

4
tests/unit/framework/email/BaseMailerTest.php

@ -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') {}
}

16
tests/unit/framework/email/swift/MailerTest.php

@ -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);
}
}

60
tests/unit/framework/email/swift/MessageTest.php

@ -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());
}
}
Loading…
Cancel
Save