Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Unit/Mail/PasswordResetTest.php
<?php | <?php | ||||
namespace Tests\Unit\Mail; | namespace Tests\Unit\Mail; | ||||
use App\Mail\PasswordReset; | use App\Mail\PasswordReset; | ||||
use App\User; | use App\User; | ||||
use App\Utils; | use App\Utils; | ||||
use App\VerificationCode; | use App\VerificationCode; | ||||
use Tests\MailInterceptTrait; | |||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class PasswordResetTest extends TestCase | class PasswordResetTest extends TestCase | ||||
{ | { | ||||
use MailInterceptTrait; | |||||
/** | /** | ||||
* Test email content | * Test email content | ||||
* | |||||
* @return void | |||||
*/ | */ | ||||
public function testPasswordResetBuild() | public function testBuild(): void | ||||
{ | { | ||||
$code = new VerificationCode([ | $code = new VerificationCode([ | ||||
'user_id' => 123456789, | 'user_id' => 123456789, | ||||
'mode' => 'password-reset', | 'mode' => 'password-reset', | ||||
'code' => 'code', | 'code' => 'code', | ||||
'short_code' => 'short-code', | 'short_code' => 'short-code', | ||||
]); | ]); | ||||
// @phpstan-ignore-next-line | |||||
$code->user = new User([ | $code->user = new User([ | ||||
'name' => 'User Name', | 'name' => 'User Name', | ||||
]); | ]); | ||||
$mail = new PasswordReset($code); | $mail = $this->fakeMail(new PasswordReset($code)); | ||||
$html = $mail->build()->render(); | |||||
$html = $mail['html']; | |||||
$plain = $mail['plain']; | |||||
$url = Utils::serviceUrl('/login/reset/' . $code->short_code . '-' . $code->code); | $url = Utils::serviceUrl('/login/reset/' . $code->short_code . '-' . $code->code); | ||||
$link = "<a href=\"$url\">$url</a>"; | $link = "<a href=\"$url\">$url</a>"; | ||||
$appName = \config('app.name'); | |||||
$this->assertMailSubject("$appName Password Reset", $mail['message']); | |||||
$this->assertSame(\config('app.name') . ' Password Reset', $mail->subject); | |||||
$this->assertStringStartsWith('<!DOCTYPE html>', $html); | $this->assertStringStartsWith('<!DOCTYPE html>', $html); | ||||
$this->assertTrue(strpos($html, $link) > 0); | $this->assertTrue(strpos($html, $link) > 0); | ||||
$this->assertTrue(strpos($html, $code->user->name(true)) > 0); | $this->assertTrue(strpos($html, $code->user->name(true)) > 0); | ||||
$this->assertStringStartsWith("Dear " . $code->user->name(true), $plain); | |||||
$this->assertTrue(strpos($plain, $link) > 0); | |||||
} | } | ||||
} | } |