51 lines
1.7 KiB
PHP
51 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Mahasiswa;
|
|
|
|
use App\Enums\Role;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use Tests\TestCase;
|
|
|
|
/** KRS untuk akun demo (provider users): akses, halaman prototipe, dan aksi KRS asli tertutup. */
|
|
class KrsTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
/** @return array<string, array{Role}> */
|
|
public static function otherRoles(): array
|
|
{
|
|
return [
|
|
'superuser' => [Role::Superuser],
|
|
'admin' => [Role::Admin],
|
|
'operator' => [Role::Operator],
|
|
'dosen' => [Role::Dosen],
|
|
];
|
|
}
|
|
|
|
public function test_guest_is_redirected_to_login(): void
|
|
{
|
|
$this->get(route('mahasiswa.krs'))->assertRedirect(route('login'));
|
|
$this->post(route('mahasiswa.krs.ambil'), ['jadwal' => 1])->assertRedirect(route('login'));
|
|
}
|
|
|
|
#[DataProvider('otherRoles')]
|
|
public function test_other_roles_are_forbidden(Role $role): void
|
|
{
|
|
$user = $this->userWithRole($role);
|
|
|
|
$this->actingAs($user)->get(route('mahasiswa.krs'))->assertForbidden();
|
|
$this->actingAs($user)->post(route('mahasiswa.krs.ambil'), ['jadwal' => 1])->assertForbidden();
|
|
$this->actingAs($user)->delete(route('mahasiswa.krs.hapus', 1))->assertForbidden();
|
|
}
|
|
|
|
public function test_demo_student_sees_the_prototype_and_cannot_use_real_actions(): void
|
|
{
|
|
$user = $this->userWithRole(Role::Mahasiswa);
|
|
|
|
$this->actingAs($user)->get(route('mahasiswa.krs'))->assertOk()->assertSee('Kartu Rencana Studi');
|
|
$this->actingAs($user)->post(route('mahasiswa.krs.ambil'), ['jadwal' => 1])->assertNotFound();
|
|
$this->actingAs($user)->delete(route('mahasiswa.krs.hapus', 1))->assertNotFound();
|
|
}
|
|
}
|