Files
Gnuboard7/plugins/_bundled/sirsoft-ckeditor5/tests/Unit/Services/ImageUploadServiceTest.php
T
HeuJung b1b5bfa417 feat(core,ecommerce,ckeditor5): 이미지 업로드 필터 훅 대칭화
공개 제보(리뷰 이미지에 filter_upload_file 부재)를 계기로 전 이미지 업로드
경로의 훅 트라이어드를 대칭화한다. 확장이 업로드 파일을 저장 전에 가로채
압축/변환할 수 있도록 하기 위함.

- 리뷰 이미지·CKEditor5 이미지 업로드에 filter_upload_file 필터 훅 추가
- 레이아웃 편집기 첨부 업로드에 훅 트라이어드(before/filter/after) 신설
- ckeditor5 1.0.2 버전 동기(manifest/package/composer/lock), 각 CHANGELOG 기재,
 README 기여자 등재, hooks.md 업로드 트라이어드 및 필터 반환 계약 문서화
- 시나리오 매니페스트(upload-filter-hook-parity) + 3계층 훅 발화 테스트 추가
2026-08-12 15:23:50 +09:00

92 lines
3.0 KiB
PHP

<?php
namespace Plugins\Sirsoft\Ckeditor5\Tests\Unit\Services;
use App\Contracts\Extension\StorageInterface;
use App\Extension\HookManager;
use Illuminate\Http\UploadedFile;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\Attributes\Test;
use Plugins\Sirsoft\Ckeditor5\Models\Ckeditor5ImageUpload;
use Plugins\Sirsoft\Ckeditor5\Repositories\Contracts\ImageUploadRepositoryInterface;
use Plugins\Sirsoft\Ckeditor5\Services\ImageUploadService;
use Plugins\Sirsoft\Ckeditor5\Tests\PluginTestCase;
/**
* ImageUploadService 단위 테스트
*
* 업로드 훅 트라이어드(before_upload → filter_upload_file → after_upload) 발화를 검증합니다.
* upload 자체 동작(저장/기록)은 Feature ImageUploadControllerTest 가 커버합니다.
*/
class ImageUploadServiceTest extends PluginTestCase
{
private ImageUploadService $service;
/** @var MockInterface&ImageUploadRepositoryInterface */
private $repository;
/** @var MockInterface&StorageInterface */
private $storage;
protected function setUp(): void
{
parent::setUp();
$this->repository = Mockery::mock(ImageUploadRepositoryInterface::class);
$this->storage = Mockery::mock(StorageInterface::class);
$this->service = new ImageUploadService($this->repository, $this->storage);
}
protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}
#[Test]
public function test_upload_fires_hooks(): void
{
// Arrange
$beforeUploadFired = false;
$afterUploadFired = false;
$filterApplied = false;
HookManager::addAction('sirsoft-ckeditor5.image.before_upload', function () use (&$beforeUploadFired) {
$beforeUploadFired = true;
});
HookManager::addFilter('sirsoft-ckeditor5.image.filter_upload_file', function ($file) use (&$filterApplied) {
$filterApplied = true;
return $file;
});
HookManager::addAction('sirsoft-ckeditor5.image.after_upload', function () use (&$afterUploadFired) {
$afterUploadFired = true;
});
$file = UploadedFile::fake()->image('test.jpg');
$this->storage->shouldReceive('put')->andReturn(true);
$this->storage->shouldReceive('getDisk')->andReturn('local');
$record = new Ckeditor5ImageUpload;
$this->repository->shouldReceive('create')->andReturn($record);
// Act
$this->service->upload($file, null);
// Assert
$this->assertTrue($beforeUploadFired, 'before_upload hook should be fired');
$this->assertTrue($filterApplied, 'filter_upload_file hook should be applied');
$this->assertTrue($afterUploadFired, 'after_upload hook should be fired');
// Cleanup hooks
HookManager::clearAction('sirsoft-ckeditor5.image.before_upload');
HookManager::clearFilter('sirsoft-ckeditor5.image.filter_upload_file');
HookManager::clearAction('sirsoft-ckeditor5.image.after_upload');
}
}