mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 14:37:02 +03:00
Add more tests
This commit is contained in:
parent
0f55220412
commit
990309f2d3
16 changed files with 716 additions and 5 deletions
133
tests/MailSo/Mime/EmailTest.php
Normal file
133
tests/MailSo/Mime/EmailTest.php
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
namespace MailSoTests;
|
||||
|
||||
class EmailTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testNewInstance()
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::NewInstance('admin@example.com', 'Administrator', 'Remark');
|
||||
$this->assertEquals('admin@example.com', $oMail->GetEmail());
|
||||
$this->assertEquals('Administrator', $oMail->GetDisplayName());
|
||||
$this->assertEquals('Remark', $oMail->GetRemark());
|
||||
$this->assertEquals('admin', $oMail->GetAccountName());
|
||||
$this->assertEquals('example.com', $oMail->GetDomain());
|
||||
$this->assertEquals('"Administrator" <admin@example.com> (Remark)', $oMail->ToString());
|
||||
$this->assertEquals(array('Administrator', 'admin@example.com', 'Remark', 'none', ''), $oMail->ToArray());
|
||||
}
|
||||
|
||||
public function testNewInstance1()
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::NewInstance('admin@example.com');
|
||||
$this->assertEquals('admin@example.com', $oMail->GetEmail());
|
||||
$this->assertEquals('', $oMail->GetDisplayName());
|
||||
$this->assertEquals('', $oMail->GetRemark());
|
||||
$this->assertEquals('admin@example.com', $oMail->ToString());
|
||||
$this->assertEquals(array('', 'admin@example.com', '', 'none', ''), $oMail->ToArray());
|
||||
}
|
||||
|
||||
public function testNewInstance2()
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::NewInstance('admin@example.com', 'Administrator');
|
||||
$this->assertEquals('admin@example.com', $oMail->GetEmail());
|
||||
$this->assertEquals('Administrator', $oMail->GetDisplayName());
|
||||
$this->assertEquals('', $oMail->GetRemark());
|
||||
$this->assertEquals('"Administrator" <admin@example.com>', $oMail->ToString());
|
||||
$this->assertEquals(array('Administrator', 'admin@example.com', '', 'none', ''), $oMail->ToArray());
|
||||
}
|
||||
|
||||
public function testNewInstance3()
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::NewInstance('admin@example.com', '', 'Remark');
|
||||
$this->assertEquals('admin@example.com', $oMail->GetEmail());
|
||||
$this->assertEquals('', $oMail->GetDisplayName());
|
||||
$this->assertEquals('Remark', $oMail->GetRemark());
|
||||
$this->assertEquals('<admin@example.com> (Remark)', $oMail->ToString());
|
||||
$this->assertEquals(array('', 'admin@example.com', 'Remark', 'none', ''), $oMail->ToArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function testNewInstance4()
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::NewInstance('');
|
||||
}
|
||||
|
||||
public function testParse1()
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::Parse('help@example.com');
|
||||
$this->assertEquals('help@example.com', $oMail->GetEmail());
|
||||
|
||||
$oMail = \MailSo\Mime\Email::Parse('<help@example.com>');
|
||||
$this->assertEquals('help@example.com', $oMail->GetEmail());
|
||||
}
|
||||
|
||||
public function testParse2()
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::Parse('"Тест" <help@example.com> (Ремарка)');
|
||||
$this->assertEquals('"Тест" <help@example.com> (Ремарка)', $oMail->ToString());
|
||||
}
|
||||
|
||||
public static function providerForParse()
|
||||
{
|
||||
return array(
|
||||
array('test <help@example.com>',
|
||||
array('test', 'help@example.com', '')),
|
||||
array('test<help@example.com>',
|
||||
array('test', 'help@example.com', '')),
|
||||
array('test< help@example.com >',
|
||||
array('test', 'help@example.com', '')),
|
||||
array('<help@example.com> (Remark)',
|
||||
array('', 'help@example.com', 'Remark')),
|
||||
array('"New \" Admin" <help@example.com> (Rem)',
|
||||
array('New " Admin', 'help@example.com', 'Rem')),
|
||||
array('"Тест" <help@example.com> (Ремарка)',
|
||||
array('Тест', 'help@example.com', 'Ремарка')),
|
||||
array('Microsoft Outlook<MicrosoftExchange329e71ec88ae4615bbc36ab6ce41109e@PPTH.PRIVATE>',
|
||||
array('Microsoft Outlook', 'MicrosoftExchange329e71ec88ae4615bbc36ab6ce41109e@ppth.private', '')),
|
||||
);
|
||||
}
|
||||
|
||||
public static function providerForParse2()
|
||||
{
|
||||
return array(
|
||||
array('help@xn--d1abbgf6aiiy.xn--p1ai',
|
||||
array('', 'help@президент.рф', '')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForParse
|
||||
*/
|
||||
public function testParseWithProvider($sValue, $aResult)
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::Parse($sValue);
|
||||
$this->assertEquals($aResult, $oMail->ToArray(false, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForParse2
|
||||
*/
|
||||
public function testParseWithProvider2($sValue, $aResult)
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::Parse($sValue);
|
||||
$this->assertEquals($aResult, $oMail->ToArray(true, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function testParse5()
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::Parse('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function testParse6()
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::Parse('example.com');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue