여러 화면에서 조건부(FormRequest) 검증이 우회되거나 과도하게 제한되던 결함을 한 계열로 묶어 수정한다. - 검증 규칙 확장 필터 이름 10개를 나머지 92개와 동일 규칙으로 통일 - 설명 길이를 바이트가 아닌 글자 수로 계산(한글 오검출 해소) - 비활성 언어팩 번역 보존한 채 수정 허용 - 알림 템플릿 제목 nullable 존중, 미지원 발송 수단 저장 차단 - 일정/실행 이력 목록 조회 검증 정합 - 게시판 첨부 미사용 시 빈 확장자 통과, new_display_hours/최소 길이 0 허용, 일괄 적용 override_values 범위 검증(SSoT) - 이커머스 클레임 사유 조회 검증, 용어 정정 - 원문 i18n 키 노출 다수 해소, 저장/삭제 실패 시 사유 화면 노출 - 아이콘 크기/다크모드 대비 회귀 수정 번들 확장(모듈3·플러그인6·템플릿2·언어팩5) 버전 new-bump 및 CHANGELOG 반영, ja 언어팩 동기.
120 lines
4.0 KiB
PHP
120 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Notifications;
|
|
|
|
use App\Models\NotificationDefinition;
|
|
use App\Models\NotificationTemplate;
|
|
use App\Models\User;
|
|
use App\Notifications\GenericNotification;
|
|
use App\Notifications\GuestNotifiable;
|
|
use App\Services\NotificationChannelService;
|
|
use App\Services\NotificationTemplateService;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* 비회원(게스트) 채널 게이트 테스트
|
|
*
|
|
* GenericNotification::via() 가 게스트 수신자에 대해 채널 allow_guest 정책을 적용하는지,
|
|
* NotificationChannelService::isChannelGuestAllowed() 가 config/훅 기반으로 동작하는지 검증.
|
|
*/
|
|
class GenericNotificationGuestGateTest extends TestCase
|
|
{
|
|
private NotificationDefinition $definition;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// 메일 발송 통과를 단언하므로 mail 채널을 준비 완료 상태로 만든다
|
|
// (기본 테스트 설정은 from_address 가 플레이스홀더라 readiness 가 false 다)
|
|
$this->enableMailChannelReadiness();
|
|
|
|
$templateService = app(NotificationTemplateService::class);
|
|
foreach (['mail', 'database'] as $ch) {
|
|
$templateService->invalidateCache('guest_gate_check', $ch);
|
|
}
|
|
|
|
$this->definition = NotificationDefinition::updateOrCreate(
|
|
['type' => 'guest_gate_check'],
|
|
[
|
|
'hook_prefix' => 'core.test',
|
|
'extension_type' => 'core',
|
|
'extension_identifier' => 'core',
|
|
'name' => ['ko' => '테스트', 'en' => 'Test'],
|
|
'variables' => [],
|
|
'channels' => ['mail', 'database'],
|
|
'hooks' => [],
|
|
'is_active' => true,
|
|
'is_default' => false,
|
|
]
|
|
);
|
|
|
|
foreach (['mail', 'database'] as $ch) {
|
|
NotificationTemplate::updateOrCreate(
|
|
['definition_id' => $this->definition->id, 'channel' => $ch],
|
|
[
|
|
'subject' => ['ko' => '제목', 'en' => 'Subject'],
|
|
'body' => ['ko' => '본문', 'en' => 'Body'],
|
|
'is_active' => true,
|
|
'is_default' => false,
|
|
]
|
|
);
|
|
}
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
NotificationTemplate::where('definition_id', $this->definition->id)->delete();
|
|
$this->definition->delete();
|
|
parent::tearDown();
|
|
}
|
|
|
|
private function notification(string $channel): GenericNotification
|
|
{
|
|
return new GenericNotification(
|
|
type: 'guest_gate_check',
|
|
hookPrefix: 'core.test',
|
|
data: [],
|
|
extensionType: 'core',
|
|
extensionIdentifier: 'core',
|
|
channel: $channel,
|
|
);
|
|
}
|
|
|
|
// ── isChannelGuestAllowed (config 기반) ──
|
|
|
|
public function test_channel_guest_allowed_reads_config(): void
|
|
{
|
|
$service = app(NotificationChannelService::class);
|
|
|
|
$this->assertTrue($service->isChannelGuestAllowed('mail'));
|
|
$this->assertFalse($service->isChannelGuestAllowed('database'));
|
|
// 미선언 채널은 기본 차단(false)
|
|
$this->assertFalse($service->isChannelGuestAllowed('nonexistent_channel'));
|
|
}
|
|
|
|
// ── via() 게스트 게이트 ──
|
|
|
|
public function test_guest_passes_mail_channel(): void
|
|
{
|
|
$guest = new GuestNotifiable('guest@example.com', '홍길동', 'ko');
|
|
|
|
$this->assertSame(['mail'], $this->notification('mail')->via($guest));
|
|
}
|
|
|
|
public function test_guest_blocked_on_database_channel(): void
|
|
{
|
|
$guest = new GuestNotifiable('guest@example.com', '홍길동', 'ko');
|
|
|
|
$this->assertSame([], $this->notification('database')->via($guest));
|
|
}
|
|
|
|
public function test_member_is_unaffected_by_guest_gate(): void
|
|
{
|
|
$member = User::factory()->make();
|
|
|
|
// 회원은 게스트 게이트 무영향 — database 채널도 정상 통과(템플릿 존재 + readiness)
|
|
$this->assertSame(['database'], $this->notification('database')->via($member));
|
|
}
|
|
}
|