fix failed tests
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 6m55s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 50s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 6m55s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 50s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
This commit is contained in:
@@ -94,6 +94,64 @@ trait CreatesApiTestUsers
|
||||
return $user;
|
||||
}
|
||||
|
||||
protected function actingAsTeacher(array $overrides = []): User
|
||||
{
|
||||
$user = $this->createApiUserWithRole('teacher', $overrides);
|
||||
$this->actingAs($user, 'api');
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
protected function actingAsStaff(array $overrides = []): User
|
||||
{
|
||||
$user = $this->createApiUserWithRole('admin', $overrides);
|
||||
$this->actingAs($user, 'api');
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
protected function actingAsParent(array $overrides = []): User
|
||||
{
|
||||
$user = $this->createApiUserWithRole('parent', $overrides);
|
||||
$this->actingAs($user, 'api');
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
protected function actingAsWithPermission(string $permission, array $overrides = []): User
|
||||
{
|
||||
$user = $this->createApiUserWithRole('administrator', $overrides);
|
||||
|
||||
if (\Illuminate\Support\Facades\Schema::hasTable('permissions') && \Illuminate\Support\Facades\Schema::hasTable('role_permissions')) {
|
||||
$permissionId = (int) \Illuminate\Support\Facades\DB::table('permissions')->where('name', $permission)->value('id');
|
||||
if ($permissionId > 0) {
|
||||
$roleIds = $user->roles()->pluck('roles.id')->all();
|
||||
foreach ($roleIds as $roleId) {
|
||||
\Illuminate\Support\Facades\DB::table('role_permissions')->updateOrInsert(
|
||||
['role_id' => $roleId, 'permission_id' => $permissionId],
|
||||
[
|
||||
'can_create' => true,
|
||||
'can_read' => true,
|
||||
'can_update' => true,
|
||||
'can_delete' => true,
|
||||
'can_manage' => true,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->actingAs($user, 'api');
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Keep test fixtures aligned with explicit permission middleware.
|
||||
|
||||
Reference in New Issue
Block a user