v7.0.0-beta.2 release
This commit is contained in:
1 parent
6595fd0eb5
commit
fa8eba7a0d
1165 files changed
+107118
-762127
No files matched your search
@@ -76,11 +76,7 @@ class SeoExtensionCacheListenerTest extends TestCase
|
||||
{
|
||||
$this->cacheMock->shouldReceive('clearAll')->once();
|
||||
|
||||
Cache::shouldReceive('forget')
|
||||
->once()
|
||||
->with('seo:sitemap');
|
||||
|
||||
Log::shouldReceive('info')
|
||||
Log::shouldReceive('info')
|
||||
->once()
|
||||
->with('[SEO] Extension changed — all cache cleared', Mockery::on(function ($context) {
|
||||
return $context['identifier'] === 'sirsoft-ecommerce';
|
||||
@@ -98,11 +94,7 @@ class SeoExtensionCacheListenerTest extends TestCase
|
||||
{
|
||||
$this->cacheMock->shouldReceive('clearAll')->once();
|
||||
|
||||
Cache::shouldReceive('forget')
|
||||
->once()
|
||||
->with('seo:sitemap');
|
||||
|
||||
Log::shouldReceive('info')->once();
|
||||
Log::shouldReceive('info')->once();
|
||||
|
||||
$this->listener->onExtensionChanged('sirsoft-ecommerce', ['name' => 'Ecommerce']);
|
||||
|
||||
@@ -116,11 +108,7 @@ class SeoExtensionCacheListenerTest extends TestCase
|
||||
{
|
||||
$this->cacheMock->shouldReceive('clearAll')->once();
|
||||
|
||||
Cache::shouldReceive('forget')
|
||||
->once()
|
||||
->with('seo:sitemap');
|
||||
|
||||
Log::shouldReceive('info')->once();
|
||||
Log::shouldReceive('info')->once();
|
||||
|
||||
$this->listener->onExtensionChanged('sirsoft-ecommerce', ['success' => true], ['name' => 'Ecommerce']);
|
||||
|
||||
@@ -136,11 +124,7 @@ class SeoExtensionCacheListenerTest extends TestCase
|
||||
{
|
||||
$this->cacheMock->shouldReceive('clearAll')->once();
|
||||
|
||||
Cache::shouldReceive('forget')
|
||||
->once()
|
||||
->with('seo:sitemap');
|
||||
|
||||
Log::shouldReceive('info')->once();
|
||||
Log::shouldReceive('info')->once();
|
||||
|
||||
$this->listener->onExtensionChanged('sirsoft-payment', ['name' => 'Payment']);
|
||||
|
||||
@@ -156,11 +140,7 @@ class SeoExtensionCacheListenerTest extends TestCase
|
||||
{
|
||||
$this->cacheMock->shouldReceive('clearAll')->once();
|
||||
|
||||
Cache::shouldReceive('forget')
|
||||
->once()
|
||||
->with('seo:sitemap');
|
||||
|
||||
Log::shouldReceive('info')->once();
|
||||
Log::shouldReceive('info')->once();
|
||||
|
||||
// 템플릿 활성화는 Template model 객체가 전달됨
|
||||
$templateModel = Mockery::mock();
|
||||
@@ -179,11 +159,7 @@ class SeoExtensionCacheListenerTest extends TestCase
|
||||
{
|
||||
$this->cacheMock->shouldReceive('clearAll')->once();
|
||||
|
||||
Cache::shouldReceive('forget')
|
||||
->once()
|
||||
->with('seo:sitemap');
|
||||
|
||||
Log::shouldReceive('info')->once();
|
||||
Log::shouldReceive('info')->once();
|
||||
|
||||
$this->listener->onExtensionChanged('sirsoft-basic', ['success' => true], ['name' => 'Basic']);
|
||||
|
||||
@@ -232,11 +208,7 @@ class SeoExtensionCacheListenerTest extends TestCase
|
||||
{
|
||||
$this->cacheMock->shouldReceive('clearAll')->once();
|
||||
|
||||
Cache::shouldReceive('forget')
|
||||
->once()
|
||||
->with('seo:sitemap');
|
||||
|
||||
Log::shouldReceive('info')
|
||||
Log::shouldReceive('info')
|
||||
->once()
|
||||
->with('[SEO] Extension changed — all cache cleared', Mockery::on(function ($context) {
|
||||
return isset($context['identifier'])
|
||||
@@ -257,11 +229,7 @@ class SeoExtensionCacheListenerTest extends TestCase
|
||||
{
|
||||
$this->cacheMock->shouldReceive('clearAll')->once();
|
||||
|
||||
Cache::shouldReceive('forget')
|
||||
->once()
|
||||
->with('seo:sitemap');
|
||||
|
||||
Log::shouldReceive('info')
|
||||
Log::shouldReceive('info')
|
||||
->once()
|
||||
->with('[SEO] Extension changed — all cache cleared', Mockery::on(function ($context) {
|
||||
return $context['identifier'] === 'unknown';
|
||||
|
||||
@@ -59,10 +59,6 @@ class SeoSettingsCacheListenerTest extends TestCase
|
||||
{
|
||||
$this->cacheMock->shouldReceive('clearAll')->once();
|
||||
|
||||
Cache::shouldReceive('forget')
|
||||
->once()
|
||||
->with('seo:sitemap');
|
||||
|
||||
Log::shouldReceive('info')
|
||||
->once()
|
||||
->with('[SEO] Core SEO settings changed — all cache cleared', Mockery::type('array'));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Unit\Seo;
|
||||
|
||||
use App\Extension\Cache\CoreCacheDriver;
|
||||
use App\Seo\SeoCacheManager;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Tests\TestCase;
|
||||
@@ -24,7 +25,7 @@ class SeoCacheManagerTest extends TestCase
|
||||
// 이전 테스트 캐시 잔여물 제거
|
||||
Cache::flush();
|
||||
|
||||
$this->cacheManager = new SeoCacheManager;
|
||||
$this->cacheManager = new SeoCacheManager(new CoreCacheDriver('array'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +59,7 @@ class SeoCacheManagerTest extends TestCase
|
||||
*/
|
||||
public function test_cache_disabled_ignores_put_and_returns_null(): void
|
||||
{
|
||||
config()->set('g7_settings.core.cache.seo_enabled', false);
|
||||
config()->set('g7_settings.core.seo.cache_enabled', false);
|
||||
|
||||
$url = '/products/123';
|
||||
@@ -199,6 +201,7 @@ class SeoCacheManagerTest extends TestCase
|
||||
*/
|
||||
public function test_put_with_layout_ignored_when_cache_disabled(): void
|
||||
{
|
||||
config()->set('g7_settings.core.cache.seo_enabled', false);
|
||||
config()->set('g7_settings.core.seo.cache_enabled', false);
|
||||
|
||||
$this->cacheManager->putWithLayout('/products/1', 'ko', '<html>상품1</html>', 'shop/show');
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Tests\Unit\Seo;
|
||||
use App\Contracts\Repositories\TemplateRepositoryInterface;
|
||||
use App\Extension\AbstractModule;
|
||||
use App\Extension\AbstractPlugin;
|
||||
use App\Extension\Cache\CoreCacheDriver;
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Extension\PluginManager;
|
||||
use App\Seo\SeoConfigMerger;
|
||||
@@ -38,6 +39,7 @@ class SeoConfigMergerTest extends TestCase
|
||||
$this->moduleManager,
|
||||
$this->pluginManager,
|
||||
$this->templateRepository,
|
||||
new CoreCacheDriver('array'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -297,8 +299,8 @@ class SeoConfigMergerTest extends TestCase
|
||||
|
||||
$this->assertEquals($result1, $result2);
|
||||
|
||||
// 캐시 키 존재 확인
|
||||
$this->assertTrue(Cache::has('seo:config:merged:sirsoft-basic'));
|
||||
// 캐시 키 존재 확인 — CoreCacheDriver 와 Cache 파사드는 동일 스토어 사용
|
||||
$this->assertTrue(Cache::store('array')->has('g7:core:seo.config.sirsoft-basic'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,17 +313,17 @@ class SeoConfigMergerTest extends TestCase
|
||||
|
||||
// 첫 호출
|
||||
$this->merger->getMergedConfig('sirsoft-basic');
|
||||
$this->assertTrue(Cache::has('seo:config:merged:sirsoft-basic'));
|
||||
$this->assertTrue(Cache::store('array')->has('g7:core:seo.config.sirsoft-basic'));
|
||||
|
||||
// 캐시 클리어
|
||||
$this->merger->clearCache('sirsoft-basic');
|
||||
$this->assertFalse(Cache::has('seo:config:merged:sirsoft-basic'));
|
||||
$this->assertFalse(Cache::store('array')->has('g7:core:seo.config.sirsoft-basic'));
|
||||
|
||||
// 재호출 — 캐시 미스이므로 다시 빌드
|
||||
$result = $this->merger->getMergedConfig('sirsoft-basic');
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertTrue(Cache::has('seo:config:merged:sirsoft-basic'));
|
||||
$this->assertTrue(Cache::store('array')->has('g7:core:seo.config.sirsoft-basic'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1151,4 +1151,85 @@ class SeoMetaResolverTest extends TestCase
|
||||
$this->assertArrayHasKey('offers', $jsonLd);
|
||||
$this->assertSame('129000', $jsonLd['offers']['price']);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// _seo context 참조 테스트
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* _seo.product.title이 context에 있으면 Tier 2로 사용됩니다.
|
||||
*/
|
||||
public function test_seo_context_title_used_as_tier2(): void
|
||||
{
|
||||
$seoConfig = [
|
||||
'enabled' => true,
|
||||
'page_type' => 'product',
|
||||
];
|
||||
|
||||
$context = [
|
||||
'_seo' => [
|
||||
'product' => [
|
||||
'title' => '테스트쇼핑몰 - 에어맥스',
|
||||
'description' => '에어맥스 설명',
|
||||
],
|
||||
],
|
||||
'product' => ['data' => ['name' => '에어맥스']],
|
||||
];
|
||||
|
||||
$result = $this->resolver->resolve($seoConfig, $context, null, null, []);
|
||||
|
||||
$this->assertEquals('테스트쇼핑몰 - 에어맥스', $result['title']);
|
||||
$this->assertEquals('에어맥스 설명', $result['description']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tier 3 (resource meta_title)가 _seo context보다 우선합니다.
|
||||
*/
|
||||
public function test_resource_meta_title_overrides_seo_context(): void
|
||||
{
|
||||
$seoConfig = [
|
||||
'enabled' => true,
|
||||
'page_type' => 'product',
|
||||
];
|
||||
|
||||
$context = [
|
||||
'_seo' => [
|
||||
'product' => [
|
||||
'title' => '테스트쇼핑몰 - 에어맥스',
|
||||
'description' => '쇼핑몰 설명',
|
||||
],
|
||||
],
|
||||
'product' => ['data' => [
|
||||
'name' => '에어맥스',
|
||||
'meta_title' => '커스텀 SEO 타이틀',
|
||||
'meta_description' => '커스텀 SEO 설명',
|
||||
]],
|
||||
];
|
||||
|
||||
$result = $this->resolver->resolve($seoConfig, $context, null, null, []);
|
||||
|
||||
// Tier 3가 Tier 2(_seo)보다 우선
|
||||
$this->assertEquals('커스텀 SEO 타이틀', $result['title']);
|
||||
$this->assertEquals('커스텀 SEO 설명', $result['description']);
|
||||
}
|
||||
|
||||
/**
|
||||
* _seo context 없고 moduleIdentifier도 null이면 빈 타이틀로 fallback합니다.
|
||||
*/
|
||||
public function test_no_seo_context_and_no_module_falls_through(): void
|
||||
{
|
||||
$seoConfig = [
|
||||
'enabled' => true,
|
||||
'page_type' => 'product',
|
||||
];
|
||||
|
||||
$context = [
|
||||
'product' => ['data' => ['name' => '에어맥스']],
|
||||
];
|
||||
|
||||
$result = $this->resolver->resolve($seoConfig, $context, null, null, []);
|
||||
|
||||
// _seo도 없고 moduleIdentifier도 null → Tier 2 스킵 → 빈 문자열
|
||||
$this->assertEquals('', $result['title']);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Tests\Unit\Seo;
|
||||
|
||||
use App\Contracts\Extension\ModuleManagerInterface;
|
||||
use App\Contracts\Extension\PluginManagerInterface;
|
||||
use App\Extension\HookManager;
|
||||
use App\Seo\ComponentHtmlMapper;
|
||||
use App\Seo\DataSourceResolver;
|
||||
@@ -42,6 +44,10 @@ class SeoRendererTest extends TestCase
|
||||
|
||||
private PluginSettingsService|MockInterface $pluginSettingsService;
|
||||
|
||||
private ModuleManagerInterface|MockInterface $moduleManager;
|
||||
|
||||
private PluginManagerInterface|MockInterface $pluginManager;
|
||||
|
||||
private SeoRenderer $renderer;
|
||||
|
||||
/**
|
||||
@@ -61,6 +67,8 @@ class SeoRendererTest extends TestCase
|
||||
$this->seoConfigMerger = Mockery::mock(SeoConfigMerger::class);
|
||||
$this->settingsService = Mockery::mock(SettingsService::class);
|
||||
$this->pluginSettingsService = Mockery::mock(PluginSettingsService::class);
|
||||
$this->moduleManager = Mockery::mock(ModuleManagerInterface::class);
|
||||
$this->pluginManager = Mockery::mock(PluginManagerInterface::class);
|
||||
|
||||
// 기본 SettingsService / PluginSettingsService mock
|
||||
$this->settingsService->shouldReceive('getFrontendSettings')
|
||||
@@ -80,9 +88,16 @@ class SeoRendererTest extends TestCase
|
||||
->andReturn(['success' => true, 'data' => [], 'error' => null])
|
||||
->byDefault();
|
||||
|
||||
// 기본 evaluator mock (setTranslations 허용)
|
||||
// 기본 evaluator mock (setTranslations, getPipeRegistry 허용)
|
||||
$this->evaluator->shouldReceive('setTranslations')
|
||||
->byDefault();
|
||||
$pipeRegistry = Mockery::mock(\App\Seo\PipeRegistry::class);
|
||||
$pipeRegistry->shouldReceive('setLocale')->byDefault();
|
||||
$this->evaluator->shouldReceive('getPipeRegistry')
|
||||
->andReturn($pipeRegistry)
|
||||
->byDefault();
|
||||
$this->evaluator->shouldReceive('setSeoOverrides')
|
||||
->byDefault();
|
||||
|
||||
// 기본 htmlMapper mock (seo-config.json 로드 시 호출되는 설정 메서드 허용)
|
||||
$this->htmlMapper->shouldReceive('setComponentMap')->byDefault();
|
||||
@@ -111,6 +126,8 @@ class SeoRendererTest extends TestCase
|
||||
$this->seoConfigMerger,
|
||||
$this->settingsService,
|
||||
$this->pluginSettingsService,
|
||||
$this->moduleManager,
|
||||
$this->pluginManager,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -869,12 +886,16 @@ class SeoRendererTest extends TestCase
|
||||
?array $initActions = null,
|
||||
?array $structuredData = null,
|
||||
?array $computed = null,
|
||||
?array $extensions = null,
|
||||
): array {
|
||||
$seo = [
|
||||
'enabled' => $seoEnabled,
|
||||
'data_sources' => $seoDataSources,
|
||||
];
|
||||
|
||||
if ($extensions !== null) {
|
||||
$seo['extensions'] = $extensions;
|
||||
}
|
||||
if ($toggleSetting !== null) {
|
||||
$seo['toggle_setting'] = $toggleSetting;
|
||||
}
|
||||
@@ -3246,4 +3267,348 @@ class SeoRendererTest extends TestCase
|
||||
$this->assertNull($capturedContext['_computed']['broken']);
|
||||
$this->assertEquals('still works', $capturedContext['_computed']['valid']);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// _seo context 주입 테스트 (extensions 기반)
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* 상품 상세 페이지에서 extensions + seoVariables()로 _seo.product context가 주입됩니다.
|
||||
*/
|
||||
public function test_seo_context_injected_for_product_page(): void
|
||||
{
|
||||
$request = Request::create('/shop/products/1');
|
||||
$this->setupRouteResolver('/shop/products/1', [
|
||||
'templateIdentifier' => 'sirsoft-basic',
|
||||
'layoutName' => 'shop/show',
|
||||
'routeParams' => ['id' => '1'],
|
||||
'moduleIdentifier' => null,
|
||||
'routeMeta' => [],
|
||||
]);
|
||||
|
||||
$mergedLayout = $this->buildMergedLayout(
|
||||
seoEnabled: true,
|
||||
seoDataSources: ['product'],
|
||||
pageType: 'product',
|
||||
extensions: [['type' => 'module', 'id' => 'sirsoft-ecommerce']],
|
||||
vars: [
|
||||
'product_name' => '{{product.data.name}}',
|
||||
'product_description' => '{{product.data.description}}',
|
||||
],
|
||||
);
|
||||
$this->layoutService->shouldReceive('getLayout')->once()->andReturn($mergedLayout);
|
||||
|
||||
// 모듈 인스턴스 mock
|
||||
$moduleMock = Mockery::mock(\App\Extension\AbstractModule::class)->makePartial();
|
||||
$moduleMock->shouldReceive('seoVariables')->andReturn([
|
||||
'_common' => [
|
||||
'commerce_name' => ['source' => 'setting', 'key' => 'basic_info.shop_name'],
|
||||
],
|
||||
'product' => [
|
||||
'product_name' => ['source' => 'data', 'required' => true],
|
||||
'product_description' => ['source' => 'data'],
|
||||
],
|
||||
]);
|
||||
$this->moduleManager->shouldReceive('getModule')
|
||||
->with('sirsoft-ecommerce')
|
||||
->andReturn($moduleMock);
|
||||
|
||||
// 설정값 mock
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.basic_info.shop_name', '테스트쇼핑몰');
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.seo.meta_product_title', '{commerce_name} - {product_name}');
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.seo.meta_product_description', '{product_description}');
|
||||
|
||||
$this->dataSourceResolver->shouldReceive('resolve')->once()->andReturn([
|
||||
'product' => ['data' => ['name' => '에어맥스', 'description' => '나이키 에어맥스 상품']],
|
||||
]);
|
||||
|
||||
// vars 해석 시 evaluator 호출
|
||||
$this->evaluator->shouldReceive('evaluate')
|
||||
->with('{{product.data.name}}', Mockery::any())
|
||||
->andReturn('에어맥스');
|
||||
$this->evaluator->shouldReceive('evaluate')
|
||||
->with('{{product.data.description}}', Mockery::any())
|
||||
->andReturn('나이키 에어맥스 상품');
|
||||
|
||||
// _seo context 캡처
|
||||
$capturedContext = null;
|
||||
$this->metaResolver->shouldReceive('resolve')
|
||||
->once()
|
||||
->withArgs(function ($seoConfig, $context) use (&$capturedContext) {
|
||||
$capturedContext = $context;
|
||||
|
||||
return true;
|
||||
})
|
||||
->andReturn($this->buildMetaResult(title: '테스트쇼핑몰 - 에어맥스'));
|
||||
|
||||
$viewMock = Mockery::mock(\Illuminate\View\View::class);
|
||||
$viewMock->shouldReceive('render')->andReturn('<html></html>');
|
||||
View::shouldReceive('make')->once()->andReturn($viewMock);
|
||||
|
||||
$this->renderer->render($request);
|
||||
|
||||
$this->assertNotNull($capturedContext);
|
||||
$this->assertArrayHasKey('_seo', $capturedContext);
|
||||
$this->assertArrayHasKey('product', $capturedContext['_seo']);
|
||||
$this->assertEquals('테스트쇼핑몰 - 에어맥스', $capturedContext['_seo']['product']['title']);
|
||||
$this->assertEquals('나이키 에어맥스 상품', $capturedContext['_seo']['product']['description']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 카테고리 목록 페이지에서 _seo.category context가 주입됩니다.
|
||||
*/
|
||||
public function test_seo_context_injected_for_category_page(): void
|
||||
{
|
||||
$request = Request::create('/shop/category/shoes');
|
||||
$this->setupRouteResolver('/shop/category/shoes', [
|
||||
'templateIdentifier' => 'sirsoft-basic',
|
||||
'layoutName' => 'shop/category',
|
||||
'routeParams' => ['slug' => 'shoes'],
|
||||
'moduleIdentifier' => null,
|
||||
'routeMeta' => [],
|
||||
]);
|
||||
|
||||
$mergedLayout = $this->buildMergedLayout(
|
||||
seoEnabled: true,
|
||||
seoDataSources: ['category'],
|
||||
pageType: 'category',
|
||||
extensions: [['type' => 'module', 'id' => 'sirsoft-ecommerce']],
|
||||
vars: [
|
||||
'category_name' => '{{category.data.name}}',
|
||||
'category_description' => '{{category.data.description}}',
|
||||
],
|
||||
);
|
||||
$this->layoutService->shouldReceive('getLayout')->once()->andReturn($mergedLayout);
|
||||
|
||||
$moduleMock = Mockery::mock(\App\Extension\AbstractModule::class)->makePartial();
|
||||
$moduleMock->shouldReceive('seoVariables')->andReturn([
|
||||
'_common' => [
|
||||
'commerce_name' => ['source' => 'setting', 'key' => 'basic_info.shop_name'],
|
||||
],
|
||||
'category' => [
|
||||
'category_name' => ['source' => 'data', 'required' => true],
|
||||
'category_description' => ['source' => 'data'],
|
||||
],
|
||||
]);
|
||||
$this->moduleManager->shouldReceive('getModule')
|
||||
->with('sirsoft-ecommerce')
|
||||
->andReturn($moduleMock);
|
||||
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.basic_info.shop_name', '테스트쇼핑몰');
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.seo.meta_category_title', '{commerce_name} - {category_name}');
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.seo.meta_category_description', '{category_description}');
|
||||
|
||||
$this->dataSourceResolver->shouldReceive('resolve')->once()->andReturn([
|
||||
'category' => ['data' => ['name' => '신발', 'description' => '신발 카테고리']],
|
||||
]);
|
||||
|
||||
$this->evaluator->shouldReceive('evaluate')
|
||||
->with('{{category.data.name}}', Mockery::any())
|
||||
->andReturn('신발');
|
||||
$this->evaluator->shouldReceive('evaluate')
|
||||
->with('{{category.data.description}}', Mockery::any())
|
||||
->andReturn('신발 카테고리');
|
||||
|
||||
$capturedContext = null;
|
||||
$this->metaResolver->shouldReceive('resolve')
|
||||
->once()
|
||||
->withArgs(function ($seoConfig, $context) use (&$capturedContext) {
|
||||
$capturedContext = $context;
|
||||
|
||||
return true;
|
||||
})
|
||||
->andReturn($this->buildMetaResult(title: '테스트쇼핑몰 - 신발'));
|
||||
|
||||
$viewMock = Mockery::mock(\Illuminate\View\View::class);
|
||||
$viewMock->shouldReceive('render')->andReturn('<html></html>');
|
||||
View::shouldReceive('make')->once()->andReturn($viewMock);
|
||||
|
||||
$this->renderer->render($request);
|
||||
|
||||
$this->assertNotNull($capturedContext);
|
||||
$this->assertEquals('테스트쇼핑몰 - 신발', $capturedContext['_seo']['category']['title']);
|
||||
$this->assertEquals('신발 카테고리', $capturedContext['_seo']['category']['description']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 검색결과 페이지에서 _seo.search context가 주입됩니다 (query source 변수 포함).
|
||||
*/
|
||||
public function test_seo_context_injected_for_search_page(): void
|
||||
{
|
||||
$request = Request::create('/search', 'GET', ['q' => '운동화']);
|
||||
// request() 헬퍼가 이 request를 반환하도록 바인딩
|
||||
app()->instance('request', $request);
|
||||
|
||||
$this->setupRouteResolver('/search', [
|
||||
'templateIdentifier' => 'sirsoft-basic',
|
||||
'layoutName' => 'search/index',
|
||||
'routeParams' => [],
|
||||
'moduleIdentifier' => null,
|
||||
'routeMeta' => [],
|
||||
]);
|
||||
|
||||
$mergedLayout = $this->buildMergedLayout(
|
||||
seoEnabled: true,
|
||||
seoDataSources: [],
|
||||
pageType: 'search',
|
||||
extensions: [['type' => 'module', 'id' => 'sirsoft-ecommerce']],
|
||||
);
|
||||
$this->layoutService->shouldReceive('getLayout')->once()->andReturn($mergedLayout);
|
||||
|
||||
$moduleMock = Mockery::mock(\App\Extension\AbstractModule::class)->makePartial();
|
||||
$moduleMock->shouldReceive('seoVariables')->andReturn([
|
||||
'_common' => [
|
||||
'commerce_name' => ['source' => 'setting', 'key' => 'basic_info.shop_name'],
|
||||
],
|
||||
'search' => [
|
||||
'keyword_name' => ['source' => 'query', 'key' => 'q'],
|
||||
],
|
||||
]);
|
||||
$this->moduleManager->shouldReceive('getModule')
|
||||
->with('sirsoft-ecommerce')
|
||||
->andReturn($moduleMock);
|
||||
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.basic_info.shop_name', '테스트쇼핑몰');
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.seo.meta_search_title', '{commerce_name} - {keyword_name}');
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.seo.meta_search_description', '');
|
||||
|
||||
$this->dataSourceResolver->shouldReceive('resolve')->never();
|
||||
|
||||
$capturedContext = null;
|
||||
$this->metaResolver->shouldReceive('resolve')
|
||||
->once()
|
||||
->withArgs(function ($seoConfig, $context) use (&$capturedContext) {
|
||||
$capturedContext = $context;
|
||||
|
||||
return true;
|
||||
})
|
||||
->andReturn($this->buildMetaResult(title: '테스트쇼핑몰 - 운동화'));
|
||||
|
||||
$viewMock = Mockery::mock(\Illuminate\View\View::class);
|
||||
$viewMock->shouldReceive('render')->andReturn('<html></html>');
|
||||
View::shouldReceive('make')->once()->andReturn($viewMock);
|
||||
|
||||
$this->renderer->render($request);
|
||||
|
||||
$this->assertNotNull($capturedContext);
|
||||
$this->assertEquals('테스트쇼핑몰 - 운동화', $capturedContext['_seo']['search']['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 설정 템플릿 값이 null인 경우에도 TypeError 없이 정상 동작합니다.
|
||||
*/
|
||||
public function test_seo_context_handles_null_settings_template(): void
|
||||
{
|
||||
$request = Request::create('/shop/products/1');
|
||||
$this->setupRouteResolver('/shop/products/1', [
|
||||
'templateIdentifier' => 'sirsoft-basic',
|
||||
'layoutName' => 'shop/show',
|
||||
'routeParams' => ['id' => '1'],
|
||||
'moduleIdentifier' => null,
|
||||
'routeMeta' => [],
|
||||
]);
|
||||
|
||||
$mergedLayout = $this->buildMergedLayout(
|
||||
seoEnabled: true,
|
||||
seoDataSources: ['product'],
|
||||
pageType: 'product',
|
||||
extensions: [['type' => 'module', 'id' => 'sirsoft-ecommerce']],
|
||||
vars: [
|
||||
'product_name' => '{{product.data.name}}',
|
||||
],
|
||||
);
|
||||
$this->layoutService->shouldReceive('getLayout')->once()->andReturn($mergedLayout);
|
||||
|
||||
$moduleMock = Mockery::mock(\App\Extension\AbstractModule::class)->makePartial();
|
||||
$moduleMock->shouldReceive('seoVariables')->andReturn([
|
||||
'product' => [
|
||||
'product_name' => ['source' => 'data', 'required' => true],
|
||||
],
|
||||
]);
|
||||
$this->moduleManager->shouldReceive('getModule')
|
||||
->with('sirsoft-ecommerce')
|
||||
->andReturn($moduleMock);
|
||||
|
||||
// 설정값을 null로 설정 (미구성 상태 재현)
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.seo.meta_product_title', null);
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.seo.meta_product_description', null);
|
||||
|
||||
$this->dataSourceResolver->shouldReceive('resolve')->once()->andReturn([
|
||||
'product' => ['data' => ['name' => '에어맥스']],
|
||||
]);
|
||||
|
||||
$this->evaluator->shouldReceive('evaluate')
|
||||
->with('{{product.data.name}}', Mockery::any())
|
||||
->andReturn('에어맥스');
|
||||
|
||||
$capturedContext = null;
|
||||
$this->metaResolver->shouldReceive('resolve')
|
||||
->once()
|
||||
->withArgs(function ($seoConfig, $context) use (&$capturedContext) {
|
||||
$capturedContext = $context;
|
||||
|
||||
return true;
|
||||
})
|
||||
->andReturn($this->buildMetaResult(title: '에어맥스'));
|
||||
|
||||
$viewMock = Mockery::mock(\Illuminate\View\View::class);
|
||||
$viewMock->shouldReceive('render')->andReturn('<html></html>');
|
||||
View::shouldReceive('make')->once()->andReturn($viewMock);
|
||||
|
||||
// TypeError 없이 정상 실행되어야 함
|
||||
$result = $this->renderer->render($request);
|
||||
$this->assertNotNull($result);
|
||||
|
||||
// null 템플릿 → _seo context에 주입되지 않음 (빈 문자열이므로)
|
||||
$this->assertNotNull($capturedContext);
|
||||
$this->assertArrayNotHasKey('_seo', $capturedContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* extensions 미선언 시 _seo context가 주입되지 않습니다 (하위호환).
|
||||
*/
|
||||
public function test_seo_context_not_injected_without_extensions(): void
|
||||
{
|
||||
$request = Request::create('/products/1');
|
||||
$this->setupRouteResolver('/products/1', [
|
||||
'templateIdentifier' => 'sirsoft-basic',
|
||||
'layoutName' => 'shop/show',
|
||||
'routeParams' => ['id' => '1'],
|
||||
'moduleIdentifier' => 'sirsoft-ecommerce',
|
||||
'routeMeta' => [],
|
||||
]);
|
||||
|
||||
$mergedLayout = $this->buildMergedLayout(
|
||||
seoEnabled: true,
|
||||
seoDataSources: ['product'],
|
||||
pageType: 'product',
|
||||
toggleSetting: '$module_settings:seo.seo_product_detail',
|
||||
);
|
||||
$this->layoutService->shouldReceive('getLayout')->once()->andReturn($mergedLayout);
|
||||
|
||||
config()->set('g7_settings.modules.sirsoft-ecommerce.seo.seo_product_detail', true);
|
||||
|
||||
$this->dataSourceResolver->shouldReceive('resolve')->once()->andReturn([
|
||||
'product' => ['data' => ['name' => '에어맥스']],
|
||||
]);
|
||||
|
||||
$capturedContext = null;
|
||||
$this->metaResolver->shouldReceive('resolve')
|
||||
->once()
|
||||
->withArgs(function ($seoConfig, $context) use (&$capturedContext) {
|
||||
$capturedContext = $context;
|
||||
|
||||
return true;
|
||||
})
|
||||
->andReturn($this->buildMetaResult(title: '에어맥스'));
|
||||
|
||||
$viewMock = Mockery::mock(\Illuminate\View\View::class);
|
||||
$viewMock->shouldReceive('render')->andReturn('<html></html>');
|
||||
View::shouldReceive('make')->once()->andReturn($viewMock);
|
||||
|
||||
$this->renderer->render($request);
|
||||
|
||||
$this->assertNotNull($capturedContext);
|
||||
$this->assertArrayNotHasKey('_seo', $capturedContext);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user