v7.0.0-beta.4 release
This commit is contained in:
1 parent
05db17887d
commit
1db039ff34
1545 files changed
+136783
-11634
No files matched your search
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Models;
|
||||
|
||||
use App\Enums\ActivityLogType;
|
||||
use App\Models\ActivityLog;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* ActivityLog::getActionLabelAttribute() 5단계 fallback 검증
|
||||
*
|
||||
* 모듈 lang 전체키 → 모듈 lang 마지막세그먼트 → 코어 lang 전체키
|
||||
* → 코어 lang 마지막세그먼트 → raw fallback 의 우선순위가 의도대로 동작하는지 회귀 차단.
|
||||
*/
|
||||
class ActivityLogActionLabelTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
App::setLocale('ko');
|
||||
}
|
||||
|
||||
/**
|
||||
* 1단계: loggable_type 으로부터 모듈 lang 의 전체 키 우선 매칭
|
||||
*/
|
||||
public function test_module_lang_full_key_takes_precedence_over_core_lang(): void
|
||||
{
|
||||
Lang::addNamespace('sirsoft-ecommerce', __DIR__);
|
||||
Lang::addLines([
|
||||
'activity_log.action.mileage.earn' => '마일리지 적립 (모듈)',
|
||||
], 'ko', 'sirsoft-ecommerce');
|
||||
Lang::addLines([
|
||||
'activity_log.action.mileage.earn' => '마일리지 적립 (코어)',
|
||||
], 'ko');
|
||||
|
||||
$log = ActivityLog::create([
|
||||
'log_type' => ActivityLogType::User,
|
||||
'action' => 'mileage.earn',
|
||||
'loggable_type' => 'Modules\\Sirsoft\\Ecommerce\\Models\\Order',
|
||||
'loggable_id' => 1,
|
||||
]);
|
||||
|
||||
$this->assertSame('마일리지 적립 (모듈)', $log->action_label);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2단계: 모듈 lang 의 마지막 세그먼트 매칭 (전체키 미정의)
|
||||
*/
|
||||
public function test_falls_back_to_module_last_segment_when_full_key_missing(): void
|
||||
{
|
||||
Lang::addNamespace('sirsoft-ecommerce', __DIR__);
|
||||
Lang::addLines([
|
||||
'activity_log.action.confirm' => '구매 확정 (모듈)',
|
||||
], 'ko', 'sirsoft-ecommerce');
|
||||
|
||||
$log = ActivityLog::create([
|
||||
'log_type' => ActivityLogType::User,
|
||||
'action' => 'order.confirm',
|
||||
'loggable_type' => 'Modules\\Sirsoft\\Ecommerce\\Models\\Order',
|
||||
'loggable_id' => 1,
|
||||
]);
|
||||
|
||||
$this->assertSame('구매 확정 (모듈)', $log->action_label);
|
||||
}
|
||||
|
||||
/**
|
||||
* 3단계: 코어 lang 의 전체 키 매칭 (모듈 lang 정의 없음)
|
||||
*/
|
||||
public function test_falls_back_to_core_full_key_when_module_lang_missing(): void
|
||||
{
|
||||
Lang::addLines([
|
||||
'activity_log.action.user.create' => '사용자 생성 전체키',
|
||||
], 'ko');
|
||||
|
||||
$log = ActivityLog::create([
|
||||
'log_type' => ActivityLogType::Admin,
|
||||
'action' => 'user.create',
|
||||
'loggable_type' => 'App\\Models\\User',
|
||||
'loggable_id' => 1,
|
||||
]);
|
||||
|
||||
$this->assertSame('사용자 생성 전체키', $log->action_label);
|
||||
}
|
||||
|
||||
/**
|
||||
* 4단계: 코어 lang 의 마지막 세그먼트 매칭
|
||||
*/
|
||||
public function test_falls_back_to_core_last_segment(): void
|
||||
{
|
||||
$log = ActivityLog::create([
|
||||
'log_type' => ActivityLogType::Admin,
|
||||
'action' => 'user.create',
|
||||
'loggable_type' => 'App\\Models\\User',
|
||||
'loggable_id' => 1,
|
||||
]);
|
||||
|
||||
// 코어 lang/ko/activity_log.php 의 'create' => '생성'
|
||||
$this->assertSame('생성', $log->action_label);
|
||||
}
|
||||
|
||||
/**
|
||||
* 5단계: raw action 문자열 fallback (어디에도 정의 없음)
|
||||
*/
|
||||
public function test_returns_raw_action_when_no_lang_match(): void
|
||||
{
|
||||
$log = ActivityLog::create([
|
||||
'log_type' => ActivityLogType::System,
|
||||
'action' => 'unknown.bizarre_segment_xyz',
|
||||
]);
|
||||
|
||||
$this->assertSame('unknown.bizarre_segment_xyz', $log->action_label);
|
||||
}
|
||||
|
||||
/**
|
||||
* loggable_type 미지정 + properties.extension_origin 으로 origin 추론
|
||||
*/
|
||||
public function test_resolves_origin_from_properties_extension_origin_when_loggable_missing(): void
|
||||
{
|
||||
Lang::addNamespace('sirsoft-ecommerce', __DIR__);
|
||||
Lang::addLines([
|
||||
'activity_log.action.mileage.expire' => '마일리지 소멸 (모듈)',
|
||||
], 'ko', 'sirsoft-ecommerce');
|
||||
|
||||
$log = ActivityLog::create([
|
||||
'log_type' => ActivityLogType::System,
|
||||
'action' => 'mileage.expire',
|
||||
'loggable_type' => null,
|
||||
'loggable_id' => null,
|
||||
'properties' => ['extension_origin' => 'sirsoft-ecommerce'],
|
||||
]);
|
||||
|
||||
$this->assertSame('마일리지 소멸 (모듈)', $log->action_label);
|
||||
}
|
||||
|
||||
/**
|
||||
* 코어 origin 라벨이 모듈 변경에도 회귀 없이 동작 (하위 호환)
|
||||
*/
|
||||
public function test_core_origin_action_label_unchanged_after_introduction(): void
|
||||
{
|
||||
$log = ActivityLog::create([
|
||||
'log_type' => ActivityLogType::Admin,
|
||||
'action' => 'auth.login',
|
||||
'loggable_type' => 'App\\Models\\User',
|
||||
'loggable_id' => 1,
|
||||
]);
|
||||
|
||||
$this->assertSame('로그인', $log->action_label);
|
||||
}
|
||||
}
|
||||
@@ -82,8 +82,7 @@ class BoardModelTest extends TestCase
|
||||
'max_file_count' => 5,
|
||||
'allowed_extensions' => ['jpg', 'png', 'pdf'],
|
||||
'comment_order' => 'ASC',
|
||||
'board_manager_id' => null,
|
||||
'notify_author_on_comment' => false,
|
||||
'notify_author' => false,
|
||||
'notify_admin_on_post' => false,
|
||||
'blocked_keywords' => ['금지어1', '금지어2'],
|
||||
];
|
||||
@@ -182,6 +181,8 @@ class BoardModelTest extends TestCase
|
||||
|
||||
/**
|
||||
* boolean 필드가 정상적으로 캐스팅되는지 테스트
|
||||
*
|
||||
* 참고: `notify_author_on_comment` 은 `notify_author` 로 필드 리네임됨 (모듈 리팩토링)
|
||||
*/
|
||||
public function test_boolean_fields_are_cast_correctly(): void
|
||||
{
|
||||
@@ -194,7 +195,7 @@ class BoardModelTest extends TestCase
|
||||
'use_reply' => true,
|
||||
'use_report' => false,
|
||||
'use_file_upload' => true,
|
||||
'notify_author_on_comment' => false,
|
||||
'notify_author' => false,
|
||||
'notify_admin_on_post' => true,
|
||||
]);
|
||||
|
||||
@@ -205,29 +206,13 @@ class BoardModelTest extends TestCase
|
||||
$this->assertTrue($board->use_reply);
|
||||
$this->assertFalse($board->use_report);
|
||||
$this->assertTrue($board->use_file_upload);
|
||||
$this->assertFalse($board->notify_author_on_comment);
|
||||
$this->assertFalse($board->notify_author);
|
||||
$this->assertTrue($board->notify_admin_on_post);
|
||||
}
|
||||
|
||||
/**
|
||||
* boardManager 관계 테스트
|
||||
*/
|
||||
public function test_belongs_to_board_manager(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->create();
|
||||
|
||||
// Act
|
||||
$board = $this->createBoard([
|
||||
'name' => ['ko' => '게시판'],
|
||||
'slug' => 'test-board',
|
||||
'board_manager_id' => $user->id,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$this->assertInstanceOf(User::class, $board->boardManager);
|
||||
$this->assertEquals($user->id, $board->boardManager->id);
|
||||
}
|
||||
// 참고: `board_manager_id` 컬럼 및 `boardManager()` 관계는
|
||||
// 모듈 리팩토링으로 제거됨 (게시판 매니저는 Role/Permission 기반으로 이행).
|
||||
// 따라서 `test_belongs_to_board_manager` 는 삭제됨.
|
||||
|
||||
/**
|
||||
* creator 관계 테스트
|
||||
@@ -360,20 +345,27 @@ class BoardModelTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* guarded 속성 테스트 (created_by, updated_by)
|
||||
* created_by / updated_by 가 fillable 로 설정되어 명시 할당 시 저장된다.
|
||||
*
|
||||
* Board model 은 created_by/updated_by 를 $fillable 에 포함해
|
||||
* 서비스 계층에서 명시적으로 제공할 수 있도록 설계됨.
|
||||
* (auto-fill trait 은 부재 — 서비스에서 Auth::id() 등 책임 주입)
|
||||
*/
|
||||
public function test_created_by_and_updated_by_are_guarded(): void
|
||||
public function test_created_by_and_updated_by_are_fillable(): void
|
||||
{
|
||||
// Arrange: FK 제약 통과를 위해 실제 User 생성
|
||||
$creator = \App\Models\User::factory()->create();
|
||||
|
||||
// Act
|
||||
$board = $this->createBoard([
|
||||
'name' => ['ko' => '게시판'],
|
||||
'slug' => 'test-board',
|
||||
'created_by' => 999, // guarded이므로 무시되어야 함
|
||||
'updated_by' => 999, // guarded이므로 무시되어야 함
|
||||
'created_by' => $creator->id,
|
||||
'updated_by' => $creator->id,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$this->assertNull($board->created_by);
|
||||
$this->assertNull($board->updated_by);
|
||||
$this->assertSame($creator->id, $board->created_by);
|
||||
$this->assertSame($creator->id, $board->updated_by);
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,8 @@ class HasUserOverridesMassUpdateTest extends TestCase
|
||||
|
||||
$this->assertSame(['ko' => '사용자 수정'], $reloaded->name);
|
||||
$this->assertIsArray($reloaded->user_overrides);
|
||||
$this->assertContains('name', $reloaded->user_overrides, 'mass update 시에도 trackable 필드가 user_overrides 에 자동 기록');
|
||||
// 7.0.0-beta.4+ 다국어 컬럼은 sub-key dot-path 단위 기록
|
||||
$this->assertContains('name.ko', $reloaded->user_overrides, 'mass update 시에도 다국어 sub-key 가 user_overrides 에 자동 기록');
|
||||
}
|
||||
|
||||
public function test_mass_update_accumulates_overrides_across_multiple_edits(): void
|
||||
@@ -69,7 +70,7 @@ class HasUserOverridesMassUpdateTest extends TestCase
|
||||
|
||||
$reloaded = NotificationDefinition::find($definition->id);
|
||||
|
||||
$this->assertContains('name', $reloaded->user_overrides);
|
||||
$this->assertContains('name.ko', $reloaded->user_overrides);
|
||||
$this->assertContains('is_active', $reloaded->user_overrides, '여러 번의 mass update 가 누적 기록');
|
||||
}
|
||||
|
||||
@@ -101,8 +102,8 @@ class HasUserOverridesMassUpdateTest extends TestCase
|
||||
$reloadedA = NotificationDefinition::find($a->id);
|
||||
$reloadedB = NotificationDefinition::find($b->id);
|
||||
|
||||
$this->assertContains('name', $reloadedA->user_overrides ?? []);
|
||||
$this->assertContains('name', $reloadedB->user_overrides ?? []);
|
||||
$this->assertContains('name.ko', $reloadedA->user_overrides ?? []);
|
||||
$this->assertContains('name.ko', $reloadedB->user_overrides ?? []);
|
||||
}
|
||||
|
||||
public function test_seeder_context_bypasses_tracking_on_mass_update(): void
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Models\Concerns;
|
||||
|
||||
use App\Models\Menu;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* HasUserOverrides Trait 의 다국어 JSON 컬럼 sub-key dot-path 추적/보존 검증.
|
||||
*
|
||||
* 7.0.0-beta.4 신규 정책:
|
||||
* - $translatableTrackableFields 에 정의된 다국어 JSON 컬럼은 sub-key 단위로 추적
|
||||
* - 사용자가 ko 만 수정 → user_overrides=['name.ko']
|
||||
* - 시더 재실행 시 ko 만 보존, 신규 locale 키(en/ja) 는 자동 동기화
|
||||
* - 일반 scalar 필드 (icon, order 등) 는 컬럼 단위 추적 (기존 동작)
|
||||
*
|
||||
* Menu 모델을 reference 로 사용 — name(translatable JSON) + icon/order/url(scalar) 혼합.
|
||||
*/
|
||||
class HasUserOverridesSubKeyTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function createMenu(array $attributes = []): Menu
|
||||
{
|
||||
return Menu::create(array_merge([
|
||||
'name' => ['ko' => '초기 메뉴', 'en' => 'Initial Menu'],
|
||||
'slug' => 'test-menu-'.uniqid(),
|
||||
'url' => '/test',
|
||||
'icon' => 'home',
|
||||
'order' => 0,
|
||||
'is_active' => true,
|
||||
], $attributes));
|
||||
}
|
||||
|
||||
/** 시나리오 1: 다국어 컬럼 ko 만 수정 → user_overrides=['name.ko'] */
|
||||
public function test_translatable_subkey_ko_only_modification_records_dot_path(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
|
||||
$menu->name = ['ko' => '수정된 메뉴', 'en' => 'Initial Menu'];
|
||||
$menu->save();
|
||||
|
||||
$this->assertEquals(['name.ko'], $menu->fresh()->user_overrides);
|
||||
}
|
||||
|
||||
/** 시나리오 2: ko, en 동시 수정 → user_overrides=['name.ko', 'name.en'] */
|
||||
public function test_translatable_subkey_multiple_locales_modification(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
|
||||
$menu->name = ['ko' => '수정 ko', 'en' => 'Modified EN'];
|
||||
$menu->save();
|
||||
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['name.ko', 'name.en'],
|
||||
$menu->fresh()->user_overrides
|
||||
);
|
||||
}
|
||||
|
||||
/** 시나리오 3: ko 보존 + ja 신규 추가 (시더 재실행 시) — 사용자 ko 보존, ja 자동 동기화 */
|
||||
public function test_sync_from_upgrade_preserves_overridden_subkey_only(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
$menu->name = ['ko' => '사용자 수정 ko', 'en' => 'Initial Menu'];
|
||||
$menu->save();
|
||||
|
||||
// 시더가 ja 포함 신규 데이터로 재실행
|
||||
$menu->syncFromUpgrade([
|
||||
'name' => ['ko' => '시더 ko', 'en' => 'Seeder EN', 'ja' => 'シーダー JA'],
|
||||
]);
|
||||
|
||||
$fresh = $menu->fresh();
|
||||
$this->assertEquals('사용자 수정 ko', $fresh->name['ko']); // ko 보존
|
||||
$this->assertEquals('Seeder EN', $fresh->name['en']); // en 갱신
|
||||
$this->assertEquals('シーダー JA', $fresh->name['ja']); // ja 자동 추가
|
||||
}
|
||||
|
||||
/** 시나리오 4: 사용자 미수정 시 시더 재실행이 전체 갱신 */
|
||||
public function test_sync_from_upgrade_full_replace_when_no_user_overrides(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
|
||||
$menu->syncFromUpgrade([
|
||||
'name' => ['ko' => '시더 ko', 'en' => 'Seeder EN', 'ja' => 'シーダー JA'],
|
||||
]);
|
||||
|
||||
$fresh = $menu->fresh();
|
||||
$this->assertEquals(['ko' => '시더 ko', 'en' => 'Seeder EN', 'ja' => 'シーダー JA'], $fresh->name);
|
||||
$this->assertNull($fresh->user_overrides);
|
||||
}
|
||||
|
||||
/** 시나리오 5: legacy 컬럼명 user_overrides=['name'] → 전체 컬럼 보존 (역호환) */
|
||||
public function test_sync_from_upgrade_legacy_column_level_override_preserved(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
// 마이그레이션 전 형식 시뮬레이션
|
||||
$menu->update(['user_overrides' => ['name']]);
|
||||
|
||||
$menu->syncFromUpgrade([
|
||||
'name' => ['ko' => '시더 ko', 'en' => 'Seeder EN', 'ja' => 'シーダー JA'],
|
||||
]);
|
||||
|
||||
$fresh = $menu->fresh();
|
||||
$this->assertEquals(['ko' => '초기 메뉴', 'en' => 'Initial Menu'], $fresh->name);
|
||||
}
|
||||
|
||||
/** 시나리오 6: scalar 필드 (icon) 수정 → 컬럼명 단위 기록 (기존 동작) */
|
||||
public function test_scalar_trackable_field_records_column_name(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
|
||||
$menu->icon = 'changed-icon';
|
||||
$menu->save();
|
||||
|
||||
$this->assertEquals(['icon'], $menu->fresh()->user_overrides);
|
||||
}
|
||||
|
||||
/** 시나리오 7: scalar + translatable 동시 수정 → 두 형식 혼재 */
|
||||
public function test_mixed_scalar_and_translatable_modification(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
|
||||
$menu->icon = 'new-icon';
|
||||
$menu->name = ['ko' => '수정 ko', 'en' => 'Initial Menu'];
|
||||
$menu->save();
|
||||
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['icon', 'name.ko'],
|
||||
$menu->fresh()->user_overrides
|
||||
);
|
||||
}
|
||||
|
||||
/** 시나리오 8: scalar 필드는 syncFromUpgrade 시 user_overrides 등록 시 갱신 SKIP (기존 동작 회귀 없음) */
|
||||
public function test_sync_from_upgrade_preserves_scalar_overridden_field(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
$menu->icon = 'user-icon';
|
||||
$menu->save();
|
||||
|
||||
$menu->syncFromUpgrade([
|
||||
'icon' => 'seeder-icon',
|
||||
'order' => 99,
|
||||
]);
|
||||
|
||||
$fresh = $menu->fresh();
|
||||
$this->assertEquals('user-icon', $fresh->icon); // 보존
|
||||
$this->assertEquals(99, $fresh->order); // 갱신
|
||||
}
|
||||
|
||||
/** 시나리오 9: 시더가 일부 locale 만 제공 + 사용자 보존 locale 누락 시 사용자 값 유지 */
|
||||
public function test_sync_from_upgrade_keeps_user_locale_when_seeder_omits_it(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
$menu->name = ['ko' => '사용자 ko', 'en' => 'Initial Menu'];
|
||||
$menu->save();
|
||||
|
||||
// 시더가 ja 만 제공 (ko 누락)
|
||||
$menu->syncFromUpgrade([
|
||||
'name' => ['ja' => 'シーダー JA'],
|
||||
]);
|
||||
|
||||
$fresh = $menu->fresh();
|
||||
$this->assertEquals('사용자 ko', $fresh->name['ko']);
|
||||
$this->assertEquals('シーダー JA', $fresh->name['ja']);
|
||||
}
|
||||
|
||||
/** 시나리오 10: mass update 경로에서도 sub-key dot-path 자동 추적 */
|
||||
public function test_mass_update_records_subkey_overrides(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
|
||||
Menu::where('id', $menu->id)->update([
|
||||
'name' => ['ko' => '대량 수정 ko', 'en' => 'Initial Menu'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(['name.ko'], $menu->fresh()->user_overrides);
|
||||
}
|
||||
|
||||
/** 시나리오 11: 동일 sub-key 반복 수정 시 user_overrides 중복 없음 */
|
||||
public function test_repeated_subkey_modification_no_duplicate(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
|
||||
$menu->name = ['ko' => '첫 수정', 'en' => 'Initial Menu'];
|
||||
$menu->save();
|
||||
$menu->name = ['ko' => '두 번째 수정', 'en' => 'Initial Menu'];
|
||||
$menu->save();
|
||||
|
||||
$this->assertEquals(['name.ko'], $menu->fresh()->user_overrides);
|
||||
}
|
||||
|
||||
/** 시나리오 12: 다른 locale 추가 수정 시 누적 */
|
||||
public function test_subsequent_locale_modification_accumulates(): void
|
||||
{
|
||||
$menu = $this->createMenu();
|
||||
|
||||
$menu->name = ['ko' => '수정 ko', 'en' => 'Initial Menu'];
|
||||
$menu->save();
|
||||
|
||||
$menu->name = ['ko' => '수정 ko', 'en' => 'Modified EN'];
|
||||
$menu->save();
|
||||
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['name.ko', 'name.en'],
|
||||
$menu->fresh()->user_overrides
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Models;
|
||||
|
||||
use App\Models\IdentityMessageDefinition;
|
||||
use App\Models\IdentityMessageTemplate;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* IdentityMessageTemplate 모델 단위 테스트.
|
||||
*
|
||||
* 다국어 fallback, replaceVariables, user_overrides 보존을 격리 검증.
|
||||
*/
|
||||
class IdentityMessageTemplateTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private IdentityMessageDefinition $definition;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->definition = IdentityMessageDefinition::create([
|
||||
'provider_id' => 'g7:core.mail',
|
||||
'scope_type' => IdentityMessageDefinition::SCOPE_PURPOSE,
|
||||
'scope_value' => 'signup',
|
||||
'name' => ['ko' => '회원가입 인증', 'en' => 'Signup Verification'],
|
||||
'channels' => ['mail'],
|
||||
'extension_type' => 'core',
|
||||
'extension_identifier' => 'core',
|
||||
'is_active' => true,
|
||||
'is_default' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_localized_subject_returns_current_locale(): void
|
||||
{
|
||||
$template = $this->makeTemplate([
|
||||
'subject' => ['ko' => '한글 제목', 'en' => 'English Subject'],
|
||||
'body' => ['ko' => '한글 본문', 'en' => 'English body'],
|
||||
]);
|
||||
|
||||
$this->assertSame('한글 제목', $template->getLocalizedSubject('ko'));
|
||||
$this->assertSame('English Subject', $template->getLocalizedSubject('en'));
|
||||
}
|
||||
|
||||
public function test_localized_subject_falls_back_to_ko_then_en(): void
|
||||
{
|
||||
$template = $this->makeTemplate([
|
||||
'subject' => ['ko' => '한글만'],
|
||||
'body' => ['ko' => '본문'],
|
||||
]);
|
||||
|
||||
$this->assertSame('한글만', $template->getLocalizedSubject('en'));
|
||||
$this->assertSame('한글만', $template->getLocalizedSubject('ja'));
|
||||
}
|
||||
|
||||
public function test_replace_variables_substitutes_placeholders(): void
|
||||
{
|
||||
$template = $this->makeTemplate([
|
||||
'subject' => ['ko' => '[{app_name}] 인증 코드', 'en' => '[{app_name}] Code'],
|
||||
'body' => ['ko' => '코드: {code} (만료 {expire_minutes}분)', 'en' => 'Code: {code} ({expire_minutes}m)'],
|
||||
]);
|
||||
|
||||
$rendered = $template->replaceVariables(
|
||||
['app_name' => '테스트사이트', 'code' => '987654', 'expire_minutes' => 10],
|
||||
'ko'
|
||||
);
|
||||
|
||||
$this->assertSame('[테스트사이트] 인증 코드', $rendered['subject']);
|
||||
$this->assertSame('코드: 987654 (만료 10분)', $rendered['body']);
|
||||
$this->assertStringNotContainsString('{code}', $rendered['body']);
|
||||
}
|
||||
|
||||
public function test_replace_variables_skips_null_values_safely(): void
|
||||
{
|
||||
$template = $this->makeTemplate([
|
||||
'subject' => ['ko' => '코드: {code}', 'en' => 'Code: {code}'],
|
||||
'body' => ['ko' => '링크: {action_url}', 'en' => 'Link: {action_url}'],
|
||||
]);
|
||||
|
||||
// text_code 흐름이라 action_url=null. 본문에 {action_url} 잔여 허용 (운영자가 본문 수정 시 의도 가시화).
|
||||
$rendered = $template->replaceVariables(
|
||||
['code' => '111222', 'action_url' => null],
|
||||
'ko'
|
||||
);
|
||||
|
||||
$this->assertSame('코드: 111222', $rendered['subject']);
|
||||
$this->assertStringContainsString('{action_url}', $rendered['body'], 'null 값은 치환에서 제외되어 잔여 토큰이 유지되어야 합니다.');
|
||||
}
|
||||
|
||||
public function test_user_overrides_records_field_change_outside_seeder(): void
|
||||
{
|
||||
$template = $this->makeTemplate([
|
||||
'subject' => ['ko' => '원본', 'en' => 'Original'],
|
||||
'body' => ['ko' => '본문', 'en' => 'Body'],
|
||||
]);
|
||||
|
||||
$template->update(['subject' => ['ko' => '변경됨', 'en' => 'Changed']]);
|
||||
$template->refresh();
|
||||
|
||||
$this->assertContains('subject', $template->user_overrides ?? []);
|
||||
}
|
||||
|
||||
public function test_user_overrides_skips_recording_in_seeder_context(): void
|
||||
{
|
||||
app()->instance('user_overrides.seeding', true);
|
||||
|
||||
try {
|
||||
$template = $this->makeTemplate([
|
||||
'subject' => ['ko' => '원본', 'en' => 'Original'],
|
||||
'body' => ['ko' => '본문', 'en' => 'Body'],
|
||||
]);
|
||||
|
||||
$template->update(['subject' => ['ko' => '시드재실행', 'en' => 'Reseed']]);
|
||||
$template->refresh();
|
||||
|
||||
$this->assertEmpty(
|
||||
$template->user_overrides ?? [],
|
||||
'시더 컨텍스트에서는 user_overrides 가 기록되지 않아야 합니다.'
|
||||
);
|
||||
} finally {
|
||||
app()->forgetInstance('user_overrides.seeding');
|
||||
}
|
||||
}
|
||||
|
||||
public function test_active_scope_filters_inactive_templates(): void
|
||||
{
|
||||
$this->makeTemplate(['subject' => ['ko' => 'A'], 'body' => ['ko' => 'a'], 'is_active' => true]);
|
||||
|
||||
IdentityMessageTemplate::create([
|
||||
'definition_id' => $this->definition->id,
|
||||
'channel' => 'sms',
|
||||
'subject' => ['ko' => 'B'],
|
||||
'body' => ['ko' => 'b'],
|
||||
'is_active' => false,
|
||||
'is_default' => true,
|
||||
]);
|
||||
|
||||
$this->assertSame(1, IdentityMessageTemplate::active()->count());
|
||||
$this->assertSame(1, IdentityMessageTemplate::active()->byChannel('mail')->count());
|
||||
$this->assertSame(0, IdentityMessageTemplate::active()->byChannel('sms')->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* 헬퍼 — 기본 템플릿 생성.
|
||||
*/
|
||||
private function makeTemplate(array $overrides = []): IdentityMessageTemplate
|
||||
{
|
||||
return IdentityMessageTemplate::create(array_merge([
|
||||
'definition_id' => $this->definition->id,
|
||||
'channel' => 'mail',
|
||||
'subject' => ['ko' => '제목', 'en' => 'Subject'],
|
||||
'body' => ['ko' => '본문', 'en' => 'Body'],
|
||||
'is_active' => true,
|
||||
'is_default' => true,
|
||||
], $overrides));
|
||||
}
|
||||
}
|
||||
@@ -41,9 +41,18 @@ class ProductLabelAssignmentTest extends TestCase
|
||||
$this->markTestSkipped('sirsoft-ecommerce 모듈이 설치되어 있지 않습니다.');
|
||||
}
|
||||
|
||||
// 모듈 마이그레이션 실행
|
||||
// 모듈 마이그레이션 실행 — 활성 디렉토리 우선, 부재 시 _bundled 로 폴백
|
||||
$activeMigrationPath = base_path('modules/sirsoft-ecommerce/database/migrations');
|
||||
$bundledMigrationPath = base_path('modules/_bundled/sirsoft-ecommerce/database/migrations');
|
||||
|
||||
$migrationPath = is_dir($activeMigrationPath) ? $activeMigrationPath : $bundledMigrationPath;
|
||||
|
||||
if (! is_dir($migrationPath)) {
|
||||
$this->markTestSkipped('sirsoft-ecommerce 마이그레이션 디렉토리를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$this->artisan('migrate', [
|
||||
'--path' => 'modules/sirsoft-ecommerce/database/migrations',
|
||||
'--path' => $migrationPath,
|
||||
'--realpath' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user