v7.0.0-beta.1 release

This commit is contained in:
HeuJung committed 2026-04-01 10:30:52 +09:00
commit 6595fd0eb5
3967 files changed
+1875383

No files matched your search

@@ -0,0 +1,455 @@
<?php
namespace Tests\Unit\Requests\Ecommerce;
use Illuminate\Support\Facades\App;
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\StoreEcommerceSettingsRequest;
use Tests\TestCase;
/**
* StoreEcommerceSettingsRequest 커스텀 검증 테스트
*
* withValidator 메서드의 커스텀 검증 로직을 테스트합니다.
* - 통화 코드 중복 검증
* - 통화명 필수 검증 (최소 하나의 로케일)
*/
class StoreEcommerceSettingsRequestCustomValidationTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
// 한국어 로케일 설정
App::setLocale('ko');
}
/**
* FormRequest를 통한 검증 수행 (커스텀 로직 포함)
*
* @param array $data 검증할 데이터
*
* @return \Illuminate\Validation\Validator
*/
protected function validateWithCustomRules(array $data): \Illuminate\Validation\Validator
{
$request = new StoreEcommerceSettingsRequest();
$request->merge($data);
$validator = \Illuminate\Support\Facades\Validator::make($data, $request->rules());
// withValidator 메서드 실행
$request->withValidator($validator);
return $validator;
}
/**
* 통화 코드 중복 - 중복된 코드가 있으면 실패
*/
public function test_duplicate_currency_codes_fail_validation(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => ['ko' => '원'],
],
[
'code' => 'KRW', // 중복
'name' => ['ko' => '원 (중복)'],
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('language_currency.currencies.1.code', $validator->errors()->toArray());
}
/**
* 통화 코드 중복 - 대소문자 무시하여 중복 검출
*/
public function test_duplicate_currency_codes_case_insensitive(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => ['ko' => '원'],
],
[
'code' => 'krw', // 소문자로 중복
'name' => ['ko' => '원 (소문자)'],
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('language_currency.currencies.1.code', $validator->errors()->toArray());
}
/**
* 통화 코드 중복 - 고유한 코드들은 통과
*/
public function test_unique_currency_codes_pass_validation(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => ['ko' => '원'],
],
[
'code' => 'USD',
'name' => ['ko' => '달러'],
],
[
'code' => 'JPY',
'name' => ['ko' => '엔'],
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertFalse($validator->fails());
}
/**
* 통화명 필수 - 빈 배열이면 실패
*/
public function test_empty_currency_name_array_fails_validation(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => [], // 빈 배열
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('language_currency.currencies.0.name', $validator->errors()->toArray());
}
/**
* 통화명 필수 - name이 없으면 실패
*/
public function test_missing_currency_name_fails_validation(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
// name 필드 누락
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('language_currency.currencies.0.name', $validator->errors()->toArray());
}
/**
* 통화명 필수 - 모든 로케일이 빈 문자열이면 실패
*/
public function test_all_empty_locale_names_fail_validation(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => [
'ko' => '',
'en' => '',
],
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('language_currency.currencies.0.name', $validator->errors()->toArray());
}
/**
* 통화명 필수 - 모든 로케일이 공백만 있으면 실패
*/
public function test_whitespace_only_locale_names_fail_validation(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => [
'ko' => ' ',
'en' => "\t\n",
],
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('language_currency.currencies.0.name', $validator->errors()->toArray());
}
/**
* 통화명 필수 - 하나의 로케일에만 이름이 있으면 통과
*/
public function test_single_locale_name_passes_validation(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => [
'ko' => '원',
// en은 없음
],
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertFalse($validator->fails());
}
/**
* 통화명 필수 - 일부 로케일만 비어있어도 다른 로케일에 값이 있으면 통과
*/
public function test_partial_locale_names_pass_validation(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => [
'ko' => '원',
'en' => '', // 빈 문자열이지만 ko에 값이 있음
],
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertFalse($validator->fails());
}
/**
* 통화명 필수 - 여러 통화 중 일부만 문제가 있는 경우
*/
public function test_mixed_valid_invalid_currencies(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => ['ko' => '원'], // 유효
],
[
'code' => 'USD',
'name' => [], // 무효 - 빈 배열
],
[
'code' => 'JPY',
'name' => ['ko' => '엔'], // 유효
],
[
'code' => 'EUR',
'name' => ['ko' => '', 'en' => ''], // 무효 - 모두 빈 문자열
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertTrue($validator->fails());
$errors = $validator->errors()->toArray();
// 인덱스 1과 3에서 오류 발생
$this->assertArrayHasKey('language_currency.currencies.1.name', $errors);
$this->assertArrayHasKey('language_currency.currencies.3.name', $errors);
// 인덱스 0과 2는 오류 없음
$this->assertArrayNotHasKey('language_currency.currencies.0.name', $errors);
$this->assertArrayNotHasKey('language_currency.currencies.2.name', $errors);
}
/**
* 통화 목록이 비어있으면 커스텀 검증 건너뜀
*/
public function test_empty_currencies_array_skips_custom_validation(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [],
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertFalse($validator->fails());
}
/**
* 통화 설정이 없으면 커스텀 검증 건너뜀
*/
public function test_missing_currencies_skips_custom_validation(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'default_language' => 'ko',
],
];
$validator = $this->validateWithCustomRules($data);
$this->assertFalse($validator->fails());
}
/**
* 오류 메시지가 다국어로 표시되는지 확인
*
* 빈 배열이 아닌 모든 로케일이 빈 문자열인 경우 테스트
* (빈 배열은 기본 required_with 검증에서 먼저 잡힘)
*/
public function test_error_messages_are_localized(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => ['ko' => '', 'en' => ''], // 모든 로케일이 빈 문자열
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$errors = $validator->errors()->toArray();
$this->assertStringContainsString(
'최소 하나의 언어로 입력',
$errors['language_currency.currencies.0.name'][0]
);
}
/**
* 중복 코드 오류 메시지가 다국어로 표시되는지 확인
*/
public function test_duplicate_code_error_message_is_localized(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => ['ko' => '원'],
],
[
'code' => 'KRW',
'name' => ['ko' => '원 중복'],
],
],
],
];
$validator = $this->validateWithCustomRules($data);
$errors = $validator->errors()->toArray();
$this->assertStringContainsString(
'중복된 통화 코드',
$errors['language_currency.currencies.1.code'][0]
);
}
}
@@ -0,0 +1,416 @@
<?php
namespace Tests\Unit\Requests\Ecommerce;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Validator;
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\StoreEcommerceSettingsRequest;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;
/**
* StoreEcommerceSettingsRequest 검증 테스트
*
* 이커머스 설정 저장 요청의 검증 로직을 테스트합니다.
*/
class StoreEcommerceSettingsRequestTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
// 한국어 로케일 설정
App::setLocale('ko');
}
/**
* FormRequest의 규칙으로 검증 수행
*
* @param array $data 검증할 데이터
*
* @return \Illuminate\Validation\Validator
*/
protected function createValidator(array $data): \Illuminate\Validation\Validator
{
$request = new StoreEcommerceSettingsRequest();
return Validator::make($data, $request->rules());
}
/**
* 기본 정보 - 쇼핑몰명 필수 검증
*/
public function test_shop_name_is_required(): void
{
$data = [
'basic_info' => [
'shop_name' => '',
'route_path' => 'shop',
],
];
$validator = $this->createValidator($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('basic_info.shop_name', $validator->errors()->toArray());
}
/**
* 기본 정보 - 쇼핑몰명 정상 입력
*/
public function test_shop_name_passes_with_valid_data(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
];
$validator = $this->createValidator($data);
$this->assertFalse($validator->fails());
}
/**
* 기본 정보 - 라우트 경로 필수 (no_route가 false일 때)
*/
public function test_route_path_required_when_no_route_is_false(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => '',
'no_route' => false,
],
];
$validator = $this->createValidator($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('basic_info.route_path', $validator->errors()->toArray());
}
/**
* 기본 정보 - 라우트 경로 불필요 (no_route가 true일 때)
*/
public function test_route_path_not_required_when_no_route_is_true(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => '',
'no_route' => true,
],
];
$validator = $this->createValidator($data);
$this->assertFalse($validator->fails());
}
/**
* 통화 설정 - 통화 코드 필수
*/
public function test_currency_code_is_required(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => '',
'name' => ['ko' => '원'],
'exchange_rate' => 1,
],
],
],
];
$validator = $this->createValidator($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('language_currency.currencies.0.code', $validator->errors()->toArray());
}
/**
* 통화 설정 - 통화명 배열 필수
*/
public function test_currency_name_must_be_array(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => '원', // 배열이 아닌 문자열
'exchange_rate' => 1,
],
],
],
];
$validator = $this->createValidator($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('language_currency.currencies.0.name', $validator->errors()->toArray());
}
/**
* 통화 설정 - 반올림 방식 유효성 검증
*/
public function test_rounding_method_must_be_valid(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => ['ko' => '원'],
'rounding_method' => 'invalid', // 잘못된 값
],
],
],
];
$validator = $this->createValidator($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('language_currency.currencies.0.rounding_method', $validator->errors()->toArray());
}
/**
* 통화 설정 - 유효한 반올림 방식 통과
*/
#[DataProvider('validRoundingMethodsProvider')]
public function test_valid_rounding_methods_pass(string $method): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'KRW',
'name' => ['ko' => '원'],
'rounding_method' => $method,
],
],
],
];
$validator = $this->createValidator($data);
$this->assertFalse($validator->fails());
}
/**
* 유효한 반올림 방식 데이터 프로바이더
*
* @return array<string, array<string>>
*/
public static function validRoundingMethodsProvider(): array
{
return [
'floor' => ['floor'],
'round' => ['round'],
'ceil' => ['ceil'],
];
}
/**
* 통화 설정 - 환율은 숫자여야 함
*/
public function test_exchange_rate_must_be_numeric(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'USD',
'name' => ['ko' => '달러'],
'exchange_rate' => 'not-a-number',
],
],
],
];
$validator = $this->createValidator($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('language_currency.currencies.0.exchange_rate', $validator->errors()->toArray());
}
/**
* 통화 설정 - 환율은 0 이상이어야 함
*/
public function test_exchange_rate_must_be_positive(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'language_currency' => [
'currencies' => [
[
'code' => 'USD',
'name' => ['ko' => '달러'],
'exchange_rate' => -1,
],
],
],
];
$validator = $this->createValidator($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('language_currency.currencies.0.exchange_rate', $validator->errors()->toArray());
}
/**
* 개인정보 책임자 이메일 형식 검증
*/
public function test_privacy_officer_email_must_be_valid_email(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
'privacy_officer_email' => 'invalid-email',
],
];
$validator = $this->createValidator($data);
$this->assertTrue($validator->fails());
$this->assertArrayHasKey('basic_info.privacy_officer_email', $validator->errors()->toArray());
}
/**
* SEO 설정 - 유효한 데이터 통과
*/
public function test_seo_settings_with_valid_data(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'seo' => [
'meta_main_title' => '{site_name} - {commerce_name}',
'meta_main_description' => '최고의 쇼핑몰입니다.',
'seo_site_main' => true,
'seo_user_agents' => ['Googlebot', 'Bingbot'],
],
];
$validator = $this->createValidator($data);
$this->assertFalse($validator->fails());
}
/**
* SEO 설정 - seo_user_agents 규칙은 코어로 이관되어 검증하지 않음
*/
public function test_seo_user_agents_is_no_longer_validated(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
],
'seo' => [
'seo_user_agents' => 'Googlebot', // 코어로 이관됨 — 이커머스에서 검증 안 함
],
];
$validator = $this->createValidator($data);
// seo_user_agents 규칙이 제거되었으므로 검증 통과해야 함
$this->assertFalse($validator->fails());
}
/**
* 전체 유효한 설정 데이터 통과
*/
public function test_complete_valid_settings_pass(): void
{
$data = [
'basic_info' => [
'shop_name' => '테스트 쇼핑몰',
'route_path' => 'shop',
'no_route' => false,
'company_name' => '테스트 회사',
'business_number_1' => '123',
'business_number_2' => '45',
'business_number_3' => '67890',
'ceo_name' => '홍길동',
'business_type' => '소매업',
'business_category' => '전자상거래',
'zipcode' => '12345',
'base_address' => '서울시 강남구',
'detail_address' => '테스트 빌딩 101호',
'phone_1' => '02',
'phone_2' => '1234',
'phone_3' => '5678',
'email_id' => 'test',
'email_domain' => 'example.com',
'privacy_officer' => '김철수',
'privacy_officer_email' => 'privacy@example.com',
],
'language_currency' => [
'default_language' => 'ko',
'default_currency' => 'KRW',
'currencies' => [
[
'code' => 'KRW',
'name' => ['ko' => '원', 'en' => 'Won'],
'exchange_rate' => null,
'rounding_unit' => '1',
'rounding_method' => 'floor',
'is_default' => true,
],
[
'code' => 'USD',
'name' => ['ko' => '달러', 'en' => 'Dollar'],
'exchange_rate' => 0.00085,
'rounding_unit' => '0.01',
'rounding_method' => 'round',
'is_default' => false,
],
],
],
'seo' => [
'meta_main_title' => '{site_name} - {commerce_name}',
'meta_main_description' => '최고의 쇼핑몰',
'seo_site_main' => true,
'seo_category' => true,
'seo_search_result' => true,
'seo_product_detail' => true,
'seo_user_agents' => ['Googlebot', 'Bingbot'],
],
];
$validator = $this->createValidator($data);
$this->assertFalse($validator->fails());
}
}
@@ -0,0 +1,135 @@
<?php
namespace Tests\Unit\Requests;
use App\Http\Requests\Public\Module\ServeModuleAssetRequest;
use App\Rules\AllowedModuleFileType;
use App\Rules\SafeModulePath;
use Tests\TestCase;
class ServeModuleAssetRequestTest extends TestCase
{
/**
* authorize()가 항상 true를 반환하는지 테스트
*/
public function test_authorize_returns_true(): void
{
$request = new ServeModuleAssetRequest();
$this->assertTrue($request->authorize());
}
/**
* 검증 규칙이 올바르게 정의되어 있는지 테스트
*/
public function test_has_correct_validation_rules(): void
{
$request = new ServeModuleAssetRequest();
// 라우트 파라미터 시뮬레이션
$request->setRouteResolver(function () use ($request) {
$route = new \Illuminate\Routing\Route('GET', 'api/modules/assets/{identifier}/{path}', []);
$route->bind($request);
$route->setParameter('identifier', 'test-module');
$route->setParameter('path', 'dist/js/module.iife.js');
return $route;
});
$rules = $request->rules();
$this->assertArrayHasKey('identifier', $rules);
$this->assertArrayHasKey('path', $rules);
$this->assertContains('required', $rules['identifier']);
$this->assertContains('string', $rules['identifier']);
$this->assertContains('required', $rules['path']);
$this->assertContains('string', $rules['path']);
}
/**
* SafeModulePath Rule이 포함되어 있는지 테스트
*/
public function test_includes_safe_path_rule(): void
{
$request = new ServeModuleAssetRequest();
// 라우트 파라미터 시뮬레이션
$request->setRouteResolver(function () use ($request) {
$route = new \Illuminate\Routing\Route('GET', 'api/modules/assets/{identifier}/{path}', []);
$route->bind($request);
$route->setParameter('identifier', 'test-module');
$route->setParameter('path', 'dist/js/module.iife.js');
return $route;
});
$rules = $request->rules();
$hasSafePathRule = false;
foreach ($rules['path'] as $rule) {
if ($rule instanceof SafeModulePath) {
$hasSafePathRule = true;
break;
}
}
$this->assertTrue($hasSafePathRule, 'SafeModulePath rule should be included in path validation');
}
/**
* AllowedModuleFileType Rule이 포함되어 있는지 테스트
*/
public function test_includes_file_type_rule(): void
{
$request = new ServeModuleAssetRequest();
// 라우트 파라미터 시뮬레이션
$request->setRouteResolver(function () use ($request) {
$route = new \Illuminate\Routing\Route('GET', 'api/modules/assets/{identifier}/{path}', []);
$route->bind($request);
$route->setParameter('identifier', 'test-module');
$route->setParameter('path', 'dist/js/module.iife.js');
return $route;
});
$rules = $request->rules();
$hasFileTypeRule = false;
foreach ($rules['path'] as $rule) {
if ($rule instanceof AllowedModuleFileType) {
$hasFileTypeRule = true;
break;
}
}
$this->assertTrue($hasFileTypeRule, 'AllowedModuleFileType rule should be included in path validation');
}
/**
* prepareForValidation이 라우트 파라미터를 병합하는지 테스트
*/
public function test_merges_route_parameters(): void
{
$request = new ServeModuleAssetRequest();
// 라우트 파라미터 시뮬레이션
$request->setRouteResolver(function () use ($request) {
$route = new \Illuminate\Routing\Route('GET', 'api/modules/assets/{identifier}/{path}', []);
$route->bind($request);
$route->setParameter('identifier', 'test-module');
$route->setParameter('path', 'dist/js/module.iife.js');
return $route;
});
// prepareForValidation 호출
$reflection = new \ReflectionClass($request);
$method = $reflection->getMethod('prepareForValidation');
$method->setAccessible(true);
$method->invoke($request);
// 병합된 파라미터 확인
$this->assertEquals('test-module', $request->input('identifier'));
$this->assertEquals('dist/js/module.iife.js', $request->input('path'));
}
}
@@ -0,0 +1,135 @@
<?php
namespace Tests\Unit\Requests;
use App\Http\Requests\Public\Plugin\ServePluginAssetRequest;
use App\Rules\AllowedPluginFileType;
use App\Rules\SafePluginPath;
use Tests\TestCase;
class ServePluginAssetRequestTest extends TestCase
{
/**
* authorize()가 항상 true를 반환하는지 테스트
*/
public function test_authorize_returns_true(): void
{
$request = new ServePluginAssetRequest();
$this->assertTrue($request->authorize());
}
/**
* 검증 규칙이 올바르게 정의되어 있는지 테스트
*/
public function test_has_correct_validation_rules(): void
{
$request = new ServePluginAssetRequest();
// 라우트 파라미터 시뮬레이션
$request->setRouteResolver(function () use ($request) {
$route = new \Illuminate\Routing\Route('GET', 'api/plugins/assets/{identifier}/{path}', []);
$route->bind($request);
$route->setParameter('identifier', 'test-plugin');
$route->setParameter('path', 'dist/js/plugin.iife.js');
return $route;
});
$rules = $request->rules();
$this->assertArrayHasKey('identifier', $rules);
$this->assertArrayHasKey('path', $rules);
$this->assertContains('required', $rules['identifier']);
$this->assertContains('string', $rules['identifier']);
$this->assertContains('required', $rules['path']);
$this->assertContains('string', $rules['path']);
}
/**
* SafePluginPath Rule이 포함되어 있는지 테스트
*/
public function test_includes_safe_path_rule(): void
{
$request = new ServePluginAssetRequest();
// 라우트 파라미터 시뮬레이션
$request->setRouteResolver(function () use ($request) {
$route = new \Illuminate\Routing\Route('GET', 'api/plugins/assets/{identifier}/{path}', []);
$route->bind($request);
$route->setParameter('identifier', 'test-plugin');
$route->setParameter('path', 'dist/js/plugin.iife.js');
return $route;
});
$rules = $request->rules();
$hasSafePathRule = false;
foreach ($rules['path'] as $rule) {
if ($rule instanceof SafePluginPath) {
$hasSafePathRule = true;
break;
}
}
$this->assertTrue($hasSafePathRule, 'SafePluginPath rule should be included in path validation');
}
/**
* AllowedPluginFileType Rule이 포함되어 있는지 테스트
*/
public function test_includes_file_type_rule(): void
{
$request = new ServePluginAssetRequest();
// 라우트 파라미터 시뮬레이션
$request->setRouteResolver(function () use ($request) {
$route = new \Illuminate\Routing\Route('GET', 'api/plugins/assets/{identifier}/{path}', []);
$route->bind($request);
$route->setParameter('identifier', 'test-plugin');
$route->setParameter('path', 'dist/js/plugin.iife.js');
return $route;
});
$rules = $request->rules();
$hasFileTypeRule = false;
foreach ($rules['path'] as $rule) {
if ($rule instanceof AllowedPluginFileType) {
$hasFileTypeRule = true;
break;
}
}
$this->assertTrue($hasFileTypeRule, 'AllowedPluginFileType rule should be included in path validation');
}
/**
* prepareForValidation이 라우트 파라미터를 병합하는지 테스트
*/
public function test_merges_route_parameters(): void
{
$request = new ServePluginAssetRequest();
// 라우트 파라미터 시뮬레이션
$request->setRouteResolver(function () use ($request) {
$route = new \Illuminate\Routing\Route('GET', 'api/plugins/assets/{identifier}/{path}', []);
$route->bind($request);
$route->setParameter('identifier', 'test-plugin');
$route->setParameter('path', 'dist/js/plugin.iife.js');
return $route;
});
// prepareForValidation 호출
$reflection = new \ReflectionClass($request);
$method = $reflection->getMethod('prepareForValidation');
$method->setAccessible(true);
$method->invoke($request);
// 병합된 파라미터 확인
$this->assertEquals('test-plugin', $request->input('identifier'));
$this->assertEquals('dist/js/plugin.iife.js', $request->input('path'));
}
}