AbstractSitemapContributor 브리지 base 로 인터페이스를 바꾸지 않고 board/ecommerce/page 기여자를 getUrlsLazy 지연 스트리밍으로 전환해, 게시글이 수백만 건인 사이트에서도 URL 배열을 통째로 적재하지 않는다. SitemapGenerator 는 capability 를 감지해 지연 경로를 쓰고, base 를 상속하지 않은 제3자 구현체는 기존 getUrls 경로로 그대로 동작한다. hreflang alternate 집합을 base URL 당 한 번만 계산해 로케일별 <url> 에 재사용하도록 바꿔 계산 비용을 로케일 수의 제곱에서 선형으로 줄였다 (정상 구성 출력은 불변). 다국어 대체 링크 사용 여부 토글과 로케일 수 상한을 추가하고 설정/검증/관리자 UI/다국어(ko·en·ja) 표면을 동반했다.
138 lines
4.2 KiB
PHP
138 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Sirsoft\Page\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\Page\Models\Page;
|
|
use Modules\Sirsoft\Page\Seo\PageSitemapContributor;
|
|
use Modules\Sirsoft\Page\Tests\ModuleTestCase;
|
|
|
|
/**
|
|
* PageSitemapContributor 단위 테스트
|
|
*
|
|
* 검증 목적:
|
|
* - getIdentifier: 'sirsoft-page' 반환
|
|
* - getUrls: 발행된 페이지 URL 포함
|
|
* - getUrls: 미발행 페이지 URL 미포함
|
|
* - getUrls: URL 항목 구조 (url/lastmod/changefreq/priority)
|
|
* - getUrls: 기여자당 URL 안전 상한 초과 시 절단
|
|
*
|
|
* @group page
|
|
* @group unit
|
|
* @group seo
|
|
*/
|
|
class PageSitemapContributorTest extends ModuleTestCase
|
|
{
|
|
private PageSitemapContributor $contributor;
|
|
|
|
/**
|
|
* 테스트 초기화 - 기여자를 컨테이너로 해석합니다.
|
|
*/
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// Repository 주입이 필요하므로 컨테이너로 해석합니다.
|
|
$this->contributor = $this->app->make(PageSitemapContributor::class);
|
|
}
|
|
|
|
/**
|
|
* SitemapContributorInterface 를 구현한다
|
|
*/
|
|
public function test_implements_sitemap_contributor_interface(): void
|
|
{
|
|
$this->assertInstanceOf(SitemapContributorInterface::class, $this->contributor);
|
|
}
|
|
|
|
/**
|
|
* getIdentifier: 'sirsoft-page' 반환
|
|
*/
|
|
public function test_get_identifier_returns_sirsoft_page(): void
|
|
{
|
|
$this->assertSame('sirsoft-page', $this->contributor->getIdentifier());
|
|
}
|
|
|
|
/**
|
|
* getUrls: 발행된 페이지 URL이 포함된다
|
|
*/
|
|
public function test_get_urls_includes_published_page(): void
|
|
{
|
|
$page = Page::factory()->published()->create();
|
|
|
|
$urlPaths = array_column($this->contributor->getUrls(), 'url');
|
|
|
|
$this->assertContains("/page/{$page->slug}", $urlPaths);
|
|
}
|
|
|
|
/**
|
|
* getUrls: 미발행 페이지는 포함되지 않는다
|
|
*/
|
|
public function test_get_urls_excludes_unpublished_page(): void
|
|
{
|
|
$page = Page::factory()->create(['published' => false]);
|
|
|
|
$urlPaths = array_column($this->contributor->getUrls(), 'url');
|
|
|
|
$this->assertNotContains("/page/{$page->slug}", $urlPaths);
|
|
}
|
|
|
|
/**
|
|
* getUrls: URL 항목이 올바른 키 구조를 가진다
|
|
*/
|
|
public function test_url_entries_have_correct_structure(): void
|
|
{
|
|
$page = Page::factory()->published()->create();
|
|
|
|
$urls = $this->contributor->getUrls();
|
|
$entry = collect($urls)->firstWhere('url', "/page/{$page->slug}");
|
|
|
|
$this->assertNotNull($entry);
|
|
$this->assertArrayHasKey('lastmod', $entry);
|
|
$this->assertSame('monthly', $entry['changefreq']);
|
|
$this->assertSame(0.5, $entry['priority']);
|
|
}
|
|
|
|
/**
|
|
* getUrls: 발행된 페이지가 없으면 빈 배열을 반환한다
|
|
*/
|
|
public function test_get_urls_returns_empty_array_when_no_published_pages(): void
|
|
{
|
|
Page::factory()->count(2)->create(['published' => false]);
|
|
|
|
$this->assertSame([], $this->contributor->getUrls());
|
|
}
|
|
|
|
/**
|
|
* getUrls: 기여자당 URL 안전 상한을 초과하면 잘린다
|
|
*/
|
|
public function test_get_urls_truncates_at_max_urls_per_contributor(): void
|
|
{
|
|
Page::factory()->count(3)->published()->create();
|
|
|
|
// g7_core_settings 는 Config 파사드 기반이므로 Config::set 으로 주입합니다.
|
|
Config::set('g7_settings.core.seo.sitemap_max_urls_per_contributor', 2);
|
|
|
|
$this->assertCount(2, $this->contributor->getUrls());
|
|
}
|
|
|
|
/**
|
|
* getUrlsLazy: 배열을 실체화하지 않는 지연 제너레이터로 URL 을 흘려보낸다 (⑭ 스트리밍)
|
|
*/
|
|
public function test_get_urls_lazy_streams_entries(): void
|
|
{
|
|
$page = Page::factory()->published()->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("/page/{$page->slug}", $urlPaths);
|
|
}
|
|
}
|