mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Added tests
Small fixes
This commit is contained in:
parent
c6a9563d81
commit
5236810d6b
16 changed files with 73608 additions and 45 deletions
96
tests/lib/MailSo/Base/LinkFinderTest.php
Normal file
96
tests/lib/MailSo/Base/LinkFinderTest.php
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace MailSoTests;
|
||||
|
||||
class LinkFinderText 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 user@domain.com <> 777')
|
||||
->LinkWrapper(function ($sLink) {
|
||||
return '~'.$sLink.'~';
|
||||
})
|
||||
->MailWrapper(function ($sMail) {
|
||||
return '~'.$sMail.'~';
|
||||
})
|
||||
;
|
||||
|
||||
$this->assertEquals('777 ~http://domain.com~ ~user@domain.com~ <> 777', $this->object->CompileText(true));
|
||||
$this->assertEquals('777 ~http://domain.com~ ~user@domain.com~ <> 777', $this->object->CompileText(false));
|
||||
}
|
||||
}
|
||||
85
tests/lib/MailSo/Imap/ImapClientTest.php
Normal file
85
tests/lib/MailSo/Imap/ImapClientTest.php
Normal 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());
|
||||
}
|
||||
}
|
||||
18
tests/lib/MailSo/Mime/EmailCollectionTest.php
Normal file
18
tests/lib/MailSo/Mime/EmailCollectionTest.php
Normal 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());
|
||||
}
|
||||
}
|
||||
131
tests/lib/MailSo/Mime/EmailTest.php
Normal file
131
tests/lib/MailSo/Mime/EmailTest.php
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
namespace MailSoTests;
|
||||
|
||||
class EmailTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testNewInstance()
|
||||
{
|
||||
$oEmail = \MailSo\Mime\Email::NewInstance('admin@example.com', 'Administrator', 'Remark');
|
||||
$this->assertEquals('admin@example.com', $oEmail->GetEmail());
|
||||
$this->assertEquals('Administrator', $oEmail->GetDisplayName());
|
||||
$this->assertEquals('Remark', $oEmail->GetRemark());
|
||||
$this->assertEquals('admin', $oEmail->GetAccountName());
|
||||
$this->assertEquals('example.com', $oEmail->GetDomain());
|
||||
$this->assertEquals('"Administrator" <admin@example.com> (Remark)', $oEmail->ToString());
|
||||
$this->assertEquals(array('Administrator', 'admin@example.com', 'Remark'), $oEmail->ToArray());
|
||||
}
|
||||
|
||||
public function testNewInstance1()
|
||||
{
|
||||
$oEmail = \MailSo\Mime\Email::NewInstance('admin@example.com');
|
||||
$this->assertEquals('admin@example.com', $oEmail->GetEmail());
|
||||
$this->assertEquals('', $oEmail->GetDisplayName());
|
||||
$this->assertEquals('', $oEmail->GetRemark());
|
||||
$this->assertEquals('admin@example.com', $oEmail->ToString());
|
||||
$this->assertEquals(array('', 'admin@example.com', ''), $oEmail->ToArray());
|
||||
}
|
||||
|
||||
public function testNewInstance2()
|
||||
{
|
||||
$oEmail = \MailSo\Mime\Email::NewInstance('admin@example.com', 'Administrator');
|
||||
$this->assertEquals('admin@example.com', $oEmail->GetEmail());
|
||||
$this->assertEquals('Administrator', $oEmail->GetDisplayName());
|
||||
$this->assertEquals('', $oEmail->GetRemark());
|
||||
$this->assertEquals('"Administrator" <admin@example.com>', $oEmail->ToString());
|
||||
$this->assertEquals(array('Administrator', 'admin@example.com', ''), $oEmail->ToArray());
|
||||
}
|
||||
|
||||
public function testNewInstance3()
|
||||
{
|
||||
$oEmail = \MailSo\Mime\Email::NewInstance('admin@example.com', '', 'Remark');
|
||||
$this->assertEquals('admin@example.com', $oEmail->GetEmail());
|
||||
$this->assertEquals('', $oEmail->GetDisplayName());
|
||||
$this->assertEquals('Remark', $oEmail->GetRemark());
|
||||
$this->assertEquals('<admin@example.com> (Remark)', $oEmail->ToString());
|
||||
$this->assertEquals(array('', 'admin@example.com', 'Remark'), $oEmail->ToArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function testNewInstance4()
|
||||
{
|
||||
\MailSo\Mime\Email::NewInstance('');
|
||||
}
|
||||
|
||||
public function testParse1()
|
||||
{
|
||||
$oEmail = \MailSo\Mime\Email::Parse('help@example.com');
|
||||
$this->assertEquals('help@example.com', $oEmail->GetEmail());
|
||||
|
||||
$oEmail = \MailSo\Mime\Email::Parse('<help@example.com>');
|
||||
$this->assertEquals('help@example.com', $oEmail->GetEmail());
|
||||
}
|
||||
|
||||
public function testParse2()
|
||||
{
|
||||
$oEmail = \MailSo\Mime\Email::Parse('"Тест" <help@example.com> (Ремарка)');
|
||||
$this->assertEquals('"Тест" <help@example.com> (Ремарка)', $oEmail->ToString());
|
||||
$this->assertEquals('"=?utf-8?B?0KLQtdGB0YI=?=" <help@example.com> (=?utf-8?B?0KDQtdC80LDRgNC60LA=?=)', $oEmail->ToString(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function testParse5()
|
||||
{
|
||||
\MailSo\Mime\Email::Parse('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function testParse6()
|
||||
{
|
||||
\MailSo\Mime\Email::Parse('example.com');
|
||||
}
|
||||
|
||||
public function testParsePuny1()
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::Parse('help@xn--d1acufc.xn--p1ai');
|
||||
$this->assertEquals('help@xn--d1acufc.xn--p1ai', $oMail->ToString());
|
||||
$this->assertEquals('help@домен.рф', $oMail->ToString(false, true));
|
||||
}
|
||||
|
||||
public function testParsePuny2()
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::Parse('help@домен.рф');
|
||||
$this->assertEquals('help@xn--d1acufc.xn--p1ai', $oMail->ToString());
|
||||
$this->assertEquals('help@домен.рф', $oMail->ToString(false, true));
|
||||
}
|
||||
|
||||
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', '')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerForParse
|
||||
*/
|
||||
public function testParseWithProvider($sValue, $aResult)
|
||||
{
|
||||
$oMail = \MailSo\Mime\Email::Parse($sValue);
|
||||
$this->assertEquals($aResult, $oMail->ToArray());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue