Files
Gnuboard7/modules/_bundled/sirsoft-board/tests/Unit/Resources/PostResourceThumbnailUrlTest.php
T
HeuJung 057e002ad1 feat(core,ecommerce,ckeditor5,board,admin_basic): 공개 자산 직접 URL(CDN) 서빙 옵트인
StorageInterface::url 의 public 하드코딩을 완화하고 core.storage.filter_url 훅을
신설해, 완전 공개 자산(상품·카테고리·리뷰·에디터 이미지)의 직접 URL 서빙을 옵트인으로
열었다. 미설정 시 기존 스트리밍 100% 보존.

디스크 결정은 확장 개별 설정 > 코어 전역 > 미설정 순이며, 서빙·삭제·이동은 행에 기록된
disk 를 따라 전환 전후 자산이 혼재해도 각자 실제 저장 위치를 향한다. 고아 disk(공급
플러그인 비활성화)는 스트리밍으로 폴백해 500 이 되지 않는다.

공개 이슈 (@lyg-kaban 건의) 대응.
2026-08-14 08:05:54 +09:00

79 lines
2.6 KiB
PHP

<?php
namespace Modules\Sirsoft\Board\Tests\Unit\Resources;
use Illuminate\Http\Request;
use Modules\Sirsoft\Board\Http\Resources\PostResource;
use Modules\Sirsoft\Board\Models\Attachment;
use Modules\Sirsoft\Board\Models\Post;
use Modules\Sirsoft\Board\Tests\BoardTestCase;
use PHPUnit\Framework\Attributes\Test;
/**
* PostResource 썸네일 URL 호출측 회귀 테스트 (#100 URL 조립 단일화)
*
* previewUrlForSlug() 헬퍼 자체가 아니라 **호출측**(PostResource
* getThumbnailUrlFromRelations)이 slug 인자를 올바르게 전달해 응답 문자열이
* 기존과 동일하게 직렬화되는지 고정합니다 — 헬퍼 출력만 고정하면 인자 전달
* 오류(슬러그 누락 등)가 전부 green 으로 통과합니다.
*/
class PostResourceThumbnailUrlTest extends BoardTestCase
{
/**
* 이미지 첨부를 가진 게시글을 생성합니다.
*
* @param string $mimeType 첨부 MIME 타입
* @return array{post: Post, attachment: Attachment} 게시글/첨부
*/
private function createPostWithAttachment(string $mimeType): array
{
$postId = $this->createTestPost();
$attachment = Attachment::create([
'board_id' => $this->board->id,
'post_id' => $postId,
'original_filename' => 'thumb.jpg',
'stored_filename' => 'stored-thumb.jpg',
'disk' => 'modules',
'path' => 'attachments/thumb.jpg',
'mime_type' => $mimeType,
'size' => 100,
'collection' => 'attachments',
'order' => 0,
]);
$post = Post::with(['thumbnailAttachment', 'board'])->findOrFail($postId);
return ['post' => $post, 'attachment' => $attachment];
}
/**
* @effects board_response_strings_unchanged
*/
#[Test]
public function thumbnail_serializes_preview_url_with_board_slug(): void
{
['post' => $post, 'attachment' => $attachment] = $this->createPostWithAttachment('image/jpeg');
$response = (new PostResource($post))->toArray(Request::create('/'));
$this->assertSame(
'/api/modules/sirsoft-board/boards/'.$this->board->slug.'/attachment/'.$attachment->hash.'/preview',
$response['thumbnail'],
);
}
/**
* @effects board_response_strings_unchanged
*/
#[Test]
public function thumbnail_is_null_for_non_image_attachment(): void
{
['post' => $post] = $this->createPostWithAttachment('application/pdf');
$response = (new PostResource($post))->toArray(Request::create('/'));
$this->assertNull($response['thumbnail']);
}
}