73 lines
2.7 KiB
PHP
73 lines
2.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_guest_is_redirected_to_login_for_the_pdf(): void
|
|
{
|
|
$this->get(route('mahasiswa.krs.cetak'))->assertRedirect(route('login'));
|
|
}
|
|
|
|
#[DataProvider('otherRoles')]
|
|
public function test_other_roles_are_forbidden_from_the_pdf(Role $role): void
|
|
{
|
|
$this->actingAs($this->userWithRole($role))->get(route('mahasiswa.krs.cetak'))->assertForbidden();
|
|
}
|
|
|
|
public function test_demo_student_gets_the_pdf_of_the_sample_plan(): void
|
|
{
|
|
$response = $this->actingAs($this->userWithRole(Role::Mahasiswa, profile: ['nim' => 'D1041211999']))
|
|
->get(route('mahasiswa.krs.cetak'))
|
|
->assertOk();
|
|
|
|
$this->assertSame('application/pdf', $response->headers->get('Content-Type'));
|
|
$this->assertStringContainsString('LIRS SEMESTER 9.pdf', $response->headers->get('Content-Disposition'));
|
|
$this->assertStringStartsWith('%PDF', $response->getContent());
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|