[FEAT] 完善全站多語系支援、角色權限篩選優化及 UI 元件重構
All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 1m4s
All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 1m4s
- [DOCS] 補齊 en, ja, zh_TW 語系檔翻譯並完善驗證錯誤訊息 (validation.php) - [FEAT] 角色權限頁面新增「所屬單位」篩選功能 (僅限系統管理員) - [STYLE] 優化角色列表顯示,將「類型」變更為具體「所屬單位」名稱 - [STYLE] 修正角色頁面工具列佈局,搜尋框置前並修正下拉箭頭顯示 - [REFACTOR] 統一全站刪除確認視窗,導入新版 <x-delete-confirm-modal /> 組件 - [REFACTOR] 優化 PermissionController 查詢效能 (Eager Loading) - [FIX] 修正 RoleSeeder 角色命名與資料庫同步邏輯
This commit is contained in:
91
tests/Feature/RoleDeletionTest.php
Normal file
91
tests/Feature/RoleDeletionTest.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\System\Company;
|
||||
use App\Models\System\User;
|
||||
use App\Models\System\Role;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RoleDeletionTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->artisan('db:seed', ['--class' => 'RoleSeeder']);
|
||||
}
|
||||
|
||||
public function test_cannot_delete_role_with_active_users()
|
||||
{
|
||||
$company = Company::create([
|
||||
'name' => 'Test Company',
|
||||
'code' => 'TEST',
|
||||
'status' => 1,
|
||||
]);
|
||||
$admin = User::create([
|
||||
'name' => 'Admin User',
|
||||
'username' => 'admin_user_' . uniqid(),
|
||||
'email' => 'admin_' . uniqid() . '@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
'company_id' => $company->id,
|
||||
]);
|
||||
$admin->assignRole('super-admin');
|
||||
|
||||
$role = Role::create([
|
||||
'name' => 'Test Role',
|
||||
'company_id' => $company->id,
|
||||
'guard_name' => 'web',
|
||||
'is_system' => false,
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => 'Test User',
|
||||
'username' => 'test_user_' . uniqid(),
|
||||
'email' => 'user_' . uniqid() . '@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
'company_id' => $company->id,
|
||||
]);
|
||||
$user->assignRole($role);
|
||||
|
||||
$response = $this->actingAs($admin)
|
||||
->delete(route('admin.permission.roles.destroy', $role->id));
|
||||
|
||||
$response->assertRedirect();
|
||||
$response->assertSessionHas('error', __('Cannot delete role with active users.'));
|
||||
$this->assertDatabaseHas('roles', ['id' => $role->id]);
|
||||
}
|
||||
|
||||
public function test_can_delete_role_without_active_users()
|
||||
{
|
||||
$company = Company::create([
|
||||
'name' => 'Test Company 2',
|
||||
'code' => 'TEST2',
|
||||
'status' => 1,
|
||||
]);
|
||||
$admin = User::create([
|
||||
'name' => 'Admin User 2',
|
||||
'username' => 'admin_user_2_' . uniqid(),
|
||||
'email' => 'admin2_' . uniqid() . '@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
'company_id' => $company->id,
|
||||
]);
|
||||
$admin->assignRole('super-admin');
|
||||
|
||||
$role = Role::create([
|
||||
'name' => 'Empty Role',
|
||||
'company_id' => $company->id,
|
||||
'guard_name' => 'web',
|
||||
'is_system' => false,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($admin)
|
||||
->delete(route('admin.permission.roles.destroy', $role->id));
|
||||
|
||||
$response->assertRedirect();
|
||||
$response->assertSessionHas('success');
|
||||
$this->assertDatabaseMissing('roles', ['id' => $role->id]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user