|
| 1 | +<?php |
| 2 | + namespace Pdsinterop\PhpSolid; |
| 3 | + |
| 4 | + use Pdsinterop\PhpSolid\Mailer; |
| 5 | + |
| 6 | + const MAILER = [ |
| 7 | + "host" => "mailerHost", |
| 8 | + "user" => "mailerUser", |
| 9 | + "password" => "mailerPass", |
| 10 | + "port" => "1337", |
| 11 | + "from" => "alice@example.com" |
| 12 | + ]; |
| 13 | + |
| 14 | + const MAILSTYLES = []; |
| 15 | + |
| 16 | + const BASEURL = "https://example.com"; |
| 17 | + |
| 18 | + class MailerMock { |
| 19 | + public $Subject; |
| 20 | + public $Body; |
| 21 | + public $AltBody; |
| 22 | + public $addresses = []; |
| 23 | + |
| 24 | + public function addAddress($address) { |
| 25 | + $this->addresses[] = $address; |
| 26 | + } |
| 27 | + public function send() { |
| 28 | + return true; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + class MailerTest extends \PHPUnit\Framework\TestCase |
| 33 | + { |
| 34 | + public function testGetMailer() { |
| 35 | + $mailer = Mailer::getMailer(); |
| 36 | + $this->assertInstanceOf('\PHPMailer\PHPMailer\PHPMailer', $mailer); |
| 37 | + $this->assertEquals($mailer->Host, MAILER['host']); |
| 38 | + $this->assertEquals($mailer->From, MAILER['from']); |
| 39 | + $this->assertEquals($mailer->Port, MAILER['port']); |
| 40 | + $this->assertEquals($mailer->Username, MAILER['user']); |
| 41 | + $this->assertEquals($mailer->Password, MAILER['password']); |
| 42 | + $this->assertEquals($mailer->SMTPAuth, true); |
| 43 | + $this->assertEquals($mailer->SMTPDebug, 0); |
| 44 | + $this->assertEquals($mailer->XMailer, null); |
| 45 | + $this->assertEquals($mailer->ContentType, "text/html"); |
| 46 | + $this->assertEquals($mailer->Mailer, "smtp"); |
| 47 | + } |
| 48 | + |
| 49 | + public function testAccountCreated() { |
| 50 | + Mailer::$mailer = new MailerMock(); |
| 51 | + Mailer::sendAccountCreated([ |
| 52 | + 'email' => 'alice@example.com', |
| 53 | + 'webId' => 'aliceWebId' |
| 54 | + ]); |
| 55 | + $this->assertContains("alice@example.com", Mailer::$mailer->addresses); |
| 56 | + $this->assertMatchesRegularExpression("/aliceWebId/", Mailer::$mailer->AltBody); |
| 57 | + $this->assertMatchesRegularExpression("/aliceWebId/", Mailer::$mailer->Body); |
| 58 | + $this->assertMatchesRegularExpression("/<!-- Header -->/", Mailer::$mailer->Body); |
| 59 | + $this->assertMatchesRegularExpression("/<!-- Footer -->/", Mailer::$mailer->Body); |
| 60 | + $this->assertMatchesRegularExpression("/<!-- Call to action -->/", Mailer::$mailer->Body); |
| 61 | + $this->assertMatchesRegularExpression("|<html>|", Mailer::$mailer->Body); |
| 62 | + $this->assertMatchesRegularExpression("|<body style=.*>|", Mailer::$mailer->Body); |
| 63 | + $this->assertMatchesRegularExpression("|</body|", Mailer::$mailer->Body); |
| 64 | + $this->assertMatchesRegularExpression("|</html>|", Mailer::$mailer->Body); |
| 65 | + $doc = new \DOMDocument(); |
| 66 | + $doc->loadHTML(Mailer::$mailer->Body); |
| 67 | + $this->assertEquals("Welkom bij Solid!", $doc->getElementsByTagName("title")[0]->textContent); // If this works, I'm assuming it is valid HTML. |
| 68 | + } |
| 69 | + |
| 70 | + public function testVerify() { |
| 71 | + Mailer::$mailer = new MailerMock(); |
| 72 | + Mailer::sendVerify([ |
| 73 | + 'email' => 'alice@example.com', |
| 74 | + 'code' => '654321' |
| 75 | + ]); |
| 76 | + $this->assertContains("alice@example.com", Mailer::$mailer->addresses); |
| 77 | + $this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->AltBody); |
| 78 | + $this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->Body); |
| 79 | + $this->assertMatchesRegularExpression("/<!-- Header -->/", Mailer::$mailer->Body); |
| 80 | + $this->assertMatchesRegularExpression("/<!-- Footer -->/", Mailer::$mailer->Body); |
| 81 | + $this->assertMatchesRegularExpression("/<!-- Call to action -->/", Mailer::$mailer->Body); |
| 82 | + $this->assertMatchesRegularExpression("|<html>|", Mailer::$mailer->Body); |
| 83 | + $this->assertMatchesRegularExpression("|<body style=.*>|", Mailer::$mailer->Body); |
| 84 | + $this->assertMatchesRegularExpression("|</body|", Mailer::$mailer->Body); |
| 85 | + $this->assertMatchesRegularExpression("|</html>|", Mailer::$mailer->Body); |
| 86 | + $doc = new \DOMDocument(); |
| 87 | + $doc->loadHTML(Mailer::$mailer->Body); |
| 88 | + $this->assertEquals("Bevestig je e-mail", $doc->getElementsByTagName("title")[0]->textContent); // If this works, I'm assuming it is valid HTML. |
| 89 | + } |
| 90 | + |
| 91 | + public function testResetPassword() { |
| 92 | + Mailer::$mailer = new MailerMock(); |
| 93 | + Mailer::sendResetPassword([ |
| 94 | + 'email' => 'alice@example.com', |
| 95 | + 'code' => '654321' |
| 96 | + ]); |
| 97 | + $this->assertContains("alice@example.com", Mailer::$mailer->addresses); |
| 98 | + $this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->AltBody); |
| 99 | + $this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->Body); |
| 100 | + $this->assertMatchesRegularExpression("/<!-- Header -->/", Mailer::$mailer->Body); |
| 101 | + $this->assertMatchesRegularExpression("/<!-- Footer -->/", Mailer::$mailer->Body); |
| 102 | + $this->assertMatchesRegularExpression("/<!-- Call to action -->/", Mailer::$mailer->Body); |
| 103 | + $this->assertMatchesRegularExpression("|<html>|", Mailer::$mailer->Body); |
| 104 | + $this->assertMatchesRegularExpression("|<body style=.*>|", Mailer::$mailer->Body); |
| 105 | + $this->assertMatchesRegularExpression("|</body|", Mailer::$mailer->Body); |
| 106 | + $this->assertMatchesRegularExpression("|</html>|", Mailer::$mailer->Body); |
| 107 | + $doc = new \DOMDocument(); |
| 108 | + $doc->loadHTML(Mailer::$mailer->Body); |
| 109 | + $this->assertEquals("Wachtwoordherstel", $doc->getElementsByTagName("title")[0]->textContent); // If this works, I'm assuming it is valid HTML. |
| 110 | + } |
| 111 | + |
| 112 | + public function testDeleteAccount() { |
| 113 | + Mailer::$mailer = new MailerMock(); |
| 114 | + Mailer::sendDeleteAccount([ |
| 115 | + 'email' => 'alice@example.com', |
| 116 | + 'code' => '654321' |
| 117 | + ]); |
| 118 | + $this->assertContains("alice@example.com", Mailer::$mailer->addresses); |
| 119 | + $this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->AltBody); |
| 120 | + $this->assertMatchesRegularExpression("/654321/", Mailer::$mailer->Body); |
| 121 | + $this->assertMatchesRegularExpression("/<!-- Header -->/", Mailer::$mailer->Body); |
| 122 | + $this->assertMatchesRegularExpression("/<!-- Footer -->/", Mailer::$mailer->Body); |
| 123 | + $this->assertMatchesRegularExpression("/<!-- Call to action -->/", Mailer::$mailer->Body); |
| 124 | + $this->assertMatchesRegularExpression("|<html>|", Mailer::$mailer->Body); |
| 125 | + $this->assertMatchesRegularExpression("|<body style=.*>|", Mailer::$mailer->Body); |
| 126 | + $this->assertMatchesRegularExpression("|</body|", Mailer::$mailer->Body); |
| 127 | + $this->assertMatchesRegularExpression("|</html>|", Mailer::$mailer->Body); |
| 128 | + $doc = new \DOMDocument(); |
| 129 | + $doc->loadHTML(Mailer::$mailer->Body); |
| 130 | + $this->assertEquals("Je account verwijderen", $doc->getElementsByTagName("title")[0]->textContent); // If this works, I'm assuming it is valid HTML. |
| 131 | + } |
| 132 | + } |
0 commit comments