공개 이슈(gnuboard/g7) 17건 전수 대조에서 "진짜 누락"으로 판정된 5건을 해소한다.
— 서버가 만들어 내보내는 상점 주소가 각 지점에서 `/shop` 리터럴이나
`"/{$routePath}/..."` 조립으로 흩어져 있었다. 기본값이 아닌 상점에서는 그 주소가
존재하지 않는 화면을 가리키는데, 서버는 문자열을 만들어 내려보냈을 뿐이라 예외도
404 로그도 남지 않는다 — 링크만 조용히 죽는다. `ShopPathResolver` 를 단일 해석
지점으로 두고 주문 완료 이동·비회원 조회 안내·알림 메일·통합검색·상품문의·SEO
캐시·사이트맵 전 지점을 경유시켰다. 같은 값에 종속된 PG 4종 리다이렉트는
`{shopBase}` 자리표시자로, 편집기 상태 scope 는 선택 세그먼트 토큰 `/*?`
(engine-v1.58.0)로 해소했다. 기설치본은 업그레이드 스텝이 백필한다.
M-02 — 답변 깊이 상한이 config 는 1~10 인데 컬럼 comment 만 1~5 로 남아,
comment 에서 자동 생성되는 계약 문서 4곳이 실제보다 좁은 상한을 공개하고 있었다.
L-01 — 관리자 게시글 폼에 첨부 안내가 아예 없었고, 대신 사장된 고정 문구
("최대 5개 파일, 각 10MB")가 남아 있었다. 게시판마다 다른 실제 설정값을 렌더한다.
— 목록 1페이지가 공지 전량을 상한 없이 읽던 것에 안전상한을 두고(구조 무변경,
limit 부가만), 조회수 정렬 목록 술어를 덮는 복합 색인을 신설했다.
브라우저 실측 검수에서 발견한 사전 결함 1건(사용자 게시판 목록이 URL 정렬
파라미터를 데이터소스로 전달하지 않던 문제)도 함께 고쳤다. 폴백을 빈 문자열로 둬
URL 에 정렬이 없을 때 게시판 설정을 덮어쓰지 않게 했다.
255 lines
9.5 KiB
PHP
255 lines
9.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\Sirsoft\Ecommerce\Tests\Unit\Seo;
|
|
|
|
require_once __DIR__.'/../../ModuleTestCase.php';
|
|
|
|
use App\Seo\AbstractSitemapContributor;
|
|
use App\Seo\Contracts\SitemapContributorInterface;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Modules\Sirsoft\Ecommerce\Models\Category;
|
|
use Modules\Sirsoft\Ecommerce\Models\Product;
|
|
use Modules\Sirsoft\Ecommerce\Seo\EcommerceSitemapContributor;
|
|
use Modules\Sirsoft\Ecommerce\Tests\ModuleTestCase;
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
|
|
/**
|
|
* EcommerceSitemapContributor 단위 테스트
|
|
*
|
|
* 검증 목적:
|
|
* - getIdentifier: 'sirsoft-ecommerce' 반환
|
|
* - getUrls: 기본(토글 ON) 상태에서 목록/카테고리/상품 URL 포함
|
|
* - getUrls: SEO 제공 페이지 토글 OFF 시 해당 URL 유형 제외 (회귀)
|
|
*/
|
|
#[Group('ecommerce')]
|
|
#[Group('unit')]
|
|
#[Group('seo')]
|
|
class EcommerceSitemapContributorTest extends ModuleTestCase
|
|
{
|
|
private EcommerceSitemapContributor $contributor;
|
|
|
|
private string $routePath = 'shop';
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
// Repository 주입이 필요하므로 컨테이너로 해석합니다.
|
|
$this->contributor = $this->app->make(EcommerceSitemapContributor::class);
|
|
$this->routePath = g7_module_settings('sirsoft-ecommerce', 'basic_info.route_path') ?? 'shop';
|
|
}
|
|
|
|
/**
|
|
* 테스트용 활성 카테고리 1건을 생성합니다.
|
|
*/
|
|
private function createTestCategory(): Category
|
|
{
|
|
return Category::create([
|
|
'name' => ['ko' => '사이트맵 카테고리', 'en' => 'Sitemap Category'],
|
|
'slug' => 'sitemap-cat',
|
|
'is_active' => true,
|
|
'path' => '/',
|
|
'depth' => 0,
|
|
'sort_order' => 0,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* SitemapContributorInterface 를 구현한다
|
|
*/
|
|
public function test_implements_sitemap_contributor_interface(): void
|
|
{
|
|
$this->assertInstanceOf(SitemapContributorInterface::class, $this->contributor);
|
|
}
|
|
|
|
/**
|
|
* getIdentifier: 'sirsoft-ecommerce' 반환
|
|
*/
|
|
public function test_get_identifier_returns_sirsoft_ecommerce(): void
|
|
{
|
|
$this->assertSame('sirsoft-ecommerce', $this->contributor->getIdentifier());
|
|
}
|
|
|
|
/**
|
|
* getUrls: route_path 미설정 시 기본값 'shop' 을 사용한다
|
|
*/
|
|
public function test_get_urls_uses_default_route_path_when_not_configured(): void
|
|
{
|
|
Config::set('g7_settings.modules.sirsoft-ecommerce.basic_info.route_path', null);
|
|
|
|
$contributor = $this->app->make(EcommerceSitemapContributor::class);
|
|
$urlPaths = array_column($contributor->getUrls(), 'url');
|
|
|
|
$this->assertContains('/shop/products', $urlPaths);
|
|
}
|
|
|
|
/**
|
|
* getUrls: 주소 없이 운영하는 상점(no_route)은 세그먼트 없이 루트 경로를 싣는다 (공개 #85)
|
|
*
|
|
* route_path 만 읽고 no_route 를 무시하면 사이트맵이 `/shop/...` 을 검색엔진에
|
|
* 제출하지만 실제 화면은 `/...` 이다 — 색인된 URL 전부가 404 로 수집된다.
|
|
*/
|
|
public function test_get_urls_omits_route_segment_when_no_route(): void
|
|
{
|
|
Config::set('g7_settings.modules.sirsoft-ecommerce.basic_info', [
|
|
'route_path' => 'shop',
|
|
'no_route' => true,
|
|
]);
|
|
|
|
$contributor = $this->app->make(EcommerceSitemapContributor::class);
|
|
$urlPaths = array_column($contributor->getUrls(), 'url');
|
|
|
|
$this->assertContains('/products', $urlPaths);
|
|
$this->assertNotContains('/shop/products', $urlPaths);
|
|
}
|
|
|
|
/**
|
|
* getUrls: 정적/카테고리/상품 URL 항목이 각각 올바른 키 구조를 가진다
|
|
*/
|
|
public function test_url_entries_have_correct_structure(): void
|
|
{
|
|
$category = $this->createTestCategory();
|
|
$product = Product::factory()->create();
|
|
|
|
$urls = collect($this->contributor->getUrls());
|
|
|
|
// 정적 목록 URL — lastmod 없음
|
|
$index = $urls->firstWhere('url', "/{$this->routePath}/products");
|
|
$this->assertNotNull($index);
|
|
$this->assertSame('daily', $index['changefreq']);
|
|
$this->assertSame(0.7, $index['priority']);
|
|
$this->assertArrayNotHasKey('lastmod', $index);
|
|
|
|
// 카테고리 URL — lastmod 있음
|
|
$categoryEntry = $urls->firstWhere('url', "/{$this->routePath}/category/{$category->slug}");
|
|
$this->assertNotNull($categoryEntry);
|
|
$this->assertArrayHasKey('lastmod', $categoryEntry);
|
|
$this->assertSame('weekly', $categoryEntry['changefreq']);
|
|
$this->assertSame(0.6, $categoryEntry['priority']);
|
|
|
|
// 상품 URL — lastmod 있음
|
|
$productEntry = $urls->firstWhere('url', "/{$this->routePath}/products/{$product->id}");
|
|
$this->assertNotNull($productEntry);
|
|
$this->assertArrayHasKey('lastmod', $productEntry);
|
|
$this->assertSame('weekly', $productEntry['changefreq']);
|
|
$this->assertSame(0.8, $productEntry['priority']);
|
|
}
|
|
|
|
/**
|
|
* getUrls: 기여자당 URL 안전 상한을 초과하면 상품 URL이 잘린다
|
|
*/
|
|
public function test_get_urls_truncates_at_max_urls_per_contributor(): void
|
|
{
|
|
Product::factory()->count(3)->create();
|
|
|
|
// 정적 목록 URL 1건이 이미 담기므로 상품은 1건까지만 담긴다.
|
|
// g7_core_settings 는 Config 파사드 기반이므로 Config::set 으로 주입합니다.
|
|
Config::set('g7_settings.core.seo.sitemap_max_urls_per_contributor', 2);
|
|
|
|
$this->assertCount(2, $this->contributor->getUrls());
|
|
}
|
|
|
|
/**
|
|
* getUrls: 상한이 카테고리 루프에도 적용된다 (회귀)
|
|
*
|
|
* 상한 검사가 상품 루프에만 있으면, 카테고리만으로 상한을 초과해도 잘리지 않는다.
|
|
*/
|
|
public function test_get_urls_truncates_within_category_loop(): void
|
|
{
|
|
$this->createTestCategory();
|
|
Category::create([
|
|
'name' => ['ko' => '사이트맵 카테고리2', 'en' => 'Sitemap Category 2'],
|
|
'slug' => 'sitemap-cat-2',
|
|
'is_active' => true,
|
|
'path' => '/',
|
|
'depth' => 0,
|
|
'sort_order' => 1,
|
|
]);
|
|
Product::factory()->count(2)->create();
|
|
|
|
// 정적 목록 1건 + 카테고리 2건 = 3건이지만 상한은 2건.
|
|
Config::set('g7_settings.core.seo.sitemap_max_urls_per_contributor', 2);
|
|
|
|
$urls = $this->contributor->getUrls();
|
|
|
|
$this->assertCount(2, $urls, '카테고리 루프에서도 상한이 지켜져야 합니다.');
|
|
// 상한 도달 후에는 상품 URL 이 하나도 담기지 않아야 한다
|
|
$this->assertEmpty(
|
|
array_filter($urls, fn (array $u): bool => str_contains($u['url'], '/products/')),
|
|
'상한 도달 후 상품 URL 이 추가되면 안 됩니다.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* getUrls: 기본(토글 ON) 상태에서 목록/카테고리/상품 URL이 모두 포함된다 (비파괴 회귀)
|
|
*/
|
|
public function test_get_urls_includes_all_when_toggles_default_on(): void
|
|
{
|
|
$category = $this->createTestCategory();
|
|
$product = Product::factory()->create();
|
|
|
|
$urls = $this->contributor->getUrls();
|
|
$urlPaths = array_column($urls, 'url');
|
|
|
|
$this->assertContains("/{$this->routePath}/products", $urlPaths);
|
|
$this->assertContains("/{$this->routePath}/category/{$category->slug}", $urlPaths);
|
|
$this->assertContains("/{$this->routePath}/products/{$product->id}", $urlPaths);
|
|
}
|
|
|
|
/**
|
|
* getUrls: seo_shop_index 토글 OFF 시 상품 목록 URL이 제외된다 (회귀)
|
|
*/
|
|
public function test_get_urls_excludes_shop_index_when_toggle_off(): void
|
|
{
|
|
Config::set('g7_settings.modules.sirsoft-ecommerce.seo.seo_shop_index', false);
|
|
|
|
$urls = $this->contributor->getUrls();
|
|
$urlPaths = array_column($urls, 'url');
|
|
|
|
$this->assertNotContains("/{$this->routePath}/products", $urlPaths);
|
|
}
|
|
|
|
/**
|
|
* getUrls: seo_category 토글 OFF 시 카테고리 URL이 제외된다 (회귀)
|
|
*/
|
|
public function test_get_urls_excludes_category_when_toggle_off(): void
|
|
{
|
|
$category = $this->createTestCategory();
|
|
Config::set('g7_settings.modules.sirsoft-ecommerce.seo.seo_category', false);
|
|
|
|
$urls = $this->contributor->getUrls();
|
|
$urlPaths = array_column($urls, 'url');
|
|
|
|
$this->assertNotContains("/{$this->routePath}/category/{$category->slug}", $urlPaths);
|
|
}
|
|
|
|
/**
|
|
* getUrls: seo_product_detail 토글 OFF 시 상품 상세 URL이 제외된다 (회귀)
|
|
*/
|
|
public function test_get_urls_excludes_product_detail_when_toggle_off(): void
|
|
{
|
|
$product = Product::factory()->create();
|
|
Config::set('g7_settings.modules.sirsoft-ecommerce.seo.seo_product_detail', false);
|
|
|
|
$urls = $this->contributor->getUrls();
|
|
$urlPaths = array_column($urls, 'url');
|
|
|
|
$this->assertNotContains("/{$this->routePath}/products/{$product->id}", $urlPaths);
|
|
}
|
|
|
|
/**
|
|
* getUrlsLazy: 배열을 실체화하지 않는 지연 제너레이터로 URL 을 흘려보낸다 (⑭ 스트리밍)
|
|
*/
|
|
public function test_get_urls_lazy_streams_entries(): void
|
|
{
|
|
$product = Product::factory()->create();
|
|
|
|
$this->assertInstanceOf(AbstractSitemapContributor::class, $this->contributor);
|
|
|
|
$lazy = $this->contributor->getUrlsLazy();
|
|
$this->assertInstanceOf(\Traversable::class, $lazy);
|
|
|
|
$urlPaths = array_column(iterator_to_array($lazy, false), 'url');
|
|
$this->assertContains("/{$this->routePath}/products/{$product->id}", $urlPaths);
|
|
}
|
|
}
|