v7.0.0 release

This commit is contained in:
HeuJung committed 2026-07-01 10:30:32 +09:00
1 parent 0e7fa04b03
commit c4ea9a6cd1
3582 files changed
+626189 -160151

No files matched your search

@@ -0,0 +1,114 @@
<?php
namespace Tests\Unit\Notifications;
use App\Models\NotificationDefinition;
use App\Models\NotificationTemplate;
use App\Notifications\GuestNotifiable;
use App\Notifications\GenericNotification;
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();
$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 = \App\Models\User::factory()->make();
// 회원은 게스트 게이트 무영향 — database 채널도 정상 통과(템플릿 존재 + readiness)
$this->assertSame(['database'], $this->notification('database')->via($member));
}
}
@@ -0,0 +1,96 @@
<?php
namespace Tests\Unit\Notifications;
use App\Contracts\Notifications\GuestRecipientInterface;
use App\Notifications\GuestNotifiable;
use Illuminate\Contracts\Translation\HasLocalePreference;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\App;
use Tests\TestCase;
/**
* GuestNotifiable 테스트
*
* 비회원 1급 수신자 값 객체의 계약(Notifiable + HasLocalePreference + GuestRecipientInterface),
* fromContext 유효성, 합성 키, 로케일 폴백을 검증합니다.
*/
class GuestNotifiableTest extends TestCase
{
public function test_implements_required_contracts(): void
{
$guest = new GuestNotifiable('guest@example.com', '홍길동', 'ko');
$this->assertInstanceOf(HasLocalePreference::class, $guest);
$this->assertInstanceOf(GuestRecipientInterface::class, $guest);
$this->assertContains(Notifiable::class, class_uses($guest));
$this->assertTrue($guest->isGuest());
}
public function test_from_context_builds_valid_recipient(): void
{
$guest = GuestNotifiable::fromContext([
'email' => 'guest@example.com',
'name' => '홍길동',
'locale' => 'ko',
]);
$this->assertNotNull($guest);
$this->assertSame('guest@example.com', $guest->email);
$this->assertSame('홍길동', $guest->name);
}
public function test_from_context_returns_null_for_empty_email(): void
{
$this->assertNull(GuestNotifiable::fromContext(['email' => '', 'name' => 'X']));
$this->assertNull(GuestNotifiable::fromContext(['name' => 'X']));
}
public function test_from_context_returns_null_for_invalid_email(): void
{
$this->assertNull(GuestNotifiable::fromContext(['email' => 'not-an-email']));
}
public function test_get_key_is_deterministic_and_case_insensitive(): void
{
$a = new GuestNotifiable('Guest@Example.com');
$b = new GuestNotifiable('guest@example.com');
$this->assertSame($a->getKey(), $b->getKey());
$this->assertStringStartsWith('guest:', $a->getKey());
}
public function test_route_notification_for_mail_uses_name_when_present(): void
{
$withName = new GuestNotifiable('guest@example.com', '홍길동');
$this->assertSame(['guest@example.com' => '홍길동'], $withName->routeNotificationForMail());
$withoutName = new GuestNotifiable('guest@example.com');
$this->assertSame('guest@example.com', $withoutName->routeNotificationForMail());
}
public function test_preferred_locale_returns_supported_locale(): void
{
$guest = new GuestNotifiable('guest@example.com', null, 'en');
$this->assertSame('en', $guest->preferredLocale());
}
public function test_preferred_locale_returns_null_for_unsupported_or_empty(): void
{
$this->assertNull((new GuestNotifiable('guest@example.com', null, 'xx'))->preferredLocale());
$this->assertNull((new GuestNotifiable('guest@example.com'))->preferredLocale());
}
public function test_resolve_notifiable_locale_falls_back_to_app_locale(): void
{
App::setLocale('en');
// locale 미지정 게스트 → preferredLocale() null → app locale 폴백
$guest = new GuestNotifiable('guest@example.com');
$this->assertSame('en', \App\Notifications\BaseNotification::resolveNotifiableLocale($guest));
// locale 지정 게스트 → 그 값 우선
$ko = new GuestNotifiable('guest@example.com', null, 'ko');
$this->assertSame('ko', \App\Notifications\BaseNotification::resolveNotifiableLocale($ko));
}
}