*/ 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.transkrip'))->assertRedirect(route('login')); } #[DataProvider('otherRoles')] public function test_other_roles_are_forbidden(Role $role): void { $this->actingAs($this->userWithRole($role))->get(route('mahasiswa.transkrip'))->assertForbidden(); } public function test_mahasiswa_sees_the_page(): void { $this->actingAs($this->userWithRole(Role::Mahasiswa)) ->get(route('mahasiswa.transkrip')) ->assertOk() ->assertSee('Transkrip nilai') ->assertSee('Cetak') ->assertSee('href="'.route('mahasiswa.transkrip.cetak').'"', false); } public function test_guest_is_redirected_to_login_for_the_pdf(): void { $this->get(route('mahasiswa.transkrip.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.transkrip.cetak'))->assertForbidden(); } public function test_mahasiswa_gets_the_pdf_of_the_sample_transcript(): void { $response = $this->actingAs($this->userWithRole(Role::Mahasiswa, profile: ['nim' => 'D1041211999'])) ->get(route('mahasiswa.transkrip.cetak')) ->assertOk(); $this->assertSame('application/pdf', $response->headers->get('Content-Type')); $this->assertStringContainsString('Transkrip - D1041211999.pdf', $response->headers->get('Content-Disposition')); $this->assertStringStartsWith('%PDF', $response->getContent()); } }