관리자 환경설정이 값을 저장은 하지만 실제 동작에는 닿지 않던 결함군을 정리했다. 설정 화면(min/max)·저장 검증(FormRequest)·런타임 적용(Service) 세 계층이 각자 리터럴을 들고 있어 서로 조용히 갈라지던 것이 공통 원인이다. 경계값 SSoT 도입: - config/core.php `settings_limits` 를 단일 출처로 두고, FormRequest 는 이 값으로 규칙을 만들고 화면은 설정 응답의 `_meta.limits` 로 같은 값을 받아 바인딩한다. - 게시판·이커머스도 각 모듈 config 의 limits 를 동일 구조로 노출한다. 적용되지 않던 정책을 실제로 적용: - 비밀번호 최소 길이·특수문자 필수(신규 지정 7개 경로. 로그인은 제외 — 정책을 올렸을 때 기존 회원이 자기 계정에 접근조차 못 하는 데드락을 막기 위함) - 계정 잠금 시간 0 = 무한대(전용 컬럼 분리. timestamp 상한과 NULL 규약 때문에 기존 컬럼 재사용이 불가능하다) + 관리자 수동 해제 경로 - 업로드 최대 크기·허용 확장자, 게시판 첨부 개수·댓글 깊이, 페이지 첨부 정책, 장바구니 수량·구매 한도, 마일리지 사용 한도, 주문 부가세 파생 결함: - 큐 Job(sync 드라이버)이 진행 중인 요청의 Request 바인딩을 덮어써, 뒤이어 실행되는 훅 리스너가 헤더를 잃고 조용히 건너뛰었다. Job 이 원 바인딩을 복원하도록 고치고, 전송 헤더가 필요한 리스너는 동기 실행으로 선언한다. - 확장 업데이트 실패 시 상태만 되돌리고 상태 캐시를 비우지 않아, 그 확장의 관리자 화면만 캐시 TTL(기본 하루) 동안 404 로 남았다. 실패 경로에도 무효화를 대칭으로 두고, 빈 목록 자체를 캐시하지 않는다. - 글 작성 시 첨부 파일이 Service 로 전달되지 않아 검증·권한은 통과하고 첨부만 사라졌다. - 환경설정 저장 실패 안내가 내부 설정 키를 그대로 노출했다(105개 항목에 라벨 부여). 재발 방지: - audit 룰 3종(레이아웃 경계 리터럴 / FormRequest 경계 불일치 / Service 재클램프) - 테스트 실행 범위 강제 훅(check-test-scope) - 트러블슈팅 사례 2건(큐 Job 요청 오염 / 확장 상태 캐시 고착) 공개 이슈: gnuboard/g7
219 lines
8.3 KiB
PHP
219 lines
8.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\View;
|
|
|
|
use App\Enums\ExtensionStatus;
|
|
use App\Models\Template;
|
|
use App\Services\TemplateService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class AdminBladeTemplateLoadingTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
/**
|
|
* 각 테스트 전에 실행 (템플릿 설치 및 활성화)
|
|
*/
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// 코어 렌더링 엔진이 빌드되어 있는지 확인
|
|
$coreEnginePath = public_path('build/core/template-engine.min.js');
|
|
if (! file_exists($coreEnginePath)) {
|
|
$this->markTestSkipped('Core template engine not built. Run npm run build to generate build files.');
|
|
}
|
|
|
|
// sirsoft-admin_basic 템플릿 설치 및 활성화
|
|
$templateService = app(TemplateService::class);
|
|
|
|
try {
|
|
// 템플릿 설치
|
|
$templateService->installTemplate('sirsoft-admin_basic');
|
|
|
|
// 설치된 템플릿 조회
|
|
$template = Template::where('identifier', 'sirsoft-admin_basic')->first();
|
|
|
|
// 템플릿 활성화
|
|
if ($template) {
|
|
$templateService->activateTemplate($template->id);
|
|
}
|
|
} catch (\Exception $e) {
|
|
// 템플릿이 이미 설치되어 있거나 설치 실패 시 무시
|
|
// 테스트는 계속 진행됨
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 활성화된 템플릿이 있을 때 템플릿 번들이 로드되는지 테스트
|
|
*/
|
|
public function test_admin_blade_loads_template_bundles_when_active_template_exists(): void
|
|
{
|
|
// Arrange: setUp()에서 이미 sirsoft-admin_basic가 설치 및 활성화됨
|
|
// 추가 템플릿 생성 불필요
|
|
|
|
// Act: admin view 렌더링
|
|
$response = $this->get('/admin');
|
|
|
|
// Assert: 템플릿 번들 로딩 확인
|
|
$response->assertStatus(200);
|
|
|
|
// CSS 번들 로드 확인 (API를 통한 에셋 서빙)
|
|
$response->assertSee('/api/templates/assets/sirsoft-admin_basic/css/components.css?v=', false);
|
|
|
|
// JS 번들 로드 확인 (API를 통한 에셋 서빙)
|
|
$response->assertSee('/api/templates/assets/sirsoft-admin_basic/js/components.iife.js?v=', false);
|
|
|
|
// 코어 렌더링 엔진 로드 확인
|
|
$response->assertSee('/build/core/template-engine.min.js?v=', false);
|
|
|
|
// data-template-id 속성 확인
|
|
$response->assertSee('data-template-id="sirsoft-admin_basic"', false);
|
|
|
|
// 템플릿 엔진 초기화 스크립트 확인
|
|
// 초기화 설정은 @json 으로 직렬화된다 — 표기는 JSON 형태여야 한다.
|
|
$response->assertSee('"templateId":"sirsoft-admin_basic"', false);
|
|
}
|
|
|
|
/**
|
|
* 활성화된 템플릿이 없을 때 기본 템플릿 번들이 로드되는지 테스트
|
|
*/
|
|
public function test_admin_blade_loads_default_template_when_no_active_template(): void
|
|
{
|
|
// Arrange: 활성화된 템플릿 없음
|
|
Template::factory()->create([
|
|
'identifier' => 'inactive-template',
|
|
'type' => 'admin',
|
|
'status' => 'inactive',
|
|
]);
|
|
|
|
// Act: admin view 렌더링
|
|
$response = $this->get('/admin');
|
|
|
|
// Assert: 기본 템플릿 번들 로딩 확인
|
|
$response->assertStatus(200);
|
|
|
|
// CSS 번들 로드 확인 (API를 통한 에셋 서빙)
|
|
$response->assertSee('/api/templates/assets/sirsoft-admin_basic/css/components.css?v=', false);
|
|
|
|
// JS 번들 로드 확인 (API를 통한 에셋 서빙)
|
|
$response->assertSee('/api/templates/assets/sirsoft-admin_basic/js/components.iife.js?v=', false);
|
|
|
|
// 코어 렌더링 엔진 로드 확인
|
|
$response->assertSee('/build/core/template-engine.min.js?v=', false);
|
|
|
|
// data-template-id 속성에 기본값 확인
|
|
$response->assertSee('data-template-id="sirsoft-admin_basic"', false);
|
|
|
|
// 템플릿 엔진 초기화 스크립트에 기본값 확인
|
|
// 초기화 설정은 @json 으로 직렬화된다 — 표기는 JSON 형태여야 한다.
|
|
$response->assertSee('"templateId":"sirsoft-admin_basic"', false);
|
|
}
|
|
|
|
/**
|
|
* 템플릿이 전혀 없을 때도 페이지가 정상 렌더링되는지 테스트
|
|
*
|
|
* 활성화된 템플릿이 없으면 Fallback UI가 표시됩니다.
|
|
* Fallback UI에서는 코어 렌더링 엔진이 로드되지 않습니다.
|
|
*/
|
|
public function test_admin_blade_renders_without_any_template(): void
|
|
{
|
|
// Arrange: 모든 템플릿 비활성화
|
|
Template::query()->update(['status' => ExtensionStatus::Inactive->value]);
|
|
|
|
// Act: admin view 렌더링
|
|
$response = $this->get('/admin');
|
|
|
|
// Assert: 페이지가 정상적으로 렌더링됨
|
|
$response->assertStatus(200);
|
|
|
|
// 기본 구조 확인
|
|
$response->assertSee('<div id="app"', false);
|
|
|
|
// Fallback UI가 표시됨 (번역 키: templates.errors.no_active_template)
|
|
$response->assertSee('error-container', false);
|
|
// 활성 템플릿 없음 문구 — 한국어 또는 영어 번역 문자열 중 하나
|
|
$content = $response->getContent();
|
|
$this->assertTrue(
|
|
str_contains($content, '활성화된 템플릿이 없습니다')
|
|
|| str_contains($content, 'No active template found'),
|
|
'Fallback UI 에 no_active_template 번역 문자열이 포함되어야 함'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 코어 렌더링 엔진이 항상 로드되는지 테스트
|
|
*/
|
|
public function test_admin_blade_always_loads_core_rendering_engine(): void
|
|
{
|
|
// Act: admin view 렌더링
|
|
$response = $this->get('/admin');
|
|
|
|
// Assert: 코어 렌더링 엔진 로드 확인
|
|
$response->assertStatus(200);
|
|
|
|
// 코어 렌더링 엔진 스크립트 확인
|
|
$response->assertSee('/build/core/template-engine.min.js?v=', false);
|
|
|
|
// 기본 구조 확인
|
|
$response->assertSee('<div id="app"', false);
|
|
}
|
|
|
|
/**
|
|
* Font Awesome CDN이 로드되는지 테스트
|
|
*/
|
|
public function test_admin_blade_loads_font_awesome_cdn(): void
|
|
{
|
|
// Act: admin view 렌더링
|
|
$response = $this->get('/admin');
|
|
|
|
// Assert: Font Awesome CDN 확인
|
|
$response->assertStatus(200);
|
|
$response->assertSee('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css', false);
|
|
}
|
|
|
|
/**
|
|
* 템플릿 엔진 초기화 설정이 올바르게 전달되는지 테스트
|
|
*/
|
|
public function test_admin_blade_initializes_template_engine_with_correct_config(): void
|
|
{
|
|
// Arrange: setUp()에서 이미 sirsoft-admin_basic가 활성화됨
|
|
// 추가 설정 없이 기본 템플릿 사용
|
|
|
|
// Act: admin view 렌더링
|
|
$response = $this->get('/admin');
|
|
|
|
// Assert: 템플릿 엔진 초기화 설정 확인
|
|
$response->assertStatus(200);
|
|
// 초기화 설정은 @json 으로 직렬화된다 — 표기는 JSON 형태여야 한다.
|
|
$response->assertSee('"templateId":"sirsoft-admin_basic"', false);
|
|
$response->assertSee('"locale":', false); // locale 값은 테스트 환경에 따라 'en' 또는 'ko'일 수 있음
|
|
$response->assertSee('"debug":', false);
|
|
}
|
|
|
|
/**
|
|
* 브라우저 캐시 버스팅을 위한 버전 쿼리 파라미터가 추가되는지 테스트
|
|
*/
|
|
public function test_admin_blade_includes_cache_busting_version_parameters(): void
|
|
{
|
|
// Arrange: setUp()에서 이미 sirsoft-admin_basic가 설치 및 활성화됨
|
|
// 추가 템플릿 생성 불필요
|
|
|
|
// Act: admin view 렌더링
|
|
$response = $this->get('/admin');
|
|
|
|
// Assert: 모든 정적 파일에 버전 쿼리 파라미터가 있는지 확인
|
|
$response->assertStatus(200);
|
|
|
|
// 코어 엔진에 버전 파라미터
|
|
$response->assertSee('/build/core/template-engine.min.js?v=', false);
|
|
|
|
// 템플릿 CSS에 버전 파라미터 (API를 통한 에셋 서빙)
|
|
$response->assertSee('/api/templates/assets/sirsoft-admin_basic/css/components.css?v=', false);
|
|
|
|
// 템플릿 JS에 버전 파라미터 (API를 통한 에셋 서빙)
|
|
$response->assertSee('/api/templates/assets/sirsoft-admin_basic/js/components.iife.js?v=', false);
|
|
}
|
|
}
|