v7.0.0 release

This commit is contained in:
HeuJung committed 2026-07-01 10:30:32 +09:00
1 parent 0e7fa04b03
commit c4ea9a6cd1
3582 files changed
+626189 -160151

No files matched your search

@@ -2,13 +2,12 @@
namespace Tests\Feature\Plugin;
use App\Contracts\Extension\PluginInterface;
use App\Enums\ExtensionOwnerType;
use App\Enums\PermissionType;
use App\Extension\PluginManager;
use App\Models\Permission;
use App\Models\Role;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\File;
use ReflectionMethod;
use Tests\TestCase;
@@ -17,25 +16,31 @@ use Tests\TestCase;
*
* PluginManager.createPluginPermissions()가 모듈과 동일한
* 3레벨 계층(플러그인 → 카테고리 → 개별 권한)을 생성하는지 검증합니다.
*
* 검증 대상 플러그인: sirsoft-gdpr
* - 그룹 1 (sirsoft-gdpr)
* - 카테고리 1 (privacy)
* - 리프 2 (privacy.view, privacy.update)
*/
class PluginPermissionGroupTest extends TestCase
{
use RefreshDatabase;
private PluginManager $pluginManager;
/**
* GDPR 플러그인의 ServiceProvider/route/권한 정의를 테스트 앱에 로드.
*
* @var array<string>
*/
protected array $requiredExtensions = [
'plugins/sirsoft-gdpr',
];
private bool $verificationExistedBefore = false;
private PluginManager $pluginManager;
protected function setUp(): void
{
parent::setUp();
$activePath = base_path('plugins/sirsoft-verification');
if (File::isDirectory($activePath) && ! File::exists($activePath.'/plugin.php')) {
File::deleteDirectory($activePath);
}
$this->verificationExistedBefore = File::isDirectory($activePath);
$this->pluginManager = app(PluginManager::class);
$this->pluginManager->loadPlugins();
@@ -50,14 +55,27 @@ class PluginPermissionGroupTest extends TestCase
]);
}
protected function tearDown(): void
/**
* 검증 대상 GDPR 플러그인 인스턴스를 반환합니다.
*/
private function gdprPlugin(): PluginInterface
{
$activePath = base_path('plugins/sirsoft-verification');
if (! $this->verificationExistedBefore && File::isDirectory($activePath)) {
File::deleteDirectory($activePath);
}
$plugin = $this->pluginManager->getPlugin('sirsoft-gdpr');
$this->assertNotNull($plugin, 'GDPR 플러그인이 로드되어야 합니다');
parent::tearDown();
return $plugin;
}
/**
* PluginManager의 protected 메서드를 호출하는 헬퍼
*
* @param string $methodName 메서드명
* @param PluginInterface $plugin 대상 플러그인
*/
private function callProtectedMethod(string $methodName, PluginInterface $plugin): void
{
$method = new ReflectionMethod(PluginManager::class, $methodName);
$method->invoke($this->pluginManager, $plugin);
}
/**
@@ -65,20 +83,16 @@ class PluginPermissionGroupTest extends TestCase
*/
public function test_creates_plugin_group_node(): void
{
$plugin = $this->pluginManager->getPlugin('sirsoft-verification');
$this->assertNotNull($plugin, '본인인증 플러그인이 로드되어야 합니다');
$this->callProtectedMethod('createPluginPermissions', $this->gdprPlugin());
$method = new ReflectionMethod(PluginManager::class, 'createPluginPermissions');
$method->invoke($this->pluginManager, $plugin);
$groupNode = Permission::where('identifier', 'sirsoft-verification')
$groupNode = Permission::where('identifier', 'sirsoft-gdpr')
->whereNull('parent_id')
->first();
$this->assertNotNull($groupNode, '플러그인 그룹 노드가 생성되어야 합니다');
$this->assertEquals(ExtensionOwnerType::Plugin, $groupNode->extension_type);
$this->assertEquals('sirsoft-verification', $groupNode->extension_identifier);
$this->assertEquals('본인인증', $groupNode->getLocalizedName());
$this->assertEquals('sirsoft-gdpr', $groupNode->extension_identifier);
$this->assertEquals('GDPR (일반 데이터 보호 규정)', $groupNode->getLocalizedName());
}
/**
@@ -86,22 +100,16 @@ class PluginPermissionGroupTest extends TestCase
*/
public function test_creates_category_nodes_under_plugin(): void
{
$plugin = $this->pluginManager->getPlugin('sirsoft-verification');
$this->callProtectedMethod('createPluginPermissions', $this->gdprPlugin());
$method = new ReflectionMethod(PluginManager::class, 'createPluginPermissions');
$method->invoke($this->pluginManager, $plugin);
$groupNode = Permission::where('identifier', 'sirsoft-verification')->first();
$groupNode = Permission::where('identifier', 'sirsoft-gdpr')->first();
// 카테고리 노드 확인
$categories = Permission::where('parent_id', $groupNode->id)->orderBy('order')->get();
$this->assertCount(2, $categories, '2개 카테고리가 있어야 합니다');
$this->assertCount(1, $categories, '1개 카테고리가 있어야 합니다');
$this->assertEquals('sirsoft-verification.settings', $categories[0]->identifier);
$this->assertEquals('설정 관리', $categories[0]->getLocalizedName());
$this->assertEquals('sirsoft-verification.user', $categories[1]->identifier);
$this->assertEquals('사용자 인증 정보', $categories[1]->getLocalizedName());
$this->assertEquals('sirsoft-gdpr.privacy', $categories[0]->identifier);
$this->assertEquals('개인정보 보호', $categories[0]->getLocalizedName());
}
/**
@@ -109,24 +117,14 @@ class PluginPermissionGroupTest extends TestCase
*/
public function test_permissions_are_children_of_category_nodes(): void
{
$plugin = $this->pluginManager->getPlugin('sirsoft-verification');
$this->callProtectedMethod('createPluginPermissions', $this->gdprPlugin());
$method = new ReflectionMethod(PluginManager::class, 'createPluginPermissions');
$method->invoke($this->pluginManager, $plugin);
// settings 카테고리의 자식 권한
$settingsCategory = Permission::where('identifier', 'sirsoft-verification.settings')->first();
$settingsPerms = Permission::where('parent_id', $settingsCategory->id)->orderBy('order')->get();
$this->assertCount(2, $settingsPerms);
$this->assertEquals('sirsoft-verification.settings.view', $settingsPerms[0]->identifier);
$this->assertEquals('sirsoft-verification.settings.update', $settingsPerms[1]->identifier);
// user 카테고리의 자식 권한
$userCategory = Permission::where('identifier', 'sirsoft-verification.user')->first();
$userPerms = Permission::where('parent_id', $userCategory->id)->orderBy('order')->get();
$this->assertCount(2, $userPerms);
$this->assertEquals('sirsoft-verification.user.view', $userPerms[0]->identifier);
$this->assertEquals('sirsoft-verification.user.update', $userPerms[1]->identifier);
// privacy 카테고리의 자식 권한
$privacyCategory = Permission::where('identifier', 'sirsoft-gdpr.privacy')->first();
$privacyPerms = Permission::where('parent_id', $privacyCategory->id)->orderBy('order')->get();
$this->assertCount(2, $privacyPerms);
$this->assertEquals('sirsoft-gdpr.privacy.view', $privacyPerms[0]->identifier);
$this->assertEquals('sirsoft-gdpr.privacy.update', $privacyPerms[1]->identifier);
}
/**
@@ -134,36 +132,30 @@ class PluginPermissionGroupTest extends TestCase
*/
public function test_only_leaf_permissions_are_assignable(): void
{
$plugin = $this->pluginManager->getPlugin('sirsoft-verification');
$method = new ReflectionMethod(PluginManager::class, 'createPluginPermissions');
$method->invoke($this->pluginManager, $plugin);
$this->callProtectedMethod('createPluginPermissions', $this->gdprPlugin());
// 그룹 노드: 자식 있음 → 할당 불가
$groupNode = Permission::where('identifier', 'sirsoft-verification')->first();
$groupNode = Permission::where('identifier', 'sirsoft-gdpr')->first();
$this->assertTrue($groupNode->children()->exists());
// 카테고리 노드: 자식 있음 → 할당 불가
$settingsCategory = Permission::where('identifier', 'sirsoft-verification.settings')->first();
$this->assertTrue($settingsCategory->children()->exists());
$privacyCategory = Permission::where('identifier', 'sirsoft-gdpr.privacy')->first();
$this->assertTrue($privacyCategory->children()->exists());
// 리프 권한: 자식 없음 → 할당 가능
$leafPerm = Permission::where('identifier', 'sirsoft-verification.settings.view')->first();
$leafPerm = Permission::where('identifier', 'sirsoft-gdpr.privacy.view')->first();
$this->assertFalse($leafPerm->children()->exists());
}
/**
* 전체 권한 수 확인 (그룹 1 + 카테고리 2 + 개별 4 = 7)
* 전체 권한 수 확인 (그룹 1 + 카테고리 1 + 개별 2 = 4)
*/
public function test_total_permission_count(): void
{
$plugin = $this->pluginManager->getPlugin('sirsoft-verification');
$this->callProtectedMethod('createPluginPermissions', $this->gdprPlugin());
$method = new ReflectionMethod(PluginManager::class, 'createPluginPermissions');
$method->invoke($this->pluginManager, $plugin);
$total = Permission::where('extension_identifier', 'sirsoft-verification')->count();
$this->assertEquals(7, $total, '그룹 1개 + 카테고리 2개 + 개별 권한 4개 = 7개');
$total = Permission::where('extension_identifier', 'sirsoft-gdpr')->count();
$this->assertEquals(4, $total, '그룹 1개 + 카테고리 1개 + 개별 권한 2개 = 4개');
}
/**
@@ -171,7 +163,7 @@ class PluginPermissionGroupTest extends TestCase
*/
public function test_no_permissions_for_plugin_without_categories(): void
{
$mockPlugin = $this->createMock(\App\Contracts\Extension\PluginInterface::class);
$mockPlugin = $this->createMock(PluginInterface::class);
$mockPlugin->method('getPermissions')->willReturn([]);
$mockPlugin->method('getIdentifier')->willReturn('test-no-permissions');
@@ -186,23 +178,21 @@ class PluginPermissionGroupTest extends TestCase
*/
public function test_sync_updates_without_duplication(): void
{
$plugin = $this->pluginManager->getPlugin('sirsoft-verification');
$method = new ReflectionMethod(PluginManager::class, 'createPluginPermissions');
$plugin = $this->gdprPlugin();
// 1차 실행
$method->invoke($this->pluginManager, $plugin);
$firstCount = Permission::where('extension_identifier', 'sirsoft-verification')->count();
$firstGroupId = Permission::where('identifier', 'sirsoft-verification')->first()->id;
$this->callProtectedMethod('createPluginPermissions', $plugin);
$firstCount = Permission::where('extension_identifier', 'sirsoft-gdpr')->count();
$firstGroupId = Permission::where('identifier', 'sirsoft-gdpr')->first()->id;
// 2차 실행 (업데이트 시뮬레이션)
$method->invoke($this->pluginManager, $plugin);
$secondCount = Permission::where('extension_identifier', 'sirsoft-verification')->count();
$secondGroupId = Permission::where('identifier', 'sirsoft-verification')->first()->id;
$this->callProtectedMethod('createPluginPermissions', $plugin);
$secondCount = Permission::where('extension_identifier', 'sirsoft-gdpr')->count();
$secondGroupId = Permission::where('identifier', 'sirsoft-gdpr')->first()->id;
$this->assertEquals($firstCount, $secondCount, '중복 생성 없이 동일 수');
$this->assertEquals($firstGroupId, $secondGroupId, '그룹 노드 ID 유지');
$this->assertEquals(7, $secondCount);
$this->assertEquals(4, $secondCount);
}
/**
@@ -210,17 +200,13 @@ class PluginPermissionGroupTest extends TestCase
*/
public function test_remove_deletes_all_permission_levels(): void
{
$plugin = $this->pluginManager->getPlugin('sirsoft-verification');
$plugin = $this->gdprPlugin();
$createMethod = new ReflectionMethod(PluginManager::class, 'createPluginPermissions');
$createMethod->invoke($this->pluginManager, $plugin);
$this->callProtectedMethod('createPluginPermissions', $plugin);
$this->assertEquals(4, Permission::where('extension_identifier', 'sirsoft-gdpr')->count());
$this->assertEquals(7, Permission::where('extension_identifier', 'sirsoft-verification')->count());
$removeMethod = new ReflectionMethod(PluginManager::class, 'removePluginPermissions');
$removeMethod->invoke($this->pluginManager, $plugin);
$this->assertEquals(0, Permission::where('extension_identifier', 'sirsoft-verification')->count());
$this->callProtectedMethod('removePluginPermissions', $plugin);
$this->assertEquals(0, Permission::where('extension_identifier', 'sirsoft-gdpr')->count());
}
/**
@@ -228,35 +214,32 @@ class PluginPermissionGroupTest extends TestCase
*/
public function test_assign_permissions_to_roles_with_categories(): void
{
$plugin = $this->pluginManager->getPlugin('sirsoft-verification');
$plugin = $this->gdprPlugin();
// 플러그인 역할 생성
Role::create([
'identifier' => 'sirsoft-verification.manager',
'name' => ['ko' => '본인인증 관리자', 'en' => 'Verification Manager'],
'description' => ['ko' => '본인인증 관리', 'en' => 'Verification management'],
'identifier' => 'sirsoft-gdpr.privacy',
'name' => ['ko' => '개인정보 운영자', 'en' => 'Privacy Operator'],
'description' => ['ko' => '개인정보 운영', 'en' => 'Privacy operation'],
'extension_type' => ExtensionOwnerType::Plugin,
'extension_identifier' => 'sirsoft-verification',
'extension_identifier' => 'sirsoft-gdpr',
'is_active' => true,
]);
// 권한 생성
$createMethod = new ReflectionMethod(PluginManager::class, 'createPluginPermissions');
$createMethod->invoke($this->pluginManager, $plugin);
$this->callProtectedMethod('createPluginPermissions', $plugin);
// 역할 할당
$assignMethod = new ReflectionMethod(PluginManager::class, 'assignPermissionsToRoles');
$assignMethod->invoke($this->pluginManager, $plugin);
$this->callProtectedMethod('assignPermissionsToRoles', $plugin);
// admin 역할에 4개 리프 권한 할당 확인
// admin 역할에 2개 리프 권한 할당 확인
$adminRole = Role::where('identifier', 'admin')->first();
$assignedPerms = $adminRole->permissions()->where('extension_identifier', 'sirsoft-verification')->get();
$this->assertCount(4, $assignedPerms, 'admin 역할에 4개 리프 권한이 할당되어야 합니다');
$assignedPerms = $adminRole->permissions()->where('extension_identifier', 'sirsoft-gdpr')->get();
$this->assertCount(2, $assignedPerms, 'admin 역할에 2개 리프 권한이 할당되어야 합니다');
// 그룹/카테고리 노드는 역할에 할당되지 않음
$assignedIdentifiers = $assignedPerms->pluck('identifier')->toArray();
$this->assertNotContains('sirsoft-verification', $assignedIdentifiers);
$this->assertNotContains('sirsoft-verification.settings', $assignedIdentifiers);
$this->assertNotContains('sirsoft-verification.user', $assignedIdentifiers);
$this->assertNotContains('sirsoft-gdpr', $assignedIdentifiers);
$this->assertNotContains('sirsoft-gdpr.privacy', $assignedIdentifiers);
}
}