Files
Gnuboard7/plugins/_bundled/sirsoft-gdpr/tests/Unit/Http/Resources/GdprUserConsentResourceTest.php
T
chym1217 1c6217f90d feat(gdpr): 마이페이지 쿠키 동의 관리 버튼 재설계
- 토글 스위치 → 상태 배지 + 동의/철회 버튼으로 재설계
 (user 템플릿 미해석 클래스로 인한 스타일 회귀 + "켜짐/꺼짐" 표현 개선)
- 동의 시에도 확인 모달 경유, 라벨에 "쿠키" 접미사, "모두 동의" 바
- 동의한 항목만 동의일 표시 (상태는 라벨 옆 배지가 표현)
- 카테고리 설명을 코드 기본값에서 조회 — 관리자 설정 화면에 설명 편집 UI가
 없어 라벨만 저장 시 설명이 유실되던 문제 해결
- 철회/동의 모달 버튼을 목록 버튼과 톤 맞춰 정리 (취소=테두리형)
- cookie_banner 운영주체 라인 admin 전용 클래스 → 공통 클래스 치환
2026-07-27 15:58:29 +09:00

125 lines
5.1 KiB
PHP

<?php
namespace Plugins\Sirsoft\Gdpr\Tests\Unit\Http\Resources;
use Illuminate\Http\Request;
use Plugins\Sirsoft\Gdpr\Http\Resources\GdprUserConsentResource;
use Plugins\Sirsoft\Gdpr\Models\GdprUserConsent;
use Plugins\Sirsoft\Gdpr\Tests\PluginTestCase;
/**
* 이슈 #430 — 마이페이지 「내 동의 현황」 각 행의 상태별 표시 필드
* (status / status_label / status_at_formatted) 계산을 검증한다.
*
* 프론트 레이아웃은 status 로 색만 분기하고 표시 텍스트·날짜는 서버가 계산한 값을 그대로 렌더하므로,
* 이 매핑이 상태별로 정확해야 화면 정보가 정확해진다.
*/
class GdprUserConsentResourceTest extends PluginTestCase
{
/**
* 주어진 동의 레코드를 Resource 배열로 변환합니다.
*
* @param GdprUserConsent $consent 대상 동의 레코드
* @return array<string, mixed>
*/
private function toArray(GdprUserConsent $consent): array
{
return (new GdprUserConsentResource($consent))->toArray(Request::create('/'));
}
public function test_required_category_maps_to_required_status_with_consented_date(): void
{
$consent = new GdprUserConsent([
'consent_key' => 'cookie_necessary',
'is_consented' => true,
'is_rejected' => false,
'consented_at' => '2026-07-14 09:00:00',
'policy_version' => '1',
]);
$result = $this->toArray($consent);
$this->assertSame('required', $result['status']);
// 필수는 '동의' 라벨을 granted 키로 공유.
$this->assertSame(__('sirsoft-gdpr::messages.mypage.privacy.status.granted'), $result['status_label']);
$this->assertNotNull($result['status_at_formatted']);
$this->assertSame(__('sirsoft-gdpr::messages.mypage.privacy.badge.required'), $result['status_badge_label']);
}
public function test_consented_optional_maps_to_consented_status_with_consented_date(): void
{
$consent = new GdprUserConsent([
'consent_key' => 'cookie_functional',
'is_consented' => true,
'is_rejected' => false,
'consented_at' => '2026-07-14 09:00:00',
'policy_version' => '1',
]);
$result = $this->toArray($consent);
$this->assertSame('consented', $result['status']);
$this->assertSame(__('sirsoft-gdpr::messages.mypage.privacy.status.consented'), $result['status_label']);
$this->assertNotNull($result['status_at_formatted']);
$this->assertSame(__('sirsoft-gdpr::messages.mypage.privacy.badge.consented'), $result['status_badge_label']);
}
public function test_rejected_optional_maps_to_rejected_status_with_no_date_label(): void
{
// PO 결정(2026-07-20) — 날짜/라벨은 "동의한 항목만" 노출. 거부는 상태만 rejected 로 내려주고
// status_label·status_at_formatted 는 null (프론트가 날짜 줄을 렌더하지 않음).
$consent = new GdprUserConsent([
'consent_key' => 'cookie_analytics',
'is_consented' => false,
'is_rejected' => true,
'rejected_at' => '2026-07-10 08:00:00',
'policy_version' => '1',
]);
$result = $this->toArray($consent);
$this->assertSame('rejected', $result['status']);
$this->assertNull($result['status_label']);
$this->assertNull($result['status_at_formatted']);
$this->assertSame(__('sirsoft-gdpr::messages.mypage.privacy.badge.rejected'), $result['status_badge_label']);
}
public function test_revoked_optional_maps_to_revoked_status_with_no_date_label(): void
{
// 철회도 거부와 동일 — 동의 상태가 아니므로 날짜/라벨 미노출.
$consent = new GdprUserConsent([
'consent_key' => 'cookie_marketing',
'is_consented' => false,
'is_rejected' => false,
'revoked_at' => '2026-07-12 07:00:00',
'policy_version' => '1',
]);
$result = $this->toArray($consent);
$this->assertSame('revoked', $result['status']);
$this->assertNull($result['status_label']);
$this->assertNull($result['status_at_formatted']);
// 철회는 신규 미선택과 함께 '미설정'(unset) 배지로 통합.
$this->assertSame(__('sirsoft-gdpr::messages.mypage.privacy.badge.unset'), $result['status_badge_label']);
}
public function test_new_untouched_optional_maps_to_none_with_null_label_and_date(): void
{
$consent = new GdprUserConsent([
'consent_key' => 'cookie_analytics',
'is_consented' => false,
'is_rejected' => false,
'policy_version' => '1',
]);
$result = $this->toArray($consent);
$this->assertSame('none', $result['status']);
// 신규 미선택은 라벨/날짜 모두 미노출 → 프론트가 날짜 줄 자체를 렌더하지 않음.
$this->assertNull($result['status_label']);
$this->assertNull($result['status_at_formatted']);
$this->assertSame(__('sirsoft-gdpr::messages.mypage.privacy.badge.unset'), $result['status_badge_label']);
}
}