Add more tests

This commit is contained in:
RainLoop Team 2016-05-20 22:55:29 +03:00
parent 0f55220412
commit 990309f2d3
16 changed files with 716 additions and 5 deletions

View file

@ -1,6 +1,8 @@
<?php
class HtmlUtilsTest extends PHPUnit_Framework_TestCase
namespace MailSoTests;
class HtmlUtilsTest extends \PHPUnit_Framework_TestCase
{
public function testCommon()
{

View file

@ -0,0 +1,96 @@
<?php
namespace MailSoTests;
class LinkFinderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \MailSo\Base\LinkFinder
*/
protected $object;
protected function setUp()
{
$this->object = \MailSo\Base\LinkFinder::NewInstance();
}
protected function tearDown()
{
$this->object = null;
}
public function testNewInstance()
{
$this->assertTrue($this->object instanceof \MailSo\Base\LinkFinder);
}
public function testClear()
{
$this->object->Text('111');
$this->assertEquals('111', $this->object->CompileText());
$this->object->Clear();
$this->assertEquals('', $this->object->CompileText());
}
public function testText()
{
$this->object->Text('222');
$this->assertEquals('222', $this->object->CompileText());
}
public function testLinkWrapper()
{
$this->object
->Text('333 http://domain.com 333')
->LinkWrapper(function ($sLink) {
return '!'.$sLink.'!';
})
;
$this->assertEquals('333 !http://domain.com! 333', $this->object->CompileText());
}
public function testMailWrapper()
{
$this->object
->Text('444 user@domain.com 444')
->MailWrapper(function ($sMail) {
return '!'.$sMail.'!';
})
;
$this->assertEquals('444 !user@domain.com! 444', $this->object->CompileText());
}
public function testUseDefaultWrappers()
{
$this->object
->Text('555 http://domain.com user@domain.com 555')
->UseDefaultWrappers()
;
$this->assertEquals('555 <a href="http://domain.com">http://domain.com</a> <a href="mailto:user@domain.com">user@domain.com</a> 555',
$this->object->CompileText());
$this->object->UseDefaultWrappers(true);
$this->assertEquals('555 <a target="_blank" href="http://domain.com">http://domain.com</a> <a target="_blank" href="mailto:user@domain.com">user@domain.com</a> 555',
$this->object->CompileText());
}
public function testCompileText()
{
$this->object
->Text('777 http://domain.com domain.com user@domain.com <> 777')
->LinkWrapper(function ($sLink) {
return '~'.$sLink.'~';
})
->MailWrapper(function ($sMail) {
return '~'.$sMail.'~';
})
;
$this->assertEquals('777 ~http://domain.com~ domain.com ~user@domain.com~ &lt;&gt; 777', $this->object->CompileText(true));
$this->assertEquals('777 ~http://domain.com~ domain.com ~user@domain.com~ <> 777', $this->object->CompileText(false));
}
}

View file

@ -0,0 +1,85 @@
<?php
namespace MailSoTests;
class ImapClientTest extends \PHPUnit_Framework_TestCase
{
const CRLF = "\r\n";
public function testNamespace()
{
$rConnect = \MailSo\Base\StreamWrappers\Test::CreateStream(
'* NAMESPACE (("" "/")) NIL NIL'.self::CRLF.
'TAG1 OK Success'.self::CRLF
);
$oImapClient = \MailSo\Imap\ImapClient::NewInstance()->TestSetValues($rConnect, array('NAMESPACE'));
$oResult = $oImapClient->GetNamespace();
$this->assertTrue($oResult instanceof \MailSo\Imap\NamespaceResult);
}
public function testQuota()
{
$rConnect = \MailSo\Base\StreamWrappers\Test::CreateStream(
'* QUOTAROOT "INBOX" ""'.self::CRLF.
'* QUOTA "" (STORAGE 55163 10511217)'.self::CRLF.
'TAG1 OK Success'.self::CRLF
);
$oImapClient = \MailSo\Imap\ImapClient::NewInstance()->TestSetValues($rConnect, array('QUOTA'));
$aResult = $oImapClient->Quota();
$this->assertTrue(is_array($aResult));
$this->assertEquals(4, count($aResult));
$this->assertEquals(55163, $aResult[0]);
$this->assertEquals(10511217, $aResult[1]);
}
public function testFolderList()
{
$rConnect = \MailSo\Base\StreamWrappers\Test::CreateStream(
'* LIST (\Noselect) "/" 0'.self::CRLF.
'* LIST (\UnMarked) "/" 0/1'.self::CRLF.
'* LIST (\Noselect) "/" 1'.self::CRLF.
'* LIST (\Noselect) "/" 1/2'.self::CRLF.
'* LIST (\UnMarked) "/" 1/2/3'.self::CRLF.
'* LIST (\UnMarked \Inbox) "/" INBOX'.self::CRLF.
'* LIST (\UnMarked) "/" "INBOX/XXX XXX"'.self::CRLF.
'* LIST (\UnMarked) "/" &-BT,MAQBDoEM'.self::CRLF.
'* LIST (\UnMarked) "NIL" NILDelimiteFolder'.self::CRLF.
'* LIST (\UnMarked) "" EmptyDelimiteFolder'.self::CRLF.
'TAG1 OK Success'.self::CRLF
);
$oImapClient = \MailSo\Imap\ImapClient::NewInstance()->TestSetValues($rConnect);
$aResult = $oImapClient->FolderList();
$this->assertTrue(is_array($aResult) && 0 < count($aResult));
$this->assertTrue($aResult[0] instanceof \MailSo\Imap\Folder);
$this->assertEquals('0', $aResult[0]->FullNameRaw());
$this->assertEquals('0', $aResult[0]->NameRaw());
$this->assertEquals('0/1', $aResult[1]->FullNameRaw());
$this->assertEquals('1', $aResult[1]->NameRaw());
$this->assertEquals('1', $aResult[2]->FullNameRaw());
$this->assertEquals('1/2', $aResult[3]->FullNameRaw());
$this->assertEquals('1/2/3', $aResult[4]->FullNameRaw());
$this->assertEquals('3', $aResult[4]->NameRaw());
$this->assertEquals('INBOX', $aResult[5]->FullNameRaw());
$this->assertEquals('INBOX/XXX XXX', $aResult[6]->FullNameRaw());
$this->assertEquals('XXX XXX', $aResult[6]->NameRaw());
$this->assertEquals('&-BT,MAQBDoEM', $aResult[7]->FullNameRaw());
$this->assertTrue($aResult[5] instanceof \MailSo\Imap\Folder);
$this->assertEquals('/', $aResult[5]->Delimiter());
$this->assertEquals(2, count($aResult[5]->FlagsLowerCase()));
$this->assertTrue(in_array('\inbox', $aResult[5]->FlagsLowerCase()));
$this->assertTrue($aResult[8] instanceof \MailSo\Imap\Folder);
$this->assertEquals('.', $aResult[8]->Delimiter());
$this->assertTrue($aResult[9] instanceof \MailSo\Imap\Folder);
$this->assertEquals('.', $aResult[8]->Delimiter());
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace MailSoTests;
class EmailCollectionTest extends \PHPUnit_Framework_TestCase
{
public function testNewInstance()
{
$oMails = \MailSo\Mime\EmailCollection::NewInstance('admin@example.com');
$this->assertEquals(1, $oMails->Count());
}
public function testNewInstance1()
{
$oMails = \MailSo\Mime\EmailCollection::NewInstance('User Name <username@domain.com>, User D\'Name <username@domain.com>, "User Name" <username@domain.com>');
$this->assertEquals(3, $oMails->Count());
}
}

View 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');
}
}