v7.0.0-beta.1 release

This commit is contained in:
HeuJung
2026-04-01 10:30:52 +09:00
commit 6595fd0eb5
3967 changed files with 1875383 additions and 0 deletions
+379
View File
@@ -0,0 +1,379 @@
<?php
namespace Tests\Unit\Models;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use PHPUnit\Framework\Attributes\Group;
/**
* sirsoft-board 모듈의 Board 모델 테스트
*/
#[Group('module-dependent')]
class BoardModelTest extends TestCase
{
use RefreshDatabase;
/**
* Board 모델 클래스명
*/
private string $boardClass = 'Modules\\Sirsoft\\Board\\Models\\Board';
/**
* 테스트 환경 설정
*/
#[Group('module')]
protected function setUp(): void
{
parent::setUp();
// Board 클래스가 로드되어 있지 않으면 테스트 스킵
if (! class_exists($this->boardClass)) {
$this->markTestSkipped('sirsoft-board 모듈이 설치되어 있지 않습니다.');
}
// 모듈 마이그레이션 실행
$this->artisan('migrate', [
'--path' => 'modules/sirsoft-board/database/migrations',
'--realpath' => true,
]);
}
/**
* Board 모델 인스턴스 생성
*
* @param array $data 생성 데이터
* @return mixed Board 모델 인스턴스
*/
private function createBoard(array $data): mixed
{
return $this->boardClass::create($data);
}
/**
* fillable 속성이 정상적으로 할당되는지 테스트
*/
public function test_fillable_attributes_are_assignable(): void
{
// Arrange
$data = [
'name' => ['ko' => '공지사항', 'en' => 'Notice Board'],
'slug' => 'notice',
'per_page' => 20,
'per_page_mobile' => 15,
'order_by' => 'created_at',
'order_direction' => 'DESC',
'type' => 'basic',
'categories' => ['공지사항', '자유게시판'],
'show_view_count' => true,
'secret_mode' => 'disabled',
'use_comment' => true,
'use_reply' => true,
'use_report' => false,
'min_title_length' => 2,
'max_title_length' => 200,
'min_content_length' => 10,
'max_content_length' => 10000,
'min_comment_length' => 2,
'max_comment_length' => 1000,
'use_file_upload' => false,
'max_file_size' => 10485760,
'max_file_count' => 5,
'allowed_extensions' => ['jpg', 'png', 'pdf'],
'comment_order' => 'ASC',
'board_manager_id' => null,
'notify_author_on_comment' => false,
'notify_admin_on_post' => false,
'blocked_keywords' => ['금지어1', '금지어2'],
];
// Act
$board = $this->createBoard($data);
// Assert
$this->assertInstanceOf($this->boardClass, $board);
$this->assertEquals('notice', $board->slug);
$this->assertEquals(20, $board->per_page);
$this->assertEquals('basic', $board->type);
}
/**
* name 필드가 배열로 캐스팅되는지 테스트
*/
public function test_name_is_cast_to_array(): void
{
// Arrange
$nameData = [
'ko' => '공지사항',
'en' => 'Notice Board',
];
// Act
$board = $this->createBoard([
'name' => $nameData,
'slug' => 'notice',
]);
// Assert
$this->assertIsArray($board->name);
$this->assertEquals($nameData, $board->name);
}
/**
* categories 필드가 배열로 캐스팅되는지 테스트
*/
public function test_categories_is_cast_to_array(): void
{
// Arrange
$categories = ['공지사항', '자유게시판', '질문답변'];
// Act
$board = $this->createBoard([
'name' => ['ko' => '게시판'],
'slug' => 'test-board',
'categories' => $categories,
]);
// Assert
$this->assertIsArray($board->categories);
$this->assertEquals($categories, $board->categories);
}
/**
* allowed_extensions 필드가 배열로 캐스팅되는지 테스트
*/
public function test_allowed_extensions_is_cast_to_array(): void
{
// Arrange
$extensions = ['jpg', 'jpeg', 'png', 'gif', 'pdf', 'zip'];
// Act
$board = $this->createBoard([
'name' => ['ko' => '게시판'],
'slug' => 'test-board',
'allowed_extensions' => $extensions,
]);
// Assert
$this->assertIsArray($board->allowed_extensions);
$this->assertEquals($extensions, $board->allowed_extensions);
}
/**
* blocked_keywords 필드가 배열로 캐스팅되는지 테스트
*/
public function test_blocked_keywords_is_cast_to_array(): void
{
// Arrange
$keywords = ['금지어1', '금지어2', '금지어3'];
// Act
$board = $this->createBoard([
'name' => ['ko' => '게시판'],
'slug' => 'test-board',
'blocked_keywords' => $keywords,
]);
// Assert
$this->assertIsArray($board->blocked_keywords);
$this->assertEquals($keywords, $board->blocked_keywords);
}
/**
* boolean 필드가 정상적으로 캐스팅되는지 테스트
*/
public function test_boolean_fields_are_cast_correctly(): void
{
// Act
$board = $this->createBoard([
'name' => ['ko' => '게시판'],
'slug' => 'test-board',
'show_view_count' => true,
'use_comment' => false,
'use_reply' => true,
'use_report' => false,
'use_file_upload' => true,
'notify_author_on_comment' => false,
'notify_admin_on_post' => true,
]);
// Assert
$this->assertIsBool($board->show_view_count);
$this->assertTrue($board->show_view_count);
$this->assertFalse($board->use_comment);
$this->assertTrue($board->use_reply);
$this->assertFalse($board->use_report);
$this->assertTrue($board->use_file_upload);
$this->assertFalse($board->notify_author_on_comment);
$this->assertTrue($board->notify_admin_on_post);
}
/**
* boardManager 관계 테스트
*/
public function test_belongs_to_board_manager(): void
{
// Arrange
$user = User::factory()->create();
// Act
$board = $this->createBoard([
'name' => ['ko' => '게시판'],
'slug' => 'test-board',
'board_manager_id' => $user->id,
]);
// Assert
$this->assertInstanceOf(User::class, $board->boardManager);
$this->assertEquals($user->id, $board->boardManager->id);
}
/**
* creator 관계 테스트
*/
public function test_belongs_to_creator(): void
{
// Arrange
$user = User::factory()->create();
// Act
$board = $this->createBoard([
'name' => ['ko' => '게시판'],
'slug' => 'test-board',
]);
$board->created_by = $user->id;
$board->save();
// Assert
$board->refresh();
$this->assertInstanceOf(User::class, $board->creator);
$this->assertEquals($user->id, $board->creator->id);
}
/**
* updater 관계 테스트
*/
public function test_belongs_to_updater(): void
{
// Arrange
$user = User::factory()->create();
// Act
$board = $this->createBoard([
'name' => ['ko' => '게시판'],
'slug' => 'test-board',
]);
$board->updated_by = $user->id;
$board->save();
// Assert
$board->refresh();
$this->assertInstanceOf(User::class, $board->updater);
$this->assertEquals($user->id, $board->updater->id);
}
/**
* getLocalizedName 메서드 테스트 (한국어)
*/
public function test_get_localized_name_returns_korean_name(): void
{
// Arrange
$board = $this->createBoard([
'name' => [
'ko' => '공지사항',
'en' => 'Notice Board',
],
'slug' => 'notice',
]);
// Act
$localizedName = $board->getLocalizedName('ko');
// Assert
$this->assertEquals('공지사항', $localizedName);
}
/**
* getLocalizedName 메서드 테스트 (영어)
*/
public function test_get_localized_name_returns_english_name(): void
{
// Arrange
$board = $this->createBoard([
'name' => [
'ko' => '공지사항',
'en' => 'Notice Board',
],
'slug' => 'notice',
]);
// Act
$localizedName = $board->getLocalizedName('en');
// Assert
$this->assertEquals('Notice Board', $localizedName);
}
/**
* getLocalizedName 메서드 테스트 (fallback)
*/
public function test_get_localized_name_returns_fallback_when_locale_not_found(): void
{
// Arrange
$board = $this->createBoard([
'name' => [
'ko' => '공지사항',
'en' => 'Notice Board',
],
'slug' => 'notice',
]);
// Act
$localizedName = $board->getLocalizedName('ja'); // 존재하지 않는 로케일
// Assert
// fallback_locale이 'ko'이므로 한국어 이름이 반환되어야 함
$this->assertEquals('공지사항', $localizedName);
}
/**
* localizedName Attribute 테스트
*/
public function test_localized_name_attribute_returns_current_locale_name(): void
{
// Arrange
app()->setLocale('ko');
$board = $this->createBoard([
'name' => [
'ko' => '공지사항',
'en' => 'Notice Board',
],
'slug' => 'notice',
]);
// Act
$localizedName = $board->localized_name;
// Assert
$this->assertEquals('공지사항', $localizedName);
}
/**
* guarded 속성 테스트 (created_by, updated_by)
*/
public function test_created_by_and_updated_by_are_guarded(): void
{
// Act
$board = $this->createBoard([
'name' => ['ko' => '게시판'],
'slug' => 'test-board',
'created_by' => 999, // guarded이므로 무시되어야 함
'updated_by' => 999, // guarded이므로 무시되어야 함
]);
// Assert
$this->assertNull($board->created_by);
$this->assertNull($board->updated_by);
}
}