Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Unit/Mail/PaymentFailureTest.php
<?php | <?php | ||||
namespace Tests\Unit\Mail; | namespace Tests\Unit\Mail; | ||||
use App\Mail\PaymentFailure; | use App\Mail\PaymentFailure; | ||||
use App\Payment; | use App\Payment; | ||||
use App\User; | use App\User; | ||||
use Tests\MailInterceptTrait; | |||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class PaymentFailureTest extends TestCase | class PaymentFailureTest extends TestCase | ||||
{ | { | ||||
use MailInterceptTrait; | |||||
/** | /** | ||||
* Test email content | * Test email content | ||||
* | |||||
* @return void | |||||
*/ | */ | ||||
public function testBuild() | public function testBuild(): void | ||||
{ | { | ||||
// @phpstan-ignore-next-line | |||||
$user = new User(); | $user = new User(); | ||||
$payment = new Payment(); | $payment = new Payment(); | ||||
$payment->amount = 123; | $payment->amount = 123; | ||||
\config(['app.support_url' => 'https://kolab.org/support']); | \config(['app.support_url' => 'https://kolab.org/support']); | ||||
$mail = new PaymentFailure($payment, $user); | $mail = $this->fakeMail(new PaymentFailure($payment, $user)); | ||||
$html = $mail->build()->render(); | |||||
$html = $mail['html']; | |||||
$plain = $mail['plain']; | |||||
$walletUrl = \App\Utils::serviceUrl('/wallet'); | $walletUrl = \App\Utils::serviceUrl('/wallet'); | ||||
$walletLink = sprintf('<a href="%s">%s</a>', $walletUrl, $walletUrl); | $walletLink = sprintf('<a href="%s">%s</a>', $walletUrl, $walletUrl); | ||||
$supportUrl = \config('app.support_url'); | $supportUrl = \config('app.support_url'); | ||||
$supportLink = sprintf('<a href="%s">%s</a>', $supportUrl, $supportUrl); | $supportLink = sprintf('<a href="%s">%s</a>', $supportUrl, $supportUrl); | ||||
$appName = \config('app.name'); | $appName = \config('app.name'); | ||||
$this->assertSame("$appName Payment Failed", $mail->subject); | $this->assertMailSubject("$appName Payment Failed", $mail['message']); | ||||
$this->assertStringStartsWith('<!DOCTYPE html>', $html); | $this->assertStringStartsWith('<!DOCTYPE html>', $html); | ||||
$this->assertTrue(strpos($html, $user->name(true)) > 0); | $this->assertTrue(strpos($html, $user->name(true)) > 0); | ||||
$this->assertTrue(strpos($html, $walletLink) > 0); | $this->assertTrue(strpos($html, $walletLink) > 0); | ||||
$this->assertTrue(strpos($html, $supportLink) > 0); | $this->assertTrue(strpos($html, $supportLink) > 0); | ||||
$this->assertTrue(strpos($html, "$appName Support") > 0); | $this->assertTrue(strpos($html, "$appName Support") > 0); | ||||
$this->assertTrue(strpos($html, "Something went wrong with auto-payment for your $appName account") > 0); | $this->assertTrue(strpos($html, "Something went wrong with auto-payment for your $appName account") > 0); | ||||
$this->assertTrue(strpos($html, "$appName Team") > 0); | $this->assertTrue(strpos($html, "$appName Team") > 0); | ||||
$this->assertStringStartsWith('Dear ' . $user->name(true), $plain); | |||||
$this->assertTrue(strpos($plain, $walletUrl) > 0); | |||||
$this->assertTrue(strpos($plain, $supportUrl) > 0); | |||||
$this->assertTrue(strpos($plain, "$appName Support") > 0); | |||||
$this->assertTrue(strpos($plain, "Something went wrong with auto-payment for your $appName account") > 0); | |||||
$this->assertTrue(strpos($plain, "$appName Team") > 0); | |||||
} | } | ||||
} | } |