공개 (답변 중복 등록)/(문의 삭제 시 답변 잔존) 수정과 동형 결함 전수 해소.
- 문의 답변 단일성: 1차(피벗 is_answered) + 2차(게시판 리스너 duplicate 마커) 이중 방어,
경합 경로에서도 사유(reply_already_exists 422)가 보존되도록 훅 반환 계약 확장
- 질문·답변·피벗 생명주기 대칭: 삭제/복원/영구삭제 훅 연동 + 고아 데이터 백필 업그레이드 스텝
- 게시판별 답글 삭제 정책(cascade/block) 신설, 정렬 화이트리스트·per_page 게이트
(전량 조회 소비처 200/999 를 수용하는 상한 999 — 조였다가 관리자 화면 2곳 422 회귀 즉시 정정)
- 결제/본인인증 플러그인 검증 계약: FormRequest 15종 승격 + 컨트롤러 catch 정합.
거래 조회 tid 상한은 저장 컬럼(varchar 100) 기준 — 해외 CBT TID(40자) 수용
- onError 토스트 고정 문구 전수 해소(67건/50파일/15확장) — 서버 실패 사유를 그대로 표면화,
change-password 오변수(response→error) 교정
- 코어 플러그인 설정 검증 안내의 항목 표시명이 스키마 라벨(ko/en) 폴백에 덮여 요청 로케일
(ja) 라벨을 잃던 회귀 정정 — 번역 등록이 있으면 그것을 우선 (7.0.7 미출시 기능 자체 결함)
- 사전 결함 정리(Icon 등가표 27·darkmode 2·validated 통일), API 문서·CHANGELOG·ja 팩 동기
- develop(60652fdc0) 리베이스: getTable 정비와 병합 — 양측 의도 보존 (충돌 18파일)
270 lines
11 KiB
PHP
270 lines
11 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Plugins\Sirsoft\PayKginicis\Tests\Feature\Controllers;
|
|
|
|
use App\Models\User;
|
|
use Modules\Sirsoft\Ecommerce\Database\Factories\OrderAddressFactory;
|
|
use Modules\Sirsoft\Ecommerce\Database\Factories\OrderFactory;
|
|
use Modules\Sirsoft\Ecommerce\Database\Factories\OrderPaymentFactory;
|
|
use Modules\Sirsoft\Ecommerce\Enums\PaymentMethodEnum;
|
|
use Modules\Sirsoft\Ecommerce\Enums\PaymentStatusEnum;
|
|
use Modules\Sirsoft\Ecommerce\Models\OrderPayment;
|
|
use Plugins\Sirsoft\PayKginicis\Services\KgInicisApiService;
|
|
use Plugins\Sirsoft\PayKginicis\Tests\PluginTestCase;
|
|
|
|
class AdminEscrowControllerTest extends PluginTestCase
|
|
{
|
|
private User $adminUser;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->adminUser = $this->createAdminUser(['sirsoft-ecommerce.orders.update']);
|
|
}
|
|
|
|
public function test_escrow_delivery_register_sanitizes_pg_response_before_storing(): void
|
|
{
|
|
$payment = $this->createEscrowPayment('ORD-ESCROW-DLV-001');
|
|
|
|
$mock = $this->createMock(KgInicisApiService::class);
|
|
$mock->expects($this->once())
|
|
->method('useEscrowCredentials')
|
|
->with(true);
|
|
$mock->expects($this->once())
|
|
->method('registerEscrowDelivery')
|
|
->willReturn([
|
|
'resultCode' => '00',
|
|
'resultMsg' => 'OK',
|
|
'tid' => $payment->transaction_id,
|
|
'recvName' => '홍길동',
|
|
'recvTel' => '010-1234-5678',
|
|
'recvAddr' => '서울시 강남구 비공개 주소',
|
|
]);
|
|
$this->app->instance(KgInicisApiService::class, $mock);
|
|
|
|
$response = $this->actingAs($this->adminUser)
|
|
->postJson('/api/plugins/sirsoft-pay_kginicis/admin/orders/ORD-ESCROW-DLV-001/escrow-delivery', [
|
|
'invoice' => 'INV-001',
|
|
'ex_code' => 'hanjin',
|
|
'recv_name' => '홍길동',
|
|
'recv_tel' => '010-1234-5678',
|
|
'recv_post' => '12345',
|
|
'recv_addr' => '서울시 강남구 비공개 주소',
|
|
]);
|
|
|
|
$response->assertOk()->assertJsonPath('success', true);
|
|
|
|
$payment->refresh();
|
|
$this->assertTrue($payment->payment_meta['pg_response_sanitized'] ?? false);
|
|
|
|
$storedPgResponse = $payment->payment_meta['escrow_delivery']['pg_response'] ?? [];
|
|
|
|
$this->assertSame('00', $storedPgResponse['resultCode'] ?? null);
|
|
$this->assertSame('OK', $storedPgResponse['resultMsg'] ?? null);
|
|
$this->assertArrayNotHasKey('recvName', $storedPgResponse);
|
|
$this->assertArrayNotHasKey('recvTel', $storedPgResponse);
|
|
$this->assertArrayNotHasKey('recvAddr', $storedPgResponse);
|
|
}
|
|
|
|
public function test_escrow_deny_confirm_sanitizes_pg_response_before_storing(): void
|
|
{
|
|
$payment = $this->createEscrowPayment('ORD-ESCROW-DNCF-001', [
|
|
'escrow_confirm' => ['type' => 'deny'],
|
|
]);
|
|
|
|
$mock = $this->createMock(KgInicisApiService::class);
|
|
$mock->expects($this->once())
|
|
->method('useEscrowCredentials')
|
|
->with(true);
|
|
$mock->expects($this->once())
|
|
->method('denyConfirmEscrow')
|
|
->willReturn([
|
|
'resultCode' => '00',
|
|
'resultMsg' => 'OK',
|
|
'originalTid' => $payment->transaction_id,
|
|
'dcnfName' => '관리자 이름',
|
|
'buyerName' => '홍길동',
|
|
'buyerTel' => '010-1234-5678',
|
|
]);
|
|
$this->app->instance(KgInicisApiService::class, $mock);
|
|
|
|
$response = $this->actingAs($this->adminUser)
|
|
->postJson('/api/plugins/sirsoft-pay_kginicis/admin/orders/ORD-ESCROW-DNCF-001/escrow-deny-confirm', [
|
|
'dcnf_name' => '관리자 이름',
|
|
]);
|
|
|
|
$response->assertOk()->assertJsonPath('success', true);
|
|
|
|
$payment->refresh();
|
|
$this->assertTrue($payment->payment_meta['pg_response_sanitized'] ?? false);
|
|
|
|
$storedPgResponse = $payment->payment_meta['escrow_deny_confirm']['pg_response'] ?? [];
|
|
|
|
$this->assertSame('00', $storedPgResponse['resultCode'] ?? null);
|
|
$this->assertSame('OK', $storedPgResponse['resultMsg'] ?? null);
|
|
$this->assertArrayNotHasKey('dcnfName', $storedPgResponse);
|
|
$this->assertArrayNotHasKey('buyerName', $storedPgResponse);
|
|
$this->assertArrayNotHasKey('buyerTel', $storedPgResponse);
|
|
}
|
|
|
|
/**
|
|
* 운송장번호 누락은 EscrowDeliveryRegisterRequest 가 표준 422 로 차단하고,
|
|
* 메시지는 다국어 키(escrow.invoice_required)의 ko 문구여야 한다
|
|
* (종전 컨트롤러 인라인 한글 하드코딩 → 다국어 키 이관 회귀 방지).
|
|
*/
|
|
public function test_escrow_delivery_register_rejects_missing_invoice_with_localized_message(): void
|
|
{
|
|
|
|
$this->createEscrowPayment('ORD-ESCROW-VAL-001');
|
|
|
|
$mock = $this->createMock(KgInicisApiService::class);
|
|
$mock->expects($this->never())->method('useEscrowCredentials');
|
|
$mock->expects($this->never())->method('registerEscrowDelivery');
|
|
$this->app->instance(KgInicisApiService::class, $mock);
|
|
|
|
$response = $this->actingAs($this->adminUser)
|
|
->withHeaders(['Accept-Language' => 'ko'])
|
|
->postJson('/api/plugins/sirsoft-pay_kginicis/admin/orders/ORD-ESCROW-VAL-001/escrow-delivery', [
|
|
'ex_code' => 'hanjin',
|
|
]);
|
|
|
|
$response->assertStatus(422)
|
|
->assertJsonValidationErrors(['invoice'])
|
|
->assertJsonPath('errors.invoice.0', '운송장번호를 입력해주세요.');
|
|
}
|
|
|
|
/**
|
|
* 코드표(COURIER_CODES) 밖의 택배사 코드는 Rule::in 이 422 로 차단해야 한다.
|
|
*/
|
|
public function test_escrow_delivery_register_rejects_unknown_courier_code(): void
|
|
{
|
|
|
|
$this->createEscrowPayment('ORD-ESCROW-VAL-002');
|
|
|
|
$mock = $this->createMock(KgInicisApiService::class);
|
|
$mock->expects($this->never())->method('registerEscrowDelivery');
|
|
$this->app->instance(KgInicisApiService::class, $mock);
|
|
|
|
$response = $this->actingAs($this->adminUser)
|
|
->withHeaders(['Accept-Language' => 'ko'])
|
|
->postJson('/api/plugins/sirsoft-pay_kginicis/admin/orders/ORD-ESCROW-VAL-002/escrow-delivery', [
|
|
'invoice' => 'INV-001',
|
|
'ex_code' => 'nope',
|
|
]);
|
|
|
|
$response->assertStatus(422)
|
|
->assertJsonValidationErrors(['ex_code'])
|
|
->assertJsonPath('errors.ex_code.0', '택배사를 선택해주세요.');
|
|
}
|
|
|
|
/**
|
|
* 수령인 필드 상한 초과(이름 31자 / 전화 21자 / 우편 11자 / 주소 201자)는
|
|
* KG 이니시스 연동 스펙 상한을 넘으므로 422 로 차단하고 PG 호출은 없어야 한다.
|
|
*/
|
|
public function test_escrow_delivery_register_rejects_overlong_recv_fields(): void
|
|
{
|
|
$this->createEscrowPayment('ORD-ESCROW-VAL-003');
|
|
|
|
$mock = $this->createMock(KgInicisApiService::class);
|
|
$mock->expects($this->never())->method('registerEscrowDelivery');
|
|
$this->app->instance(KgInicisApiService::class, $mock);
|
|
|
|
$response = $this->actingAs($this->adminUser)
|
|
->postJson('/api/plugins/sirsoft-pay_kginicis/admin/orders/ORD-ESCROW-VAL-003/escrow-delivery', [
|
|
'invoice' => 'INV-001',
|
|
'ex_code' => 'hanjin',
|
|
'recv_name' => str_repeat('가', 31),
|
|
'recv_tel' => str_repeat('0', 21),
|
|
'recv_post' => str_repeat('1', 11),
|
|
'recv_addr' => str_repeat('가', 201),
|
|
]);
|
|
|
|
$response->assertStatus(422)
|
|
->assertJsonValidationErrors([
|
|
'recv_name',
|
|
'recv_tel',
|
|
'recv_post',
|
|
'recv_addr',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 배열 주입(`dcnf_name[]=x`)은 EscrowDenyConfirmRequest 의 string 규칙이 422 로
|
|
* 차단하고 PG 구매거절확인 API 는 호출되지 않아야 한다.
|
|
*/
|
|
public function test_escrow_deny_confirm_rejects_array_dcnf_name(): void
|
|
{
|
|
$this->createEscrowPayment('ORD-ESCROW-DNCF-VAL-001', [
|
|
'escrow_confirm' => ['type' => 'deny'],
|
|
]);
|
|
|
|
$mock = $this->createMock(KgInicisApiService::class);
|
|
$mock->expects($this->never())->method('useEscrowCredentials');
|
|
$mock->expects($this->never())->method('denyConfirmEscrow');
|
|
$this->app->instance(KgInicisApiService::class, $mock);
|
|
|
|
$response = $this->actingAs($this->adminUser)
|
|
->postJson('/api/plugins/sirsoft-pay_kginicis/admin/orders/ORD-ESCROW-DNCF-VAL-001/escrow-deny-confirm', [
|
|
'dcnf_name' => ['x'],
|
|
]);
|
|
|
|
$response->assertStatus(422)
|
|
->assertJsonValidationErrors(['dcnf_name']);
|
|
}
|
|
|
|
/**
|
|
* 확인자명 상한(20자) 초과는 422 로 차단해야 한다 (이니시스 확인자명 20자 스펙).
|
|
*/
|
|
public function test_escrow_deny_confirm_rejects_overlong_dcnf_name(): void
|
|
{
|
|
$this->createEscrowPayment('ORD-ESCROW-DNCF-VAL-002', [
|
|
'escrow_confirm' => ['type' => 'deny'],
|
|
]);
|
|
|
|
$mock = $this->createMock(KgInicisApiService::class);
|
|
$mock->expects($this->never())->method('denyConfirmEscrow');
|
|
$this->app->instance(KgInicisApiService::class, $mock);
|
|
|
|
$response = $this->actingAs($this->adminUser)
|
|
->postJson('/api/plugins/sirsoft-pay_kginicis/admin/orders/ORD-ESCROW-DNCF-VAL-002/escrow-deny-confirm', [
|
|
'dcnf_name' => str_repeat('가', 21),
|
|
]);
|
|
|
|
$response->assertStatus(422)
|
|
->assertJsonValidationErrors(['dcnf_name']);
|
|
}
|
|
|
|
private function createEscrowPayment(string $orderNumber, array $paymentMeta = []): OrderPayment
|
|
{
|
|
$order = OrderFactory::new()->paid()->create([
|
|
'order_number' => $orderNumber,
|
|
'subtotal_amount' => 30000,
|
|
'total_amount' => 30000,
|
|
'total_paid_amount' => 30000,
|
|
'total_due_amount' => 0,
|
|
]);
|
|
|
|
OrderAddressFactory::new()->forOrder($order)->shipping()->create([
|
|
'recipient_name' => '홍길동',
|
|
'recipient_phone' => '010-1234-5678',
|
|
'zipcode' => '12345',
|
|
'address' => '서울시 강남구',
|
|
'address_detail' => '비공개 주소',
|
|
]);
|
|
|
|
return OrderPaymentFactory::new()->forOrder($order)->create([
|
|
'payment_status' => PaymentStatusEnum::PAID,
|
|
'payment_method' => PaymentMethodEnum::CARD,
|
|
'pg_provider' => 'kginicis',
|
|
'transaction_id' => 'INIMX_CARDINIpayTest20260623123456',
|
|
'paid_amount_local' => 30000,
|
|
'paid_amount_base' => 30000,
|
|
'is_escrow' => true,
|
|
'payment_meta' => $paymentMeta,
|
|
]);
|
|
}
|
|
}
|