|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LeKoala\EmailTemplates\Test; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
6
|
|
|
use LeKoala\EmailTemplates\Helpers\EmailUtils; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Test for EmailUtils |
|
10
|
|
|
* |
|
11
|
|
|
* @group EmailTemplates |
|
12
|
|
|
*/ |
|
13
|
|
|
class EmailUtilsTest extends SapphireTest |
|
14
|
|
|
{ |
|
15
|
|
|
public function testDisplayName() |
|
16
|
|
|
{ |
|
17
|
|
|
$arr = [ |
|
18
|
|
|
// Standard emails |
|
19
|
|
|
"[email protected]" => "me", |
|
20
|
|
|
"[email protected]" => "mobius", |
|
21
|
|
|
"[email protected]" => "test_with-chars.in.it", |
|
22
|
|
|
// Rfc emails |
|
23
|
|
|
"Me <[email protected]>" => "Me", |
|
24
|
|
|
"Möbius <[email protected]>" => "Möbius", |
|
25
|
|
|
"John Smith <[email protected]>" => "John Smith", |
|
26
|
|
|
|
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
foreach ($arr as $k => $v) { |
|
30
|
|
|
$displayName = EmailUtils::get_displayname_from_rfc_email($k); |
|
31
|
|
|
$this->assertEquals($v, $displayName); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testGetEmail() |
|
36
|
|
|
{ |
|
37
|
|
|
$arr = [ |
|
38
|
|
|
// Standard emails |
|
39
|
|
|
"[email protected]" => "[email protected]", |
|
40
|
|
|
"[email protected]" => "[email protected]", |
|
41
|
|
|
"[email protected]" => "[email protected]", |
|
42
|
|
|
// Rfc emails |
|
43
|
|
|
"Me <[email protected]>" => "[email protected]", |
|
44
|
|
|
"Möbius <[email protected]>" => "[email protected]", |
|
45
|
|
|
"John Smith <[email protected]>" => "[email protected]", |
|
46
|
|
|
|
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
foreach ($arr as $k => $v) { |
|
50
|
|
|
$email = EmailUtils::get_email_from_rfc_email($k); |
|
51
|
|
|
$this->assertEquals($v, $email); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testConvertHtmlToText() |
|
56
|
|
|
{ |
|
57
|
|
|
$someHtml = ' Some<br/>Text <a href="http://test.com">Link</a> <strong>End</strong> '; |
|
58
|
|
|
|
|
59
|
|
|
$textResult = "Some\r\nText Link (http://test.com) *End*"; |
|
60
|
|
|
|
|
61
|
|
|
$process = EmailUtils::convert_html_to_text($someHtml); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertEquals($textResult, $process); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testConvertEmails() |
|
67
|
|
|
{ |
|
68
|
|
|
$addresses = [ |
|
69
|
|
|
'[email protected]' => "Test man" |
|
70
|
|
|
]; |
|
71
|
|
|
|
|
72
|
|
|
$result = EmailUtils::format_email_addresses($addresses); |
|
73
|
|
|
$this->assertEquals("[email protected] <Test man>", $result); |
|
74
|
|
|
|
|
75
|
|
|
$addresses2 = [ |
|
76
|
|
|
'[email protected]' => "Test man", |
|
77
|
|
|
'[email protected]' => "Test man 2" |
|
78
|
|
|
]; |
|
79
|
|
|
|
|
80
|
|
|
$result = EmailUtils::format_email_addresses($addresses2); |
|
81
|
|
|
$this->assertEquals("[email protected] <Test man>, [email protected] <Test man 2>", $result); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|