-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMailerTest.php
More file actions
132 lines (121 loc) · 6.94 KB
/
MailerTest.php
File metadata and controls
132 lines (121 loc) · 6.94 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace Pdsinterop\PhpSolid;
use Pdsinterop\PhpSolid\Mailer;
const MAILER = [
"host" => "mailerHost",
"user" => "mailerUser",
"password" => "mailerPass",
"port" => "1337",
"from" => "alice@example.com"
];
const MAILSTYLES = [];
const BASEURL = "https://example.com";
class MailerMock {
public $Subject;
public $Body;
public $AltBody;
public $addresses = [];
public function addAddress($address) {
$this->addresses[] = $address;
}
public function send() {
return true;
}
}
class MailerTest extends \PHPUnit\Framework\TestCase
{
public function testGetMailer() {
$mailer = Mailer::getMailer();
$this->assertInstanceOf('\PHPMailer\PHPMailer\PHPMailer', $mailer);
$this->assertEquals($mailer->Host, MAILER['host']);
$this->assertEquals($mailer->From, MAILER['from']);
$this->assertEquals($mailer->Port, MAILER['port']);
$this->assertEquals($mailer->Username, MAILER['user']);
$this->assertEquals($mailer->Password, MAILER['password']);
$this->assertEquals($mailer->SMTPAuth, true);
$this->assertEquals($mailer->SMTPDebug, 0);
$this->assertEquals($mailer->XMailer, null);
$this->assertEquals($mailer->ContentType, "text/html");
$this->assertEquals($mailer->Mailer, "smtp");
}
public function testAccountCreated() {
Mailer::$mailer = new MailerMock();
Mailer::sendAccountCreated([
'email' => 'alice@example.com',
'webId' => 'aliceWebId'
]);
$this->assertContains("alice@example.com", Mailer::$mailer->addresses);
$this->assertMatchesRegularExpression("/aliceWebId/", Mailer::$mailer->AltBody);
$this->assertMatchesRegularExpression("/aliceWebId/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Header -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Footer -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Call to action -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|<html>|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|<body style=.*>|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|</body|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|</html>|", Mailer::$mailer->Body);
$doc = new \DOMDocument();
$doc->loadHTML(Mailer::$mailer->Body);
$this->assertEquals("Welkom bij Solid!", $doc->getElementsByTagName("title")[0]->textContent); // If this works, I'm assuming it is valid HTML.
}
public function testVerify() {
Mailer::$mailer = new MailerMock();
Mailer::sendVerify([
'email' => 'alice@example.com',
'code' => '654321'
]);
$this->assertContains("alice@example.com", Mailer::$mailer->addresses);
$this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->AltBody);
$this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Header -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Footer -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Call to action -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|<html>|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|<body style=.*>|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|</body|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|</html>|", Mailer::$mailer->Body);
$doc = new \DOMDocument();
$doc->loadHTML(Mailer::$mailer->Body);
$this->assertEquals("Bevestig je e-mail", $doc->getElementsByTagName("title")[0]->textContent); // If this works, I'm assuming it is valid HTML.
}
public function testResetPassword() {
Mailer::$mailer = new MailerMock();
Mailer::sendResetPassword([
'email' => 'alice@example.com',
'code' => '654321'
]);
$this->assertContains("alice@example.com", Mailer::$mailer->addresses);
$this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->AltBody);
$this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Header -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Footer -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Call to action -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|<html>|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|<body style=.*>|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|</body|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|</html>|", Mailer::$mailer->Body);
$doc = new \DOMDocument();
$doc->loadHTML(Mailer::$mailer->Body);
$this->assertEquals("Wachtwoordherstel", $doc->getElementsByTagName("title")[0]->textContent); // If this works, I'm assuming it is valid HTML.
}
public function testDeleteAccount() {
Mailer::$mailer = new MailerMock();
Mailer::sendDeleteAccount([
'email' => 'alice@example.com',
'code' => '654321'
]);
$this->assertContains("alice@example.com", Mailer::$mailer->addresses);
$this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->AltBody);
$this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Header -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Footer -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("/<!-- Call to action -->/", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|<html>|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|<body style=.*>|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|</body|", Mailer::$mailer->Body);
$this->assertMatchesRegularExpression("|</html>|", Mailer::$mailer->Body);
$doc = new \DOMDocument();
$doc->loadHTML(Mailer::$mailer->Body);
$this->assertEquals("Je account verwijderen", $doc->getElementsByTagName("title")[0]->textContent); // If this works, I'm assuming it is valid HTML.
}
}