Files
Gnuboard7/plugins/_bundled/sirsoft-message_bizppurio/tests/Unit/Services/AlimtalkPayloadMapperTest.php
T
chym1217 4e77d25926 feat(message_bizppurio): 검수 모드 라벨 통일 + 발송 payload 저장 + 알림톡 URL 프로토콜 중복 방지
발송 이력 화면의 "테스트 모드" 표기를 "검수 모드"로 통일하고, 검수 모드 발송 건은
상태 라벨 대신 "검수" 라벨로 표시한다. 설정 미완료 상태에서도 검수 모드 안내가
함께 표시되도록 배너 노출 조건을 수정한다.

발송 요청 payload가 어디에도 저장되지 않아 실패 원인을 사후 재구성할 수 없던 문제를
해결한다. bizppurio_dispatches.request_payload 컬럼을 신설해 발송 시점(성공/실패
무관)에 실제 비즈뿌리오 전송 payload를 저장하되, 다른 컬럼과 중복되는 개인식별
정보(수신번호·치환된 본문 텍스트)는 제외하고 저장한다.

카카오 알림톡 버튼 URL과 완전한 URL 변수(action_url 등, 항상 프로토콜 포함)가
결합될 때 프로토콜이 중복(https://https://...)되어 잘못된 링크로 발송되던 문제를
방지한다.

플러그인 제거 후 재설치 시 sms·alimtalk 채널 템플릿이 재생성되지 않던 문제를
해결한다. 리스너 등록 이력 캐시가 재활성화 후에도 남아있어 재등록이 조용히
스킵되던 것으로, 코어 수정 없이 플러그인 내부에서 리플렉션으로 우회한다.
2026-07-28 12:40:15 +09:00

276 lines
11 KiB
PHP

<?php
namespace Plugins\Sirsoft\MessageBizppurio\Tests\Unit\Services;
use Plugins\Sirsoft\MessageBizppurio\Services\AlimtalkPayloadMapper;
use Plugins\Sirsoft\MessageBizppurio\Tests\PluginTestCase;
/**
* AlimtalkPayloadMapper — 카카오 상세조회 응답 → 발송 API content.at 변환 + 변수 치환 검증 (B안 5-2).
*
* 카카오 관리 API 필드(templateContent/buttons.linkMo/…)를 발송 API 필드
* (message/button.url_mobile/…)로 변환하고, 각 필드의 #{var} 를 알림 data 로 치환한다.
* 빈/부재 필드는 payload 에 넣지 않는다(방어적).
*/
class AlimtalkPayloadMapperTest extends PluginTestCase
{
private function mapper(): AlimtalkPayloadMapper
{
return new AlimtalkPayloadMapper;
}
public function test_본문의_변수를_치환해_message로_반환한다(): void
{
$result = $this->mapper()->map(
['templateContent' => '#{name}님 주문 #{order_no} 완료'],
['name' => '홍길동', 'order_no' => 'A123'],
);
$this->assertSame('홍길동님 주문 A123 완료', $result['message']);
}
public function test_웹링크_버튼을_발송형식으로_변환하고_url변수를_치환한다(): void
{
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'buttons' => [
[
'name' => '주문조회',
'linkType' => 'WL',
'linkMo' => 'https://m.shop/orders/#{order_no}',
'linkPc' => 'https://shop/orders/#{order_no}',
],
],
],
['order_no' => 'A123'],
);
$button = $result['extra']['button'][0];
$this->assertSame('주문조회', $button['name']);
$this->assertSame('WL', $button['type']);
$this->assertSame('https://m.shop/orders/A123', $button['url_mobile']);
$this->assertSame('https://shop/orders/A123', $button['url_pc']);
// 카카오 필드명(linkType/linkMo)은 발송 payload 에 남지 않아야 한다.
$this->assertArrayNotHasKey('linkType', $button);
$this->assertArrayNotHasKey('linkMo', $button);
}
public function test_앱링크_전화_플러그인_버튼_필드를_매핑한다(): void
{
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'buttons' => [
['name' => '앱', 'linkType' => 'AL', 'linkAnd' => 'myapp://a', 'linkIos' => 'myapp://i'],
['name' => '전화', 'linkType' => 'TN', 'telNumber' => '1588-0000'],
['name' => '플러그인', 'linkType' => 'P1', 'pluginId' => 'PLUG_1'],
],
],
[],
);
$buttons = $result['extra']['button'];
$this->assertSame('myapp://a', $buttons[0]['scheme_android']);
$this->assertSame('myapp://i', $buttons[0]['scheme_ios']);
$this->assertSame('1588-0000', $buttons[1]['tel_number']);
$this->assertSame('PLUG_1', $buttons[2]['plugin_id']);
}
public function test_quick_replies를_quickreply로_변환한다(): void
{
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'quickReplies' => [
['name' => '바로가기', 'linkType' => 'WL', 'linkMo' => 'https://m.shop'],
],
],
[],
);
$qr = $result['extra']['quickreply'][0];
$this->assertSame('바로가기', $qr['name']);
$this->assertSame('WL', $qr['type']);
$this->assertSame('https://m.shop', $qr['url_mobile']);
}
public function test_title_header를_치환해_매핑한다(): void
{
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'templateTitle' => '#{name}님',
'templateHeader' => '주문 안내',
],
['name' => '홍길동'],
);
$this->assertSame('홍길동님', $result['extra']['title']);
$this->assertSame('주문 안내', $result['extra']['header']);
}
public function test_item과_itemhighlight를_매핑하고_치환한다(): void
{
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'templateItem' => [
'list' => [
['title' => '상품', 'description' => '#{product}'],
],
'summary' => ['title' => '합계', 'description' => '#{total}원'],
],
'templateItemHighlight' => ['title' => '#{name}님', 'description' => '주문완료'],
],
['product' => '티셔츠', 'total' => '20,000', 'name' => '홍길동'],
);
$this->assertSame('티셔츠', $result['extra']['item']['list'][0]['description']);
$this->assertSame('20,000원', $result['extra']['item']['summary']['description']);
$this->assertSame('홍길동님', $result['extra']['itemhighlight']['title']);
}
public function test_대표링크를_link로_변환하고_치환한다(): void
{
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'templateRepresentLink' => [
'linkMo' => 'https://m.shop/#{id}',
'linkPc' => 'https://shop/#{id}',
],
],
['id' => 'X1'],
);
$this->assertSame('https://m.shop/X1', $result['extra']['link']['url_mobile']);
$this->assertSame('https://shop/X1', $result['extra']['link']['url_pc']);
}
public function test_원문에_프로토콜_접두어가_있고_변수값도_완전url이면_중복을_제거한다(): void
{
// 결함② — 카카오 콘솔에 `http://#{action_url}` 로 등록된 버튼. action_url 자체가
// config('app.url') 기반 완전 URL(https://...)이라 단순 치환 시 프로토콜이 중복된다.
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'buttons' => [
['name' => '로그인하기', 'linkType' => 'WL', 'linkMo' => 'http://#{action_url}'],
],
],
['action_url' => 'https://ehkim.gnuboard.net/login'],
);
$this->assertSame(
'https://ehkim.gnuboard.net/login',
$result['extra']['button'][0]['url_mobile'],
'원문 접두어(http://)를 제거해 프로토콜 중복(http://https://...)을 방지해야 한다.',
);
}
public function test_원문_접두어가_https이고_변수값도_https이면_중복을_제거한다(): void
{
// 실제 카카오 콘솔 등록값(관리자 화면 상세조회 스크린샷 확인, 2026-07-24) —
// "회원가입 환영" 템플릿 버튼이 http:// 가 아니라 https://#{action_url} 로 등록돼 있다.
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'buttons' => [
['name' => '로그인하기', 'linkType' => 'WL', 'linkMo' => 'https://#{action_url}'],
],
],
['action_url' => 'https://ehkim.gnuboard.net/login'],
);
$this->assertSame(
'https://ehkim.gnuboard.net/login',
$result['extra']['button'][0]['url_mobile'],
'원문 접두어가 https:// 인 경우도 동일하게 중복(https://https://...)을 방지해야 한다.',
);
}
public function test_원문에_프로토콜_접두어가_없으면_변수값을_그대로_둔다(): void
{
// 가이드 문서 원안(#{action_url} 만 등록)대로면 애초에 중복이 없으므로 손대지 않는다.
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'buttons' => [
['name' => '로그인하기', 'linkType' => 'WL', 'linkMo' => '#{action_url}'],
],
],
['action_url' => 'https://ehkim.gnuboard.net/login'],
);
$this->assertSame('https://ehkim.gnuboard.net/login', $result['extra']['button'][0]['url_mobile']);
}
public function test_원문_접두어가_있어도_변수값이_상대경로면_접두어를_유지한다(): void
{
// 변수값 자체가 프로토콜을 포함하지 않는 경우(상대경로 등) 접두어는 진짜로 필요한
// 부분이므로 제거하면 안 된다.
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'buttons' => [
['name' => '이동', 'linkType' => 'WL', 'linkMo' => 'http://#{path}'],
],
],
['path' => '/foo'],
);
$this->assertSame('http:///foo', $result['extra']['button'][0]['url_mobile']);
}
public function test_대표링크도_프로토콜_중복을_제거한다(): void
{
// mapLinkFields(대표링크)도 mapButtons 와 동일 규칙을 공유해야 한다.
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'templateRepresentLink' => ['linkMo' => 'http://#{action_url}'],
],
['action_url' => 'https://ehkim.gnuboard.net/login'],
);
$this->assertSame('https://ehkim.gnuboard.net/login', $result['extra']['link']['url_mobile']);
}
public function test_변수가_data에_없으면_원문을_유지한다(): void
{
// data 에 없는 변수는 원문(#{key}) 유지 정책 — 프로토콜 중복 방어 로직이 이 정책을
// 깨서는 안 된다(원문이 http:// 로 시작하지만 치환 자체가 안 일어나므로 그대로 둔다).
$result = $this->mapper()->map(
[
'templateContent' => '본문',
'buttons' => [
['name' => '로그인하기', 'linkType' => 'WL', 'linkMo' => 'http://#{unknown_var}'],
],
],
[],
);
$this->assertSame('http://#{unknown_var}', $result['extra']['button'][0]['url_mobile']);
}
public function test_부재_필드는_extra에_넣지_않는다(): void
{
// 본문만 있는 단순 템플릿 → extra 는 비어야 한다.
$result = $this->mapper()->map(['templateContent' => '본문'], []);
$this->assertSame('본문', $result['message']);
$this->assertSame([], $result['extra']);
}
public function test_빈_버튼배열은_extra에_button을_만들지_않는다(): void
{
$result = $this->mapper()->map(
['templateContent' => '본문', 'buttons' => []],
[],
);
$this->assertArrayNotHasKey('button', $result['extra']);
}
}