Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Unit/Mail/NegativeBalanceBeforeDeleteTest.php
<?php | <?php | ||||
namespace Tests\Unit\Mail; | namespace Tests\Unit\Mail; | ||||
use App\Jobs\WalletCheck; | use App\Jobs\WalletCheck; | ||||
use App\Mail\NegativeBalanceBeforeDelete; | use App\Mail\NegativeBalanceBeforeDelete; | ||||
use App\User; | use App\User; | ||||
use App\Wallet; | use App\Wallet; | ||||
use Tests\MailInterceptTrait; | |||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class NegativeBalanceBeforeDeleteTest extends TestCase | class NegativeBalanceBeforeDeleteTest extends TestCase | ||||
{ | { | ||||
use MailInterceptTrait; | |||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
\App\TenantSetting::truncate(); | \App\TenantSetting::truncate(); | ||||
Show All 20 Lines | public function testBuild(): void | ||||
$wallet->save(); | $wallet->save(); | ||||
$threshold = WalletCheck::threshold($wallet, WalletCheck::THRESHOLD_DELETE); | $threshold = WalletCheck::threshold($wallet, WalletCheck::THRESHOLD_DELETE); | ||||
\config([ | \config([ | ||||
'app.support_url' => 'https://kolab.org/support', | 'app.support_url' => 'https://kolab.org/support', | ||||
]); | ]); | ||||
$mail = $this->fakeMail(new NegativeBalanceBeforeDelete($wallet, $user)); | $mail = $this->renderMail(new NegativeBalanceBeforeDelete($wallet, $user)); | ||||
$html = $mail['html']; | $html = $mail['html']; | ||||
$plain = $mail['plain']; | $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 = $user->tenant->title; | $appName = $user->tenant->title; | ||||
$this->assertMailSubject("$appName Final Warning", $mail['message']); | $this->assertSame("$appName Final Warning", $mail['subject']); | ||||
$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, "This is a final reminder to settle your $appName") > 0); | $this->assertTrue(strpos($html, "This is a final reminder to settle your $appName") > 0); | ||||
$this->assertTrue(strpos($html, $threshold->toDateString()) > 0); | $this->assertTrue(strpos($html, $threshold->toDateString()) > 0); | ||||
$this->assertTrue(strpos($html, "$appName Support") > 0); | $this->assertTrue(strpos($html, "$appName Support") > 0); | ||||
Show All 16 Lines | public function testBuild(): void | ||||
$threshold = WalletCheck::threshold($wallet, WalletCheck::THRESHOLD_DELETE); | $threshold = WalletCheck::threshold($wallet, WalletCheck::THRESHOLD_DELETE); | ||||
$tenant->setSettings([ | $tenant->setSettings([ | ||||
'app.support_url' => 'https://test.org/support', | 'app.support_url' => 'https://test.org/support', | ||||
'app.public_url' => 'https://test.org', | 'app.public_url' => 'https://test.org', | ||||
]); | ]); | ||||
$mail = $this->fakeMail(new NegativeBalanceBeforeDelete($wallet, $user)); | $mail = $this->renderMail(new NegativeBalanceBeforeDelete($wallet, $user)); | ||||
$html = $mail['html']; | $html = $mail['html']; | ||||
$plain = $mail['plain']; | $plain = $mail['plain']; | ||||
$walletUrl = 'https://test.org/wallet'; | $walletUrl = 'https://test.org/wallet'; | ||||
$walletLink = sprintf('<a href="%s">%s</a>', $walletUrl, $walletUrl); | $walletLink = sprintf('<a href="%s">%s</a>', $walletUrl, $walletUrl); | ||||
$supportUrl = 'https://test.org/support'; | $supportUrl = 'https://test.org/support'; | ||||
$supportLink = sprintf('<a href="%s">%s</a>', $supportUrl, $supportUrl); | $supportLink = sprintf('<a href="%s">%s</a>', $supportUrl, $supportUrl); | ||||
$this->assertMailSubject("{$tenant->title} Final Warning", $mail['message']); | $this->assertSame("{$tenant->title} Final Warning", $mail['subject']); | ||||
$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, "This is a final reminder to settle your {$tenant->title}") > 0); | $this->assertTrue(strpos($html, "This is a final reminder to settle your {$tenant->title}") > 0); | ||||
$this->assertTrue(strpos($html, $threshold->toDateString()) > 0); | $this->assertTrue(strpos($html, $threshold->toDateString()) > 0); | ||||
$this->assertTrue(strpos($html, "{$tenant->title} Support") > 0); | $this->assertTrue(strpos($html, "{$tenant->title} Support") > 0); | ||||
Show All 11 Lines |