178 lines
7.6 KiB
PHP
178 lines
7.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Mahasiswa;
|
|
|
|
use App\Support\Legacy\TranscriptSheet;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\Concerns\FakesLegacyDatabase;
|
|
use Tests\Concerns\InspectsHtml;
|
|
use Tests\TestCase;
|
|
|
|
/** Transkrip dari nilai asli DB lama untuk mahasiswa yang masuk lewat provider legacy. */
|
|
class LegacyTranskripTest extends TestCase
|
|
{
|
|
use FakesLegacyDatabase;
|
|
use InspectsHtml;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->useLegacyDatabase();
|
|
$this->post(route('login.store'), ['username' => 'D1041191001', 'password' => 'rahasia-mhs'])
|
|
->assertRedirect(route('mahasiswa.dashboard'));
|
|
}
|
|
|
|
/** @return list<string> */
|
|
private function courseNames(): array
|
|
{
|
|
$response = $this->get(route('mahasiswa.transkrip'))->assertOk();
|
|
$cells = $this->dom($response)->query('//tbody/tr/td[contains(@class, "table__title")]');
|
|
|
|
return array_map(fn ($cell): string => trim($cell->textContent), iterator_to_array($cells));
|
|
}
|
|
|
|
public function test_transcript_lists_counted_courses_once(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
|
|
$this->assertSame(['Algoritma', 'Basis Data', 'Jaringan Komputer', 'Etika Profesi'], $this->courseNames());
|
|
}
|
|
|
|
public function test_retaken_course_keeps_the_best_grade(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
|
|
$row = $this->dom($this->get(route('mahasiswa.transkrip')))->query('//tr[td[contains(@class, "table__title") and normalize-space(.) = "Algoritma"]]')->item(0);
|
|
|
|
$this->assertNotNull($row);
|
|
$this->assertStringContainsString('IF101', $row->textContent);
|
|
$this->assertStringNotContainsString('IF101P', $row->textContent);
|
|
$this->assertStringContainsString('4,00', $row->textContent);
|
|
}
|
|
|
|
public function test_summary_follows_legacy_rules(): void
|
|
{
|
|
$this->seedLegacyGrades();
|
|
|
|
$this->get(route('mahasiswa.transkrip'))->assertOk()
|
|
->assertSee('3,07') // IPK: 33,75 / 11
|
|
->assertSee('33,75') // jumlah mutu
|
|
->assertSee('Cetak')
|
|
->assertDontSee('Unduh PDF')
|
|
->assertDontSee('dari 144 SKS');
|
|
|
|
$figures = $this->dom($this->get(route('mahasiswa.transkrip')))->query('//*[contains(@class, "stat__value")]');
|
|
$this->assertSame(['3,07', '11', '8', '4'], array_map(fn ($node): string => trim($node->textContent), iterator_to_array($figures)));
|
|
}
|
|
|
|
public function test_falls_back_to_stored_transcript_for_old_students(): void
|
|
{
|
|
$db = DB::connection('untan');
|
|
$db->table('t_matakuliah')->insert([
|
|
['idmatakuliah' => 50, 'idmastermk' => null, 'kodemk' => 'MK050', 'namamk' => 'Pengantar Ekonomi', 'sks' => 3, 'semester' => 1, 'nilailulus' => 1, 'tipe' => 0],
|
|
['idmatakuliah' => 51, 'idmastermk' => null, 'kodemk' => 'MK051', 'namamk' => 'Bahasa Indonesia', 'sks' => 2, 'semester' => 1, 'nilailulus' => 1, 'tipe' => 0],
|
|
]);
|
|
$db->table('t_transkrip')->insert([
|
|
['idmahasiswa' => 500, 'idmatakuliah' => 50, 'nilaimutu' => 3, 'nilaihuruf' => 'B'],
|
|
['idmahasiswa' => 500, 'idmatakuliah' => 51, 'nilaimutu' => 4, 'nilaihuruf' => 'A'],
|
|
['idmahasiswa' => 501, 'idmatakuliah' => 50, 'nilaimutu' => 1, 'nilaihuruf' => 'D'],
|
|
]);
|
|
|
|
$this->assertSame(['Pengantar Ekonomi', 'Bahasa Indonesia'], $this->courseNames());
|
|
$this->get(route('mahasiswa.transkrip'))->assertSee('3,40'); // (9 + 8) / 5
|
|
}
|
|
|
|
public function test_student_without_grades_sees_empty_state(): void
|
|
{
|
|
$this->get(route('mahasiswa.transkrip'))->assertOk()
|
|
->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();
|
|
}
|
|
}
|