You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.4 KiB
100 lines
2.4 KiB
11 years ago
|
<?php
|
||
|
|
||
11 years ago
|
namespace yiiunit\extensions\swiftmailer;
|
||
11 years ago
|
|
||
|
use Yii;
|
||
11 years ago
|
use yii\swiftmailer\Mailer;
|
||
|
use yii\swiftmailer\Message;
|
||
11 years ago
|
use yiiunit\TestCase;
|
||
|
|
||
|
/**
|
||
|
* @group email
|
||
|
* @group swiftmailer
|
||
|
*/
|
||
|
class MessageTest extends TestCase
|
||
|
{
|
||
11 years ago
|
/**
|
||
|
* @var string test email address, which will be used as receiver for the messages.
|
||
|
*/
|
||
|
protected $testEmailReceiver = 'someuser@somedomain.com';
|
||
|
|
||
11 years ago
|
public function setUp()
|
||
|
{
|
||
|
$this->mockApplication(array(
|
||
|
'vendorPath' => Yii::getAlias('@yiiunit/vendor')
|
||
|
));
|
||
|
Yii::$app->setComponent('email', $this->createTestEmailComponent());
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return Mailer test email component instance.
|
||
|
*/
|
||
|
protected function createTestEmailComponent()
|
||
|
{
|
||
|
$component = new Mailer();
|
||
|
return $component;
|
||
|
}
|
||
|
|
||
|
// Tests :
|
||
|
|
||
|
public function testGetSwiftMessage()
|
||
|
{
|
||
|
$message = new Message();
|
||
|
$this->assertTrue(is_object($message->getSwiftMessage()), 'Unable to get Swift message!');
|
||
|
}
|
||
11 years ago
|
|
||
|
/**
|
||
|
* @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());
|
||
|
}
|
||
11 years ago
|
}
|