1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\Mailgun\Test; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
6
|
|
|
use SilverStripe\Control\Email\Email; |
7
|
|
|
use SilverStripe\Core\Injector\Injector; |
8
|
|
|
use LeKoala\Mailgun\EmailUtils; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Test for EmailUtils |
12
|
|
|
* |
13
|
|
|
* @group Mailgun |
14
|
|
|
*/ |
15
|
|
|
class EmailUtilsTest extends SapphireTest |
16
|
|
|
{ |
17
|
|
|
public function testDisplayName() |
18
|
|
|
{ |
19
|
|
|
$arr = [ |
20
|
|
|
// Standard emails |
21
|
|
|
"[email protected]" => "me", |
22
|
|
|
"[email protected]" => "mobius", |
23
|
|
|
"[email protected]" => "test_with-chars.in.it", |
24
|
|
|
// Rfc emails |
25
|
|
|
"Me <[email protected]>" => "Me", |
26
|
|
|
"Möbius <[email protected]>" => "Möbius", |
27
|
|
|
"John Smith <[email protected]>" => "John Smith", |
28
|
|
|
|
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
foreach ($arr as $k => $v) { |
32
|
|
|
$displayName = EmailUtils::get_displayname_from_rfc_email($k); |
33
|
|
|
$this->assertEquals($v, $displayName); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testGetEmail() |
38
|
|
|
{ |
39
|
|
|
$arr = [ |
40
|
|
|
// Standard emails |
41
|
|
|
"[email protected]" => "[email protected]", |
42
|
|
|
"[email protected]" => "[email protected]", |
43
|
|
|
"[email protected]" => "[email protected]", |
44
|
|
|
// Rfc emails |
45
|
|
|
"Me <[email protected]>" => "[email protected]", |
46
|
|
|
"Möbius <[email protected]>" => "[email protected]", |
47
|
|
|
"John Smith <[email protected]>" => "[email protected]", |
48
|
|
|
|
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
foreach ($arr as $k => $v) { |
52
|
|
|
$email = EmailUtils::get_email_from_rfc_email($k); |
53
|
|
|
$this->assertEquals($v, $email); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testInlineStyles() |
58
|
|
|
{ |
59
|
|
|
if (!class_exists(\Pelago\Emogrifier::class)) { |
60
|
|
|
return $this->markTestIncomplete('Install pelago\emogrifier to run this test'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$html = <<<HTML |
64
|
|
|
<!DOCTYPE html> |
65
|
|
|
<html> |
66
|
|
|
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css">.red {color:red;}</style></head> |
67
|
|
|
<body><span class="red">red</span></body> |
68
|
|
|
</html> |
69
|
|
|
HTML; |
70
|
|
|
$result = <<<HTML |
71
|
|
|
<!DOCTYPE html> |
72
|
|
|
<html> |
73
|
|
|
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head> |
74
|
|
|
<body><span class="red" style="color: red;">red</span></body> |
75
|
|
|
</html> |
76
|
|
|
|
77
|
|
|
HTML; |
78
|
|
|
|
79
|
|
|
$process = EmailUtils::inline_styles($html); |
80
|
|
|
$this->assertEquals($result, $process); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testConvertHtmlToText() |
84
|
|
|
{ |
85
|
|
|
$someHtml = ' Some<br/>Text <a href="http://test.com">Link</a> <strong>End</strong> '; |
86
|
|
|
|
87
|
|
|
$textResult = "Some\r\nText Link (http://test.com) *End*"; |
88
|
|
|
|
89
|
|
|
$process = EmailUtils::convert_html_to_text($someHtml); |
90
|
|
|
|
91
|
|
|
$this->assertEquals($textResult, $process); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|