You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
|
11 months ago
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Feature;
|
||
|
|
|
||
|
|
use App\Models\Admin;
|
||
|
|
use App\Notifications\VisitEmailNotify;
|
||
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
use Tests\TestCase;
|
||
|
|
|
||
|
|
class VisitEmailNotificationTest extends TestCase
|
||
|
|
{
|
||
|
|
use RefreshDatabase;
|
||
|
|
|
||
|
|
/** @test */
|
||
|
|
public function test_visit_email_notification_content()
|
||
|
|
{
|
||
|
|
$admin = Admin::factory()->create([
|
||
|
|
'name' => '测试管理员',
|
||
|
|
'email' => 'test@example.com'
|
||
|
|
]);
|
||
|
|
|
||
|
|
$visitData = [
|
||
|
|
'name' => '测试访客',
|
||
|
|
'date' => '2024-01-15',
|
||
|
|
'mobile' => '13800138000',
|
||
|
|
'reason' => '商务洽谈',
|
||
|
|
];
|
||
|
|
|
||
|
|
$notification = new VisitEmailNotify($visitData);
|
||
|
|
$mailMessage = $notification->toMail($admin);
|
||
|
|
|
||
|
|
// 验证邮件内容
|
||
|
|
$this->assertStringContainsString('新的拜访预约通知', $mailMessage->subject);
|
||
|
|
$this->assertStringContainsString('测试访客', $mailMessage->subject);
|
||
|
|
$this->assertStringContainsString('您好 测试管理员', $mailMessage->greeting);
|
||
|
|
$this->assertStringContainsString('测试访客', $mailMessage->introLines[0]);
|
||
|
|
$this->assertStringContainsString('2024-01-15', $mailMessage->introLines[0]);
|
||
|
|
$this->assertStringContainsString('13800138000', $mailMessage->introLines[1]);
|
||
|
|
$this->assertStringContainsString('商务洽谈', $mailMessage->introLines[2]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** @test */
|
||
|
|
public function test_visit_email_notification_without_reason()
|
||
|
|
{
|
||
|
|
$admin = Admin::factory()->create([
|
||
|
|
'name' => '测试管理员',
|
||
|
|
'email' => 'test@example.com'
|
||
|
|
]);
|
||
|
|
|
||
|
|
$visitData = [
|
||
|
|
'name' => '测试访客',
|
||
|
|
'date' => '2024-01-15',
|
||
|
|
'mobile' => '13800138000',
|
||
|
|
'reason' => null,
|
||
|
|
];
|
||
|
|
|
||
|
|
$notification = new VisitEmailNotify($visitData);
|
||
|
|
$mailMessage = $notification->toMail($admin);
|
||
|
|
|
||
|
|
// 验证邮件内容包含"无"
|
||
|
|
$this->assertStringContainsString('无', $mailMessage->introLines[2]);
|
||
|
|
}
|
||
|
|
}
|