1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
<?php
namespace Roundcube\Tests\Framework;
use PHPUnit\Framework\TestCase;
use function Roundcube\Tests\invokeMethod;
/**
* Test class to test rcube_smtp class
*/
class Framework_Smtp extends TestCase
{
/**
* Class constructor
*/
function test_class()
{
$object = new \rcube_smtp();
$this->assertInstanceOf(\rcube_smtp::class, $object, "Class constructor");
}
/**
* Test preparing headers
*/
function test_prepare_headers()
{
$smtp = new \rcube_smtp();
$headers = [
'Subject' => 'Test',
'From' => '"John Doe" <john@domain.tld>',
'Received' => 'from github.com ([10.48.109.45]) by smtp.github.com (Postfix) with ESMTPA id 8C9B4E0075'
. ' for <john@domain.tld>; Sat, 28 Nov 2020 22:45:44 -0800 (PST)',
];
$result = invokeMethod($smtp, '_prepare_headers', [$headers]);
$this->assertCount(2, $result);
$this->assertSame('john@domain.tld', $result[0]);
$this->assertSame(
"Received: from github.com ([10.48.109.45]) by smtp.github.com (Postfix) with ESMTPA id 8C9B4E0075"
. " for <john@domain.tld>; Sat, 28 Nov 2020 22:45:44 -0800 (PST)\r\n"
. "Subject: Test\r\n"
. "From: \"John Doe\" <john@domain.tld>\r\n",
$result[1]
);
}
/**
* Test parsing email address input
*/
function test_parse_rfc822()
{
$smtp = new \rcube_smtp();
$input = 'test@test1.com, "test" <test@test2.pl>, "test@test3.eu" <test@test3.uk>';
$result = invokeMethod($smtp, '_parse_rfc822', [$input]);
$this->assertSame(['test@test1.com', 'test@test2.pl', 'test@test3.uk'], $result);
}
}
|