[Mahasiswa] Penambahan Cetak KRS, KHS, dan Transkrip
This commit is contained in:
@@ -105,6 +105,7 @@ trait FakesLegacyDatabase
|
||||
$table->string('nim');
|
||||
$table->string('nama');
|
||||
$table->string('email_mhs')->nullable();
|
||||
$table->binary('pic')->nullable();
|
||||
$table->integer('idangkatan')->nullable();
|
||||
$table->integer('idprogdi')->nullable();
|
||||
$table->integer('idprogram')->nullable();
|
||||
@@ -431,6 +432,10 @@ trait FakesLegacyDatabase
|
||||
$table->integer('idperiode');
|
||||
$table->smallInteger('stat_akd_akhir')->nullable();
|
||||
$table->double('ips')->nullable();
|
||||
// IPK dan SKS kumulatif transkrip yang dicatat sistem lama (dipakai LIHS).
|
||||
$table->double('ipk')->nullable();
|
||||
$table->smallInteger('skstranskrip')->nullable();
|
||||
$table->smallInteger('skstranskriplulus')->nullable();
|
||||
});
|
||||
$schema->create('t_kurikulum', function (Blueprint $table) {
|
||||
$table->integer('idkurikulum')->primary();
|
||||
|
||||
@@ -34,6 +34,28 @@ class KhsTest extends TestCase
|
||||
$this->actingAs($this->userWithRole($role))->get(route('mahasiswa.khs'))->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_guest_is_redirected_to_login_for_the_pdf(): void
|
||||
{
|
||||
$this->get(route('mahasiswa.khs.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.khs.cetak'))->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_mahasiswa_gets_the_pdf_of_the_sample_semester(): void
|
||||
{
|
||||
$response = $this->actingAs($this->userWithRole(Role::Mahasiswa, profile: ['nim' => 'D1041211999']))
|
||||
->get(route('mahasiswa.khs.cetak', ['semester' => 7]))
|
||||
->assertOk();
|
||||
|
||||
$this->assertSame('application/pdf', $response->headers->get('Content-Type'));
|
||||
$this->assertStringContainsString('LIHS_SEMESTER 7.pdf', $response->headers->get('Content-Disposition'));
|
||||
$this->assertStringStartsWith('%PDF', $response->getContent());
|
||||
}
|
||||
|
||||
public function test_mahasiswa_sees_the_page(): void
|
||||
{
|
||||
$this->actingAs($this->userWithRole(Role::Mahasiswa))
|
||||
|
||||
@@ -39,6 +39,28 @@ class KrsTest extends TestCase
|
||||
$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);
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
<?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'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Mahasiswa;
|
||||
|
||||
use App\Support\Legacy\StudyPlanSheet;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\Concerns\InspectsHtml;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** Cetak LIRS (KRS PDF) dari KRS asli DB lama, termasuk semester sebelumnya; data dari seedLegacyKrs() dan seedLegacyGrades(). */
|
||||
class LegacyKrsCetakTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
use InspectsHtml;
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
/** 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<string, mixed> */
|
||||
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'));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature\Mahasiswa;
|
||||
|
||||
use App\Support\Legacy\TranscriptSheet;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\Concerns\InspectsHtml;
|
||||
@@ -88,4 +89,89 @@ class LegacyTranskripTest extends TestCase
|
||||
->assertSee('Transkrip masih kosong')
|
||||
->assertDontSee('Cetak');
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function sheet(): array
|
||||
{
|
||||
return app(TranscriptSheet::class)->forStudent(500);
|
||||
}
|
||||
|
||||
public function test_pdf_is_streamed_inline_named_after_the_nim(): void
|
||||
{
|
||||
$this->seedLegacyGrades();
|
||||
|
||||
$response = $this->get(route('mahasiswa.transkrip.cetak'))->assertOk();
|
||||
|
||||
$this->assertSame('application/pdf', $response->headers->get('Content-Type'));
|
||||
$this->assertStringContainsString('inline', $response->headers->get('Content-Disposition'));
|
||||
$this->assertStringContainsString('Transkrip - D1041191001.pdf', $response->headers->get('Content-Disposition'));
|
||||
$this->assertStringStartsWith('%PDF', $response->getContent());
|
||||
}
|
||||
|
||||
public function test_page_links_the_print_button_to_the_pdf(): void
|
||||
{
|
||||
$this->seedLegacyGrades();
|
||||
|
||||
$this->get(route('mahasiswa.transkrip'))->assertOk()
|
||||
->assertSee('href="'.route('mahasiswa.transkrip.cetak').'"', false);
|
||||
}
|
||||
|
||||
public function test_sheet_has_the_same_courses_and_figures_as_the_page(): void
|
||||
{
|
||||
$this->seedLegacyGrades();
|
||||
$db = DB::connection('untan');
|
||||
$db->table('t_mahasiswa')->where('idmahasiswa', 500)->update(['tmplahir' => 'PONTIANAK', 'tgllahir' => '1998-05-13']);
|
||||
|
||||
$sheet = $this->sheet();
|
||||
|
||||
$this->assertSame($this->courseNames(), array_column($sheet['matkul'], 'nama'));
|
||||
$this->assertSame([1, 2, 3, 4], array_column($sheet['matkul'], 'no'));
|
||||
$this->assertSame([3.07, 11], [$sheet['ipk'], $sheet['sks']]);
|
||||
$this->assertSame(['D1041191001', 'Rina Lestari', 'Teknik Informatika', 2019], [$sheet['nim'], $sheet['nama'], $sheet['prodi'], $sheet['angkatan']]);
|
||||
$this->assertSame('PONTIANAK, 13/05/1998', $sheet['lahir']);
|
||||
$this->assertNotContains('Nilai Mahasiswa Lain', array_column($sheet['matkul'], 'nama'));
|
||||
}
|
||||
|
||||
public function test_rendered_sheet_has_the_transcript_layout(): void
|
||||
{
|
||||
$this->seedLegacyGrades();
|
||||
|
||||
$html = view('mahasiswa.pdf.transkrip', ['card' => $this->sheet()])->render();
|
||||
|
||||
foreach ([
|
||||
'KEMENTERIAN PENDIDIKAN DAN KEBUDAYAAN', 'UNIVERSITAS TANJUNGPURA', 'FAKULTAS TEKNIK', 'Alamat : Jalan Prof. Dr. H. Hadari Nawawi',
|
||||
'REKAPITULASI NILAI', 'Nama Lengkap</td><td>: Rina Lestari', ': D1041191001', ': Teknik Informatika', ': 2019', ': 3.07 / 11 SKS',
|
||||
'KODE MATA', 'Jaringan Komputer', '3 SKS', 'An. Dekan', 'Wakil Dekan I', 'u.b Kasubbag Akademik',
|
||||
'Lambang Universitas Tanjungpura',
|
||||
] as $text) {
|
||||
$this->assertStringContainsString($text, $html);
|
||||
}
|
||||
|
||||
$this->assertStringNotContainsString('NIP. ', $html, 'Tanpa Kasubbag Akademik terdaftar, baris NIP dihilangkan.');
|
||||
}
|
||||
|
||||
public function test_long_transcripts_continue_in_the_right_column_then_on_a_new_page(): void
|
||||
{
|
||||
$this->seedLegacyGrades();
|
||||
$card = $this->sheet();
|
||||
|
||||
$render = fn (int $rows): string => view('mahasiswa.pdf.transkrip', ['card' => [...$card, 'matkul' => array_map(
|
||||
fn (int $i): array => ['no' => $i, 'kode' => "MK{$i}", 'nama' => "Mata Kuliah {$i}", 'sks' => 2, 'huruf' => 'A'],
|
||||
range(1, $rows),
|
||||
)]])->render();
|
||||
|
||||
// Satu halaman: dua tabel berdampingan (kiri 30 baris), tanda tangan sekali. Lebih dari 60 baris: halaman kedua.
|
||||
$this->assertSame(2, substr_count($render(30), 'KODE MATA'));
|
||||
$this->assertSame(2, substr_count($render(55), 'KODE MATA'));
|
||||
$this->assertSame(0, substr_count($render(55), 'page-break-before'));
|
||||
$long = $render(65);
|
||||
$this->assertSame(4, substr_count($long, 'KODE MATA'));
|
||||
$this->assertSame(1, substr_count($long, 'page-break-before'));
|
||||
$this->assertSame(1, substr_count($long, 'Pontianak, '));
|
||||
}
|
||||
|
||||
public function test_student_without_grades_gets_not_found_for_the_pdf(): void
|
||||
{
|
||||
$this->get(route('mahasiswa.transkrip.cetak'))->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,29 @@ class TranskripTest extends TestCase
|
||||
->get(route('mahasiswa.transkrip'))
|
||||
->assertOk()
|
||||
->assertSee('Transkrip nilai')
|
||||
->assertSee('Unduh PDF');
|
||||
->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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user