164 lines
6.3 KiB
PHP
164 lines
6.3 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature\Mahasiswa;
|
||
|
||
use Illuminate\Support\Facades\DB;
|
||
use Tests\Concerns\FakesLegacyDatabase;
|
||
use Tests\Concerns\InspectsHtml;
|
||
use Tests\TestCase;
|
||
|
||
/** KRS asli (t_kst) untuk mahasiswa yang masuk lewat provider legacy; data dari seedLegacyKrs(). */
|
||
class LegacyKrsTest 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'));
|
||
}
|
||
|
||
private function kst(int $idmahasiswa = 500)
|
||
{
|
||
return DB::connection('untan')->table('t_kst')->where('idmahasiswa', $idmahasiswa)->where('idperiode', 368);
|
||
}
|
||
|
||
private function idkst(int $idjadwal): int
|
||
{
|
||
return (int) $this->kst()->where('idjadwal', $idjadwal)->value('idkst');
|
||
}
|
||
|
||
/** @return list<string> */
|
||
private function availableTitles(): array
|
||
{
|
||
$nodes = $this->dom($this->get(route('mahasiswa.krs')))->query('//section[@aria-labelledby="judul-tersedia"]//*[contains(@class, "list__title")]');
|
||
|
||
return array_map(fn ($node): string => trim($node->textContent), iterator_to_array($nodes));
|
||
}
|
||
|
||
public function test_closed_period_shows_the_plan_read_only(): void
|
||
{
|
||
$this->seedLegacyKrs(open: false);
|
||
|
||
$response = $this->get(route('mahasiswa.krs'))->assertOk()
|
||
->assertSee('Rencana studi semester 2020/2021 Ganjil bersama dosen pembimbing akademik Siti Aminah, M.Pd.')
|
||
->assertSee('Masa pengisian KRS ditutup')
|
||
->assertSee('Sistem Basis Data')
|
||
->assertSee('Senin, 07.30–09.10, Lab Komputer 1')
|
||
->assertSee('Menunggu persetujuan')
|
||
->assertSee('Disetujui')
|
||
->assertDontSee('Kelas tersedia');
|
||
|
||
$this->assertSame(0, $this->dom($response)->query('//form[contains(@action, "/krs/")]')->length, 'Tanpa tombol ambil atau hapus.');
|
||
}
|
||
|
||
public function test_open_period_lists_classes_offered_to_the_students_curriculum(): void
|
||
{
|
||
$this->seedLegacyKrs();
|
||
|
||
$this->assertSame([
|
||
'Jaringan Lanjut (kelas A)',
|
||
'Kecerdasan Buatan (kelas A)',
|
||
'Kelas Bentrok (kelas A)',
|
||
'Kerja Praktik (kelas A)',
|
||
], $this->availableTitles());
|
||
|
||
$this->get(route('mahasiswa.krs'))
|
||
->assertSee('Pengisian KRS dibuka sampai')
|
||
->assertSee('Penuh')
|
||
->assertSee('Dr. Budi Santoso, S.T., M.T.')
|
||
->assertDontSee('Kelas Prodi Lain');
|
||
}
|
||
|
||
public function test_student_enrolls_through_the_legacy_function(): void
|
||
{
|
||
$this->seedLegacyKrs();
|
||
|
||
$this->post(route('mahasiswa.krs.ambil'), ['jadwal' => 304])
|
||
->assertRedirect(route('mahasiswa.krs'))
|
||
->assertSessionHas('status', 'Jaringan Lanjut (A) ditambahkan ke KRS dan menunggu persetujuan dosen PA.');
|
||
|
||
$row = $this->kst()->where('idjadwal', 304)->first();
|
||
$this->assertNotNull($row);
|
||
$this->assertSame(0, (int) $row->stat);
|
||
$this->assertSame('SIAKAD Untan', $row->cname);
|
||
$this->assertSame('D1041191001', $row->uname);
|
||
}
|
||
|
||
public function test_enrolment_rules_are_enforced(): void
|
||
{
|
||
$this->seedLegacyKrs();
|
||
$this->legacyMaxSks = 8;
|
||
|
||
$cases = [
|
||
303 => 'Kelas Kecerdasan Buatan (A) sudah penuh.',
|
||
305 => 'Menambah Kerja Praktik (A) membuat total 10 SKS, melebihi batas 8 SKS.',
|
||
307 => 'Kelas ini tidak ditawarkan untuk Anda pada semester ini.',
|
||
301 => 'Sistem Basis Data sudah ada di KRS Anda.',
|
||
306 => 'Jadwal Matakuliah Bentrok Dengan Sistem Basis Data ( Senin 07:30 - 09:10 ).',
|
||
999 => 'Kelas ini tidak ditawarkan untuk Anda pada semester ini.',
|
||
];
|
||
|
||
foreach ($cases as $jadwal => $message) {
|
||
$this->post(route('mahasiswa.krs.ambil'), ['jadwal' => $jadwal])
|
||
->assertRedirect(route('mahasiswa.krs'))
|
||
->assertSessionHasErrors(['krs' => $message]);
|
||
}
|
||
|
||
$this->assertSame(2, $this->kst()->count(), 'Tidak ada baris baru.');
|
||
}
|
||
|
||
public function test_unregistered_student_cannot_enroll(): void
|
||
{
|
||
$this->seedLegacyKrs(registered: false);
|
||
|
||
$this->get(route('mahasiswa.krs'))->assertSee('Belum dapat mengisi KRS')->assertDontSee('Kelas tersedia');
|
||
|
||
$this->post(route('mahasiswa.krs.ambil'), ['jadwal' => 304])
|
||
->assertSessionHasErrors(['krs' => 'Anda belum terdaftar aktif (registrasi) pada semester ini, sehingga belum dapat mengisi KRS.']);
|
||
$this->assertSame(2, $this->kst()->count());
|
||
}
|
||
|
||
public function test_closed_period_rejects_changes(): void
|
||
{
|
||
$this->seedLegacyKrs(open: false);
|
||
|
||
$this->post(route('mahasiswa.krs.ambil'), ['jadwal' => 304])->assertSessionHasErrors(['krs' => 'Masa pengisian KRS sedang ditutup.']);
|
||
$this->delete(route('mahasiswa.krs.hapus', $this->idkst(301)))->assertSessionHasErrors(['krs' => 'Masa pengisian KRS sudah ditutup, sehingga KRS tidak dapat diubah.']);
|
||
$this->assertSame(2, $this->kst()->count());
|
||
}
|
||
|
||
public function test_student_drops_an_ungraded_class(): void
|
||
{
|
||
$this->seedLegacyKrs();
|
||
|
||
$this->delete(route('mahasiswa.krs.hapus', $this->idkst(301)))
|
||
->assertRedirect(route('mahasiswa.krs'))
|
||
->assertSessionHas('status', 'Sistem Basis Data (A) dihapus dari KRS.');
|
||
|
||
$this->assertSame(0, $this->kst()->where('idjadwal', 301)->count());
|
||
}
|
||
|
||
public function test_graded_or_foreign_classes_cannot_be_dropped(): void
|
||
{
|
||
$this->seedLegacyKrs();
|
||
|
||
$this->delete(route('mahasiswa.krs.hapus', $this->idkst(302)))->assertSessionHasErrors(['krs' => 'Tidak Boleh Menghapus LIRS ini !']);
|
||
|
||
$foreign = (int) $this->kst(501)->value('idkst');
|
||
$this->delete(route('mahasiswa.krs.hapus', $foreign))->assertSessionHasErrors(['krs' => 'Mata kuliah ini tidak ada di KRS Anda semester ini.']);
|
||
|
||
$this->assertSame(2, $this->kst()->count());
|
||
$this->assertSame(1, $this->kst(501)->count());
|
||
}
|
||
|
||
public function test_student_without_active_period_sees_empty_state(): void
|
||
{
|
||
$this->get(route('mahasiswa.krs'))->assertOk()->assertSee('Belum ada periode perkuliahan aktif');
|
||
}
|
||
}
|