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