useLegacyDatabase(); } private function login(): void { $this->post(route('login.store'), ['username' => 'D1041191001', 'password' => 'rahasia-mhs']) ->assertRedirect(route('mahasiswa.dashboard')); } /** KRS periode 368 (kelas 301 dan 302) dan nilai semester lama (362, 365, 366) untuk mahasiswa 500. */ private function seedAll(): void { $this->seedLegacyGrades(); $this->seedLegacyKrs(); } /** Dosen PA, foto, dan data diri untuk mahasiswa 500. */ private function seedIdentity(): void { $db = DB::connection('untan'); ob_start(); imagepng(imagecreatetruecolor(3, 4)); $png = (string) ob_get_clean(); $db->table('t_mahasiswa')->where('idmahasiswa', 500)->update([ 'pic' => $png, 'tmplahir' => 'PONTIANAK', 'tgllahir' => '1998-05-13', 'alamat_mhs' => 'JL. PARIT HAJI MUKSIN 2', ]); $db->table('t_jenisprogram')->insert(['idprogram' => 1, 'program' => 'Reguler A']); } /** @return array */ private function sheet(?int $periode): array { return app(StudyPlanSheet::class)->forPeriod(500, $periode); } public function test_pdf_is_streamed_inline_with_semester_in_the_file_name(): void { $this->seedAll(); $this->login(); $response = $this->get(route('mahasiswa.krs.cetak', ['semester' => 368]))->assertOk(); $this->assertSame('application/pdf', $response->headers->get('Content-Type')); $this->assertStringContainsString('inline', $response->headers->get('Content-Disposition')); $this->assertStringContainsString('LIRS SEMESTER 3.pdf', $response->headers->get('Content-Disposition')); $this->assertStringStartsWith('%PDF', $response->getContent()); } public function test_previous_semesters_can_be_printed_too(): void { $this->seedAll(); $this->login(); $this->get(route('mahasiswa.krs.cetak', ['semester' => 365]))->assertOk() ->assertHeader('Content-Type', 'application/pdf'); $this->assertSame(['Jaringan Komputer', 'Kalkulus', 'Skripsi'], array_column($this->sheet(365)['matkul'], 'nama')); $this->assertSame(['Algoritma', 'Basis Data'], array_column($this->sheet(362)['matkul'], 'nama')); } public function test_page_links_the_current_print_button_and_lists_previous_semesters(): void { $this->seedAll(); $this->login(); $response = $this->get(route('mahasiswa.krs'))->assertOk() ->assertSee('href="'.route('mahasiswa.krs.cetak', ['semester' => 368]).'"', false) ->assertSee('Riwayat KRS'); $links = array_map( fn ($node): string => $node->getAttribute('href'), iterator_to_array($this->dom($response)->query('//section[@aria-labelledby="judul-riwayat"]//a')), ); $this->assertSame([ route('mahasiswa.krs.cetak', ['semester' => 366]), route('mahasiswa.krs.cetak', ['semester' => 365]), route('mahasiswa.krs.cetak', ['semester' => 362]), ], $links, 'Semester sebelumnya, terbaru dulu, tanpa semester berjalan.'); $response->assertSee('Semester 2, 2019/2020 Genap', false); } public function test_page_without_previous_semesters_has_no_history_panel(): void { $this->seedLegacyKrs(); $this->login(); $this->get(route('mahasiswa.krs'))->assertOk()->assertDontSee('Riwayat KRS'); } public function test_sheet_lists_the_students_courses_with_schedule_and_lecturers(): void { $this->seedAll(); // KST batal tidak dicetak; peserta lain tidak ikut. DB::connection('untan')->table('t_kst')->insert([ 'idmahasiswa' => 500, 'idjadwal' => 304, 'idmatakuliah' => 304, 'idperiode' => 368, 'stat' => 2, ]); $sheet = $this->sheet(368); $this->assertSame(3, $sheet['semester']); $this->assertSame('2020/2021 - Ganjil', $sheet['tahun_akademik']); $this->assertSame(6, $sheet['jumlah_sks']); $this->assertSame(['IF311', 'IF312'], array_column($sheet['matkul'], 'kode')); $this->assertSame([ 'no' => 1, 'kode' => 'IF311', 'nama' => 'Sistem Basis Data', 'sks' => 3, 'kelas' => 'A', 'jadwal' => ['Senin - 07:30:00 s/d 09:10:00 (Lab Komputer 1)'], 'dosen' => ['Siti Aminah, M.Pd.'], ], $sheet['matkul'][0]); $this->assertSame([], $sheet['matkul'][1]['jadwal']); $this->assertSame([], $sheet['matkul'][1]['dosen']); } public function test_previous_results_come_from_the_regular_semester_before_the_printed_one(): void { $this->seedAll(); // Sebelum 368 (pendek 366 dilewati): semester 2 (365), IPS 1,95 dan IPK terhitung ulang 3,47. $sheet = $this->sheet(368); $this->assertSame([1.95, 3.47], [$sheet['ips_sebelumnya'], $sheet['ipk_sebelumnya']]); // Sebelum 365: semester 1 (362), IPS dan IPK 3,6. $sheet = $this->sheet(365); $this->assertSame([3.6, 3.6], [$sheet['ips_sebelumnya'], $sheet['ipk_sebelumnya']]); // Semester pertama: belum ada hasil sebelumnya. $sheet = $this->sheet(362); $this->assertNull($sheet['ips_sebelumnya']); $this->assertNull($sheet['ipk_sebelumnya']); } public function test_maximum_credits_follow_the_legacy_function(): void { $this->seedAll(); $this->assertSame(24, $this->sheet(368)['maks_sks']); } public function test_identity_comes_from_the_student_master_data(): void { $this->seedAll(); $this->seedIdentity(); $sheet = $this->sheet(368); $this->assertSame('Fakultas Teknik', $sheet['fakultas_nama']); $this->assertSame('Teknik Informatika', $sheet['prodi']); $this->assertSame('Reguler A', $sheet['program']); $this->assertSame(['D1041191001', 'Rina Lestari'], [$sheet['nim'], $sheet['nama']]); $this->assertSame('PONTIANAK, 13/05/1998', $sheet['lahir']); $this->assertSame('JL. PARIT HAJI MUKSIN 2', $sheet['alamat']); $this->assertSame(['0001017501', 'Siti Aminah, M.Pd.'], [$sheet['pa_nip'], $sheet['pa_nama']]); $this->assertStringStartsWith('data:image/png;base64,', $sheet['foto']); } public function test_rendered_sheet_has_the_lirs_layout(): void { $this->seedAll(); $this->seedIdentity(); $html = view('mahasiswa.pdf.krs', ['card' => $this->sheet(368)])->render(); foreach ([ 'KEMENTERIAN PENDIDIKAN DAN', 'UNIVERSITAS TANJUNGPURA', 'FAKULTAS TEKNIK', 'LEMBAR ISIAN RENCANA STUDI (LIRS)', 'Nomor Induk Mahasiswa', 'D1041191001', 'Nama Lengkap : Rina Lestari', 'Tempat/Tanggal Lahir : PONTIANAK, 13/05/1998', 'Alamat Sekarang : JL. PARIT HAJI MUKSIN 2', 'Tahun Akademik', '2020/2021 - Ganjil', 'Teknik Informatika', 'Reguler A', 'Kode MK', 'Nama Mata Kuliah', 'KLS', 'Sistem Basis Data', 'Senin - 07:30:00 s/d 09:10:00 (Lab Komputer 1)', '1. Siti Aminah, M.Pd.', 'Jumlah Kredit', 'Indeks Prestasi Semester sebelumnya', ': 1.95', 'Indeks Prestasi Komulatif sebelumnya', ': 3.47', 'Maksimum SKS yang dapat diambil', ': 24', 'LIRS disalin', 'Dosen', 'Pembimbing Akademik', 'NIP. 0001017501', 'Lambang Universitas Tanjungpura', 'data:image/png;base64,', ] as $text) { $this->assertStringContainsString($text, $html); } $this->assertStringNotContainsString('Kecerdasan Buatan', $html, 'Kelas yang tidak diambil mahasiswa ini.'); } public function test_sheet_without_advisor_or_photo_still_renders(): void { $this->seedAll(); DB::connection('untan')->table('t_mahasiswa')->where('idmahasiswa', 500)->update(['idpa' => null]); $sheet = $this->sheet(362); $this->assertNull($sheet['foto']); $this->assertNull($sheet['pa_nama']); $html = view('mahasiswa.pdf.krs', ['card' => $sheet])->render(); $this->assertStringNotContainsString('NIP. ', $html); $this->assertStringContainsString('class="foto"', $html); $this->assertStringContainsString(': -', $html, 'Hasil sebelumnya kosong pada semester pertama.'); } public function test_unknown_semester_falls_back_to_the_latest_plan(): void { $this->seedAll(); $this->login(); $this->assertSame('2020/2021 - Ganjil', $this->sheet(999)['tahun_akademik']); $this->get(route('mahasiswa.krs.cetak', ['semester' => 999]))->assertOk(); $this->get(route('mahasiswa.krs.cetak'))->assertOk(); } public function test_other_students_plans_are_never_printed(): void { $this->seedAll(); foreach ([null, 362, 365, 368] as $periode) { $this->assertNotContains('Nilai Mahasiswa Lain', array_column($this->sheet($periode)['matkul'], 'nama')); $this->assertNotContains('Kecerdasan Buatan', array_column($this->sheet($periode)['matkul'], 'nama')); } } public function test_student_without_a_plan_gets_not_found(): void { $this->login(); $this->get(route('mahasiswa.krs.cetak'))->assertNotFound(); } public function test_guest_is_redirected_to_login(): void { $this->get(route('mahasiswa.krs.cetak'))->assertRedirect(route('login')); } }