Converted all notification emails to the branded layout by routing them through a shared Blade template and swapping
the MailMessage builders to use view(). This keeps the existing copy/labels but aligns the look with resources/views/ emails/partials/layout.blade.php. I also switched the customer add‑on receipt notification to reuse the existing branded view and added missing translations for the upload pipeline alert.
This commit is contained in:
71
tests/Feature/BrandedNotificationEmailsTest.php
Normal file
71
tests/Feature/BrandedNotificationEmailsTest.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\PackagePurchase;
|
||||
use App\Models\Tenant;
|
||||
use App\Notifications\Customer\RefundReceipt;
|
||||
use App\Notifications\InactiveTenantDeletionWarning;
|
||||
use App\Notifications\Ops\PurchaseCreated;
|
||||
use App\Notifications\UploadPipelineFailed;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BrandedNotificationEmailsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_upload_pipeline_failed_uses_branded_view(): void
|
||||
{
|
||||
$notification = new UploadPipelineFailed([
|
||||
'job' => 'UploadJob',
|
||||
'queue' => 'uploads',
|
||||
'event_id' => 123,
|
||||
'photo_id' => 456,
|
||||
'exception' => 'ExampleException',
|
||||
]);
|
||||
|
||||
$mailMessage = $notification->toMail((object) []);
|
||||
|
||||
$this->assertInstanceOf(MailMessage::class, $mailMessage);
|
||||
$this->assertSame('emails.notifications.basic', $mailMessage->view);
|
||||
$this->assertArrayHasKey('lines', $mailMessage->viewData);
|
||||
}
|
||||
|
||||
public function test_inactive_tenant_deletion_warning_uses_branded_view(): void
|
||||
{
|
||||
$tenant = Tenant::factory()->create([
|
||||
'name' => 'Demo Tenant',
|
||||
]);
|
||||
|
||||
$notification = new InactiveTenantDeletionWarning($tenant, Carbon::now()->addDays(10));
|
||||
$mailMessage = $notification->toMail((object) []);
|
||||
|
||||
$this->assertInstanceOf(MailMessage::class, $mailMessage);
|
||||
$this->assertSame('emails.notifications.basic', $mailMessage->view);
|
||||
$this->assertArrayHasKey('cta', $mailMessage->viewData);
|
||||
}
|
||||
|
||||
public function test_refund_receipt_uses_branded_view(): void
|
||||
{
|
||||
$purchase = PackagePurchase::factory()->create();
|
||||
$notification = new RefundReceipt($purchase);
|
||||
$mailMessage = $notification->toMail((object) []);
|
||||
|
||||
$this->assertInstanceOf(MailMessage::class, $mailMessage);
|
||||
$this->assertSame('emails.notifications.basic', $mailMessage->view);
|
||||
$this->assertArrayHasKey('footer', $mailMessage->viewData);
|
||||
}
|
||||
|
||||
public function test_ops_purchase_created_uses_branded_view(): void
|
||||
{
|
||||
$purchase = PackagePurchase::factory()->create();
|
||||
$notification = new PurchaseCreated($purchase);
|
||||
$mailMessage = $notification->toMail((object) []);
|
||||
|
||||
$this->assertInstanceOf(MailMessage::class, $mailMessage);
|
||||
$this->assertSame('emails.notifications.basic', $mailMessage->view);
|
||||
}
|
||||
}
|
||||
119
tests/Feature/CustomerEmailRenderTest.php
Normal file
119
tests/Feature/CustomerEmailRenderTest.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventPackage;
|
||||
use App\Models\EventPackageAddon;
|
||||
use App\Models\GiftVoucher;
|
||||
use App\Models\Package;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CustomerEmailRenderTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_customer_emails_render_in_de(): void
|
||||
{
|
||||
app()->setLocale('de');
|
||||
|
||||
[$user, $tenant, $package] = $this->makeCustomerContext();
|
||||
|
||||
$welcome = view('emails.welcome', ['user' => $user])->render();
|
||||
$this->assertStringContainsString('Die Fotospiel.App', $welcome);
|
||||
|
||||
$abandoned = view('emails.abandoned-checkout', [
|
||||
'user' => $user,
|
||||
'package' => $package,
|
||||
'packageName' => $package->name,
|
||||
'timing' => '1h',
|
||||
'resumeUrl' => 'https://example.test/checkout',
|
||||
])->render();
|
||||
$this->assertStringContainsString($package->name, $abandoned);
|
||||
|
||||
$contact = view('emails.contact-confirmation', ['name' => 'Soren'])->render();
|
||||
$this->assertStringContainsString('Soren', $contact);
|
||||
|
||||
$event = Event::factory()->create(['tenant_id' => $tenant->id]);
|
||||
$eventPackage = EventPackage::create([
|
||||
'event_id' => $event->id,
|
||||
'package_id' => $package->id,
|
||||
'purchased_price' => 59,
|
||||
'purchased_at' => now(),
|
||||
]);
|
||||
$addon = EventPackageAddon::create([
|
||||
'event_package_id' => $eventPackage->id,
|
||||
'event_id' => $event->id,
|
||||
'tenant_id' => $tenant->id,
|
||||
'addon_key' => 'extra_photos',
|
||||
'extra_photos' => 250,
|
||||
'amount' => 9.0,
|
||||
'currency' => 'EUR',
|
||||
'status' => 'completed',
|
||||
'metadata' => ['label' => 'Extra Fotos'],
|
||||
'purchased_at' => now(),
|
||||
]);
|
||||
$receipt = view('emails.addons.receipt', ['addon' => $addon])->render();
|
||||
$this->assertStringContainsString('Extra Fotos', $receipt);
|
||||
|
||||
$voucher = GiftVoucher::factory()->create([
|
||||
'message' => 'Herzlichen Glückwunsch!',
|
||||
]);
|
||||
$gift = view('emails.gift-voucher', [
|
||||
'voucher' => $voucher,
|
||||
'amount' => number_format((float) $voucher->amount, 2),
|
||||
'currency' => $voucher->currency,
|
||||
'forRecipient' => false,
|
||||
'printUrl' => 'https://example.test/print',
|
||||
])->render();
|
||||
$this->assertStringContainsString($voucher->code, $gift);
|
||||
}
|
||||
|
||||
public function test_customer_emails_render_in_en(): void
|
||||
{
|
||||
app()->setLocale('en');
|
||||
|
||||
[$user, $tenant, $package] = $this->makeCustomerContext();
|
||||
|
||||
$welcome = view('emails.welcome', ['user' => $user])->render();
|
||||
$this->assertStringContainsString('Die Fotospiel.App', $welcome);
|
||||
|
||||
$abandoned = view('emails.abandoned-checkout', [
|
||||
'user' => $user,
|
||||
'package' => $package,
|
||||
'packageName' => $package->name,
|
||||
'timing' => '24h',
|
||||
'resumeUrl' => 'https://example.test/checkout',
|
||||
])->render();
|
||||
$this->assertStringContainsString('Resume checkout', $abandoned);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: User, 1: Tenant, 2: Package}
|
||||
*/
|
||||
private function makeCustomerContext(): array
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'first_name' => 'Soren',
|
||||
'last_name' => 'Eberhardt',
|
||||
'username' => 'soren',
|
||||
]);
|
||||
$tenant = Tenant::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
$user->forceFill(['tenant_id' => $tenant->id])->save();
|
||||
|
||||
$package = Package::factory()->create([
|
||||
'name' => 'Standard',
|
||||
'type' => 'endcustomer',
|
||||
'max_photos' => 500,
|
||||
'max_guests' => 200,
|
||||
'gallery_days' => 30,
|
||||
]);
|
||||
|
||||
return [$user, $tenant, $package];
|
||||
}
|
||||
}
|
||||
44
tests/Feature/VerifyEmailNotificationTest.php
Normal file
44
tests/Feature/VerifyEmailNotificationTest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\VerifyEmailNotification;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
|
||||
class VerifyEmailNotificationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_user_sends_custom_verify_email_notification(): void
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
|
||||
$user->sendEmailVerificationNotification();
|
||||
|
||||
Notification::assertSentTo($user, VerifyEmailNotification::class);
|
||||
}
|
||||
|
||||
public function test_verify_email_notification_uses_custom_view(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
|
||||
$notification = new VerifyEmailNotification;
|
||||
$mailMessage = $notification->toMail($user);
|
||||
|
||||
$this->assertInstanceOf(MailMessage::class, $mailMessage);
|
||||
$this->assertSame('emails.verify-email', $mailMessage->view);
|
||||
$this->assertArrayHasKey('verificationUrl', $mailMessage->viewData);
|
||||
$this->assertArrayHasKey('user', $mailMessage->viewData);
|
||||
$this->assertSame($user->getKey(), $mailMessage->viewData['user']->getKey());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user