fix(core,admin_basic,board,ecommerce,page,gdpr,verification): 설정 미러·자동 정리·탈퇴 원자성·일괄 선택 범위 정비
공개이슈 ··· 및 그 전수 해소분. - 설정 저장·복원·초기화가 상주 프로세스 미러를 갱신하도록 단일 소유자화 - 만료 데이터 자동 정리 예약 12종 신설, 파기는 기본키 배치로 분할 - 회원 탈퇴를 전 경로 원자화하고 관리자 상태변경 경로를 정식 탈퇴로 통일 - 일괄 처리 목록의 선택을 화면에 보이는 행으로 한정(selectionScope) - 비밀번호 정책 문구를 도메인 중립 라벨로 정정 - 정적 검사 2종·검증 스킬 설계 정합성 축 신설
This commit is contained in:
1 parent
49c155509e
commit
4e1ec6e001
136 files changed
+7016
-504
No files matched your search
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Tests\Unit\Providers;
|
||||
|
||||
use App\Providers\SettingsServiceProvider;
|
||||
use App\Repositories\JsonConfigRepository;
|
||||
use App\Support\ExtensionSettingsMirror;
|
||||
use Carbon\Carbon;
|
||||
use ReflectionClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -56,13 +56,48 @@ class SettingsServiceProviderTest extends TestCase
|
||||
|
||||
/**
|
||||
* CORE_CATEGORIES에 seo 카테고리가 포함되어 봇 감지 설정이 로딩되는지 테스트합니다.
|
||||
*
|
||||
* 목록의 소유자는 ExtensionSettingsMirror 다 — Provider 에 사본을 두고 그 사본을
|
||||
* 단언하면, 미러의 목록에서 카테고리가 빠져도 이 테스트가 초록으로 남는다.
|
||||
*/
|
||||
public function test_seo_category_included_in_core_categories(): void
|
||||
{
|
||||
$reflection = new ReflectionClass(SettingsServiceProvider::class);
|
||||
$categories = $reflection->getConstant('CORE_CATEGORIES');
|
||||
$this->assertContains(
|
||||
'seo',
|
||||
ExtensionSettingsMirror::CORE_CATEGORIES,
|
||||
'CORE_CATEGORIES에 seo 카테고리가 포함되어야 합니다.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->assertContains('seo', $categories, 'CORE_CATEGORIES에 seo 카테고리가 포함되어야 합니다.');
|
||||
/**
|
||||
* CORE_CATEGORIES 가 실제로 미러에 채워지는 목록인지 테스트합니다.
|
||||
*
|
||||
* 이 단언이 없으면 위/아래의 상수 포함 검사는 "상수에 문자열이 있다" 만 증명한다.
|
||||
* 상수와 채움 동작이 실제로 이어져 있어야 그 검사에 회귀 차단 효력이 생긴다.
|
||||
*/
|
||||
public function test_core_categories_constant_is_what_the_mirror_fills(): void
|
||||
{
|
||||
$probe = new class extends JsonConfigRepository
|
||||
{
|
||||
/**
|
||||
* 어느 카테고리를 물어도 비어 있지 않은 값을 돌려준다 (채움 대상 판정용).
|
||||
*
|
||||
* @param string $category 카테고리명
|
||||
* @return array<string, mixed> 탐침 값
|
||||
*/
|
||||
public function getCategory(string $category): array
|
||||
{
|
||||
return ['__probe' => $category];
|
||||
}
|
||||
};
|
||||
|
||||
app(ExtensionSettingsMirror::class)->refreshCore($probe);
|
||||
|
||||
$this->assertSame(
|
||||
ExtensionSettingsMirror::CORE_CATEGORIES,
|
||||
array_keys(config('g7_settings.core')),
|
||||
'g7_settings.core 에 채워지는 카테고리가 CORE_CATEGORIES 와 일치해야 합니다.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,10 +120,11 @@ class SettingsServiceProviderTest extends TestCase
|
||||
*/
|
||||
public function test_identity_category_included_in_core_categories(): void
|
||||
{
|
||||
$reflection = new ReflectionClass(SettingsServiceProvider::class);
|
||||
$categories = $reflection->getConstant('CORE_CATEGORIES');
|
||||
|
||||
$this->assertContains('identity', $categories, 'CORE_CATEGORIES 에 identity 카테고리가 포함되어야 합니다.');
|
||||
$this->assertContains(
|
||||
'identity',
|
||||
ExtensionSettingsMirror::CORE_CATEGORIES,
|
||||
'CORE_CATEGORIES 에 identity 카테고리가 포함되어야 합니다.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Repositories;
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use App\Repositories\Concerns\DeletesInBatches;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 배치 삭제 트레이트 테스트
|
||||
*
|
||||
* 정리 예약은 도입 직후 첫 실행에서 이미 쌓여 있던 과거 데이터를 전부 지운다.
|
||||
* 한 문장으로 지우면 그 한 건이 테이블을 오래 잠그므로 배치로 끊어 지운다 —
|
||||
* 끊어 지우면서도 대상이 남김없이 사라지는지를 고정한다.
|
||||
*
|
||||
* @scenario row_age=beyond_retention
|
||||
*
|
||||
* @effects large_purge_is_split_into_batches
|
||||
*/
|
||||
class DeletesInBatchesTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* 배치 크기를 넘는 대상도 남김없이 삭제된다.
|
||||
*
|
||||
* 단일 배치만 처리하고 끝내는 구현이면 나머지가 남아 red 가 된다.
|
||||
*/
|
||||
public function test_deletes_every_matching_row_across_multiple_batches(): void
|
||||
{
|
||||
foreach (range(1, 7) as $i) {
|
||||
$log = ActivityLog::create([
|
||||
'log_type' => 'system',
|
||||
'action' => 'test.batch',
|
||||
'description' => "오래된 기록 {$i}",
|
||||
]);
|
||||
$log->forceFill(['created_at' => now()->subDays(400)])->saveQuietly();
|
||||
}
|
||||
|
||||
$deleted = $this->runner()->purge(
|
||||
ActivityLog::where('created_at', '<', now()->subDays(365))
|
||||
);
|
||||
|
||||
$this->assertSame(7, $deleted);
|
||||
$this->assertSame(0, ActivityLog::where('action', 'test.batch')->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* 조건 밖의 행은 배치가 몇 회전을 돌아도 건드리지 않는다.
|
||||
*/
|
||||
public function test_keeps_rows_outside_the_condition(): void
|
||||
{
|
||||
foreach (range(1, 5) as $i) {
|
||||
$old = ActivityLog::create([
|
||||
'log_type' => 'system',
|
||||
'action' => 'test.batch.old',
|
||||
'description' => "오래된 기록 {$i}",
|
||||
]);
|
||||
$old->forceFill(['created_at' => now()->subDays(400)])->saveQuietly();
|
||||
}
|
||||
|
||||
$recent = ActivityLog::create([
|
||||
'log_type' => 'system',
|
||||
'action' => 'test.batch.recent',
|
||||
'description' => '최근 기록',
|
||||
]);
|
||||
|
||||
$this->runner()->purge(
|
||||
ActivityLog::where('created_at', '<', now()->subDays(365))
|
||||
);
|
||||
|
||||
$this->assertDatabaseHas('activity_logs', ['id' => $recent->id]);
|
||||
$this->assertSame(0, ActivityLog::where('action', 'test.batch.old')->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* 대상이 없으면 0 을 돌려주고 끝난다 (무한 루프 방지).
|
||||
*/
|
||||
public function test_returns_zero_when_nothing_matches(): void
|
||||
{
|
||||
$deleted = $this->runner()->purge(
|
||||
ActivityLog::where('created_at', '<', now()->subDays(365))
|
||||
);
|
||||
|
||||
$this->assertSame(0, $deleted);
|
||||
}
|
||||
|
||||
/**
|
||||
* 배치 크기를 작게 잡은 실행기를 만듭니다.
|
||||
*
|
||||
* 기본 배치(1000)로는 여러 회전을 만들려면 그만큼 행을 쌓아야 해서,
|
||||
* 회전 자체를 검증하려면 크기를 줄이는 편이 정확하다.
|
||||
*
|
||||
* @return object purge(Builder): int 를 제공하는 실행기
|
||||
*/
|
||||
private function runner(): object
|
||||
{
|
||||
return new class
|
||||
{
|
||||
use DeletesInBatches;
|
||||
|
||||
/**
|
||||
* 조건에 맞는 행을 배치로 삭제합니다.
|
||||
*
|
||||
* 회전을 강제하려고 배치 크기를 2 로 낮춰 호출합니다.
|
||||
*
|
||||
* @param Builder $query 삭제 대상 쿼리
|
||||
* @return int 삭제된 건수
|
||||
*/
|
||||
public function purge(Builder $query): int
|
||||
{
|
||||
return $this->deleteInBatches($query, 2);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services;
|
||||
|
||||
use App\Enums\UserStatus;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Schema\Builder as SchemaBuilder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* User::withdraw() 익명화 규칙 단위 테스트 (공개이슈 #112)
|
||||
*
|
||||
* 서비스 계층의 원자성은 `tests/Feature/Api/Auth/WithdrawAtomicityTest.php` 가 다루고,
|
||||
* 여기서는 모델이 만드는 **익명화 값 자체**의 규칙을 고정한다 —
|
||||
* 접미사 형식·유일성·멱등·컬럼 길이 클램프.
|
||||
*
|
||||
* @scenario target_account=normal, target_account=already_withdrawn, field_length=exceeds_limit
|
||||
*
|
||||
* @effects suffix_includes_user_id_for_structural_uniqueness, long_values_truncated_within_column_limits, withdraw_is_idempotent
|
||||
*/
|
||||
class UserServiceWithdrawTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* 이메일 접미사는 날짜 + 사용자 ID 로 구성된다.
|
||||
*/
|
||||
public function test_email_suffix_contains_date_and_user_id(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2026-08-13 09:00:00'));
|
||||
|
||||
$user = User::factory()->create(['email' => 'suffix@example.com']);
|
||||
|
||||
$this->assertTrue($user->withdraw());
|
||||
|
||||
$this->assertSame('suffix@example.com_deleted_20260813_'.$user->id, $user->email);
|
||||
}
|
||||
|
||||
/**
|
||||
* 같은 날 같은 원본 이메일이어도 사용자마다 결과가 다르다 (구조적 유일).
|
||||
*/
|
||||
public function test_same_original_email_yields_distinct_anonymized_values(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2026-08-13 09:00:00'));
|
||||
|
||||
$first = User::factory()->create(['email' => 'dup@example.com']);
|
||||
$first->withdraw();
|
||||
|
||||
$second = User::factory()->create(['email' => 'dup@example.com']);
|
||||
$second->withdraw();
|
||||
|
||||
$this->assertNotSame($first->email, $second->email);
|
||||
}
|
||||
|
||||
/**
|
||||
* 이름·닉네임 접미사 규칙.
|
||||
*/
|
||||
public function test_name_and_nickname_suffixes(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2026-08-13 09:00:00'));
|
||||
|
||||
$user = User::factory()->create(['name' => '홍길동', 'nickname' => '길동이']);
|
||||
|
||||
$user->withdraw();
|
||||
|
||||
$this->assertSame('홍길동_탈퇴_20260813', $user->name);
|
||||
$this->assertSame('길동이_탈퇴', $user->nickname);
|
||||
}
|
||||
|
||||
/**
|
||||
* 닉네임이 없으면 접미사를 붙이지 않는다.
|
||||
*/
|
||||
public function test_null_nickname_is_left_untouched(): void
|
||||
{
|
||||
$user = User::factory()->create(['nickname' => null]);
|
||||
|
||||
$user->withdraw();
|
||||
|
||||
$this->assertNull($user->nickname);
|
||||
}
|
||||
|
||||
/**
|
||||
* 이미 탈퇴한 계정은 값이 변하지 않는다 (멱등).
|
||||
*/
|
||||
public function test_withdraw_is_idempotent(): void
|
||||
{
|
||||
$user = User::factory()->create(['email' => 'idem@example.com', 'nickname' => '닉']);
|
||||
|
||||
$user->withdraw();
|
||||
$snapshot = [$user->email, $user->name, $user->nickname, (string) $user->withdrawn_at];
|
||||
|
||||
$this->assertTrue($user->withdraw());
|
||||
|
||||
$this->assertSame($snapshot, [$user->email, $user->name, $user->nickname, (string) $user->withdrawn_at]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 컬럼 상한을 넘기지 않도록 원값 앞부분을 잘라 붙인다.
|
||||
*/
|
||||
public function test_values_are_clamped_to_column_limits(): void
|
||||
{
|
||||
$limit = SchemaBuilder::$defaultStringLength ?? 255;
|
||||
|
||||
$user = User::factory()->create([
|
||||
'email' => str_repeat('a', $limit - 12).'@example.com',
|
||||
'name' => str_repeat('나', $limit),
|
||||
'nickname' => str_repeat('다', User::NICKNAME_MAX_LENGTH),
|
||||
]);
|
||||
|
||||
$user->withdraw();
|
||||
|
||||
$this->assertSame($limit, mb_strlen($user->email));
|
||||
$this->assertSame($limit, mb_strlen($user->name));
|
||||
$this->assertSame(User::NICKNAME_MAX_LENGTH, mb_strlen($user->nickname));
|
||||
|
||||
// 잘렸어도 접미사는 온전히 남는다 (식별 규칙이 깨지면 안 된다)
|
||||
$this->assertStringEndsWith('_deleted_'.now()->format('Ymd').'_'.$user->id, $user->email);
|
||||
$this->assertStringEndsWith('_탈퇴', $user->nickname);
|
||||
}
|
||||
|
||||
/**
|
||||
* 상태·탈퇴 일시가 함께 기록된다.
|
||||
*/
|
||||
public function test_status_and_withdrawn_at_are_set(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$user->withdraw();
|
||||
|
||||
$this->assertSame(UserStatus::Withdrawn->value, $user->status);
|
||||
$this->assertNotNull($user->withdrawn_at);
|
||||
$this->assertTrue($user->isWithdrawn());
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Carbon::setTestNow();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user