208 lines
8.6 KiB
PHP
208 lines
8.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Mahasiswa;
|
|
|
|
use App\Support\Legacy\StudyReportCard;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\Concerns\FakesLegacyDatabase;
|
|
use Tests\TestCase;
|
|
|
|
/** Cetak LIHS (KHS PDF) dari nilai asli DB lama untuk mahasiswa yang masuk lewat provider legacy. */
|
|
class LegacyKhsCetakTest extends TestCase
|
|
{
|
|
use FakesLegacyDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->useLegacyDatabase();
|
|
}
|
|
|
|
private function login(): void
|
|
{
|
|
$this->post(route('login.store'), ['username' => 'D1041191001', 'password' => 'rahasia-mhs'])
|
|
->assertRedirect(route('mahasiswa.dashboard'));
|
|
}
|
|
|
|
/** Dosen PA, foto, dan Kasubbag Akademik fakultas (Fakultas Teknik = bagian 5) 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(['idpa' => 11, 'pic' => $png]);
|
|
$db->table('t_jabatanbagian')->insert(['idjabatanbagian' => 90, 'idbagian' => 5, 'idjenisjabatan' => 1]);
|
|
$db->table('t_jabatanpegawai')->insert(['idpegawai' => 10, 'idjabatanbagian' => 90, 'aktif' => 1]);
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
private function card(?int $periode): array
|
|
{
|
|
return app(StudyReportCard::class)->forPeriod(500, $periode);
|
|
}
|
|
|
|
public function test_pdf_is_streamed_inline_with_semester_in_the_file_name(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
$this->login();
|
|
|
|
$response = $this->get(route('mahasiswa.khs.cetak', ['semester' => 365]))->assertOk();
|
|
|
|
$this->assertSame('application/pdf', $response->headers->get('Content-Type'));
|
|
$this->assertStringContainsString('inline', $response->headers->get('Content-Disposition'));
|
|
$this->assertStringContainsString('LIHS_SEMESTER 2.pdf', $response->headers->get('Content-Disposition'));
|
|
$this->assertStringStartsWith('%PDF', $response->getContent());
|
|
}
|
|
|
|
public function test_page_links_the_print_button_to_the_pdf_of_the_active_semester(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
$this->login();
|
|
|
|
$this->get(route('mahasiswa.khs', ['semester' => 362]))->assertOk()
|
|
->assertSee('href="'.route('mahasiswa.khs.cetak', ['semester' => 362]).'"', false);
|
|
}
|
|
|
|
public function test_semester_figures_follow_legacy_rules(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
|
|
// Semester 2 (365): Jaringan 3 SKS B+ (3,25) terbit, Kalkulus 2 SKS belum terbit, Skripsi tipe 2 tanpa nilai dan KST batal tidak dihitung.
|
|
$card = $this->card(365);
|
|
|
|
$this->assertSame(2, $card['semester']);
|
|
$this->assertSame('2019/2020 - Genap', $card['tahun_akademik']);
|
|
$this->assertSame(['beban' => 5, 'lulus' => 3, 'am' => 9.75, 'ip' => 1.95], $card['semester_ini']);
|
|
$this->assertSame(['Jaringan Komputer', 'Kalkulus'], array_column($card['matkul'], 'nama'));
|
|
|
|
$kalkulus = $card['matkul'][1];
|
|
$this->assertSame(['Belum terbit', null, null, null], [$kalkulus['ket'], $kalkulus['nm'], $kalkulus['hm'], $kalkulus['kn']]);
|
|
|
|
$jaringan = $card['matkul'][0];
|
|
$this->assertSame([1, 'B+', 3.25, 9.75, 'Antara Sangat Baik dan Baik'], [$jaringan['no'], $jaringan['hm'], $jaringan['nm'], $jaringan['kn'], $jaringan['ket']]);
|
|
}
|
|
|
|
public function test_cumulative_figures_are_recomputed_when_history_is_empty(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
|
|
// Terbaik per mata kuliah sampai periode itu: Algoritma 4 (3), Basis Data 3 (2), Jaringan 3,25 (3) = 8 SKS, mutu 27,75.
|
|
$card = $this->card(365);
|
|
|
|
$this->assertSame(['beban' => 8, 'lulus' => 8, 'am' => 27.75, 'ip' => 3.47], $card['kumulatif']);
|
|
$this->assertSame([['semester' => 1, 'sks' => 5, 'lulus' => 5, 'am' => 18.0, 'ips' => 3.6, 'ipk' => 3.6]], $card['catatan']);
|
|
}
|
|
|
|
public function test_cumulative_figures_prefer_the_history_recorded_by_the_legacy_system(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
DB::connection('untan')->table('t_histori_mahasiswa')->insert([
|
|
['idmahasiswa' => 500, 'idperiode' => 365, 'stat_akd_akhir' => 1, 'ips' => 1.95, 'ipk' => 3.4, 'skstranskrip' => 10, 'skstranskriplulus' => 9],
|
|
]);
|
|
|
|
$this->assertSame(['beban' => 10, 'lulus' => 9, 'am' => 27.75, 'ip' => 3.4], $this->card(365)['kumulatif']);
|
|
}
|
|
|
|
public function test_progress_notes_only_list_regular_semesters_before_the_printed_one(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
|
|
$this->assertSame([], $this->card(362)['catatan']);
|
|
|
|
// Periode pendek 366 (tanpa nomor semester) dicetak: semester reguler 1 dan 2 tercatat, dirinya sendiri tidak.
|
|
$card = $this->card(366);
|
|
$this->assertNull($card['semester']);
|
|
$this->assertSame([1, 2], array_column($card['catatan'], 'semester'));
|
|
$this->assertSame('2019/2020 - Genap (Pendek)', $card['tahun_akademik']);
|
|
}
|
|
|
|
public function test_unknown_semester_falls_back_to_the_latest(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
$this->login();
|
|
|
|
$this->assertSame('2019/2020 - Genap (Pendek)', $this->card(999)['tahun_akademik']);
|
|
$this->get(route('mahasiswa.khs.cetak', ['semester' => 999]))->assertOk();
|
|
}
|
|
|
|
public function test_identity_advisor_signer_and_photo_come_from_master_tables(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
$this->seedIdentity();
|
|
|
|
$card = $this->card(362);
|
|
|
|
$this->assertSame('FAKULTAS TEKNIK', $card['fakultas']);
|
|
$this->assertSame('Teknik Informatika', $card['prodi']);
|
|
$this->assertSame(['D1041191001', 'Rina Lestari'], [$card['nim'], $card['nama']]);
|
|
$this->assertSame(['0001017501', 'Siti Aminah, M.Pd.'], [$card['pa_nip'], $card['pa_nama']]);
|
|
$this->assertSame(['nama' => 'Dr. Budi Santoso, S.T., M.T.', 'nip' => '198001012005011001'], $card['pejabat']);
|
|
$this->assertStringStartsWith('data:image/png;base64,', $card['foto']);
|
|
$this->assertSame(24, $card['sks_yad']);
|
|
}
|
|
|
|
public function test_rendered_sheet_has_the_lihs_layout(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
$this->seedIdentity();
|
|
|
|
$html = view('mahasiswa.pdf.khs', ['card' => $this->card(365)])->render();
|
|
|
|
foreach ([
|
|
'KEMENTERIAN PENDIDIKAN DAN KEBUDAYAAN', 'UNIVERSITAS TANJUNGPURA', 'FAKULTAS TEKNIK', 'LEMBAR ISIAN HASIL STUDI (LIHS)',
|
|
'Teknik Informatika', 'Rina Lestari', 'D1041191001', 'Siti Aminah, M.Pd.', '2019/2020 - Genap',
|
|
'Kode MK', 'Nama Mata Kuliah', 'Jaringan Komputer', 'Belum terbit', 'An. Dekan', 'ub. Kasubbag. Akademik',
|
|
'Dr. Budi Santoso, S.T., M.T.', 'NIP. 198001012005011001', 'CATATAN PERKEMBANGAN PRESTASI PER SEMESTER',
|
|
'Lambang Universitas Tanjungpura', 'data:image/png;base64,',
|
|
] as $text) {
|
|
$this->assertStringContainsString($text, $html);
|
|
}
|
|
|
|
$this->assertStringNotContainsString('Nilai Mahasiswa Lain', $html);
|
|
$this->assertStringNotContainsString('Statistika', $html);
|
|
// Tidak ada semester reguler sesudah 365, jadi baris SKS yad dihilangkan; untuk 362 ada (f_maxsks periode 365).
|
|
$this->assertStringNotContainsString('SKS yad', $html);
|
|
$this->assertStringContainsString('SKS yad', view('mahasiswa.pdf.khs', ['card' => $this->card(362)])->render());
|
|
}
|
|
|
|
public function test_sheet_without_photo_or_signer_still_renders(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
DB::connection('untan')->table('t_mahasiswa')->where('idmahasiswa', 500)->update(['pic' => 'bukan gambar']);
|
|
|
|
$card = $this->card(362);
|
|
$this->assertNull($card['foto']);
|
|
$this->assertNull($card['pejabat']);
|
|
|
|
$html = view('mahasiswa.pdf.khs', ['card' => $card])->render();
|
|
$this->assertStringNotContainsString('NIP. ', $html);
|
|
$this->assertStringContainsString('class="foto"', $html);
|
|
}
|
|
|
|
public function test_other_students_grades_are_never_printed(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
|
|
foreach ([null, 362, 365, 366] as $periode) {
|
|
$names = array_column($this->card($periode)['matkul'], 'nama');
|
|
$this->assertNotContains('Nilai Mahasiswa Lain', $names);
|
|
}
|
|
}
|
|
|
|
public function test_student_without_grades_gets_not_found(): void
|
|
{
|
|
$this->login();
|
|
|
|
$this->get(route('mahasiswa.khs.cetak'))->assertNotFound();
|
|
}
|
|
|
|
public function test_guest_is_redirected_to_login(): void
|
|
{
|
|
$this->get(route('mahasiswa.khs.cetak'))->assertRedirect(route('login'));
|
|
}
|
|
}
|