Integrasi Login dan menu Dasar SIAKAD Operator dan Mahasiswa

This commit is contained in:
Ariyutta
2026-11-02 09:08:03 +07:00
parent b7a0c8705b
commit 43269095bf
68 changed files with 4287 additions and 216 deletions
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace Tests\Feature\Mahasiswa;
use App\Enums\Role;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;
/** KHS untuk akun demo (provider users): akses dan halaman dasar. Data asli diuji di LegacyKhsTest. */
class KhsTest extends TestCase
{
use RefreshDatabase;
/** @return array<string, array{Role}> */
public static function otherRoles(): array
{
return [
'superuser' => [Role::Superuser],
'admin' => [Role::Admin],
'operator' => [Role::Operator],
'dosen' => [Role::Dosen],
];
}
public function test_guest_is_redirected_to_login(): void
{
$this->get(route('mahasiswa.khs'))->assertRedirect(route('login'));
}
#[DataProvider('otherRoles')]
public function test_other_roles_are_forbidden(Role $role): void
{
$this->actingAs($this->userWithRole($role))->get(route('mahasiswa.khs'))->assertForbidden();
}
public function test_mahasiswa_sees_the_page(): void
{
$this->actingAs($this->userWithRole(Role::Mahasiswa))
->get(route('mahasiswa.khs'))
->assertOk()
->assertSee('<h1', false)
->assertSee('Kartu Hasil Studi')
->assertSee('Semester 8');
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace Tests\Feature\Mahasiswa;
use App\Enums\Role;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;
/** KRS untuk akun demo (provider users): akses, halaman prototipe, dan aksi KRS asli tertutup. */
class KrsTest extends TestCase
{
use RefreshDatabase;
/** @return array<string, array{Role}> */
public static function otherRoles(): array
{
return [
'superuser' => [Role::Superuser],
'admin' => [Role::Admin],
'operator' => [Role::Operator],
'dosen' => [Role::Dosen],
];
}
public function test_guest_is_redirected_to_login(): void
{
$this->get(route('mahasiswa.krs'))->assertRedirect(route('login'));
$this->post(route('mahasiswa.krs.ambil'), ['jadwal' => 1])->assertRedirect(route('login'));
}
#[DataProvider('otherRoles')]
public function test_other_roles_are_forbidden(Role $role): void
{
$user = $this->userWithRole($role);
$this->actingAs($user)->get(route('mahasiswa.krs'))->assertForbidden();
$this->actingAs($user)->post(route('mahasiswa.krs.ambil'), ['jadwal' => 1])->assertForbidden();
$this->actingAs($user)->delete(route('mahasiswa.krs.hapus', 1))->assertForbidden();
}
public function test_demo_student_sees_the_prototype_and_cannot_use_real_actions(): void
{
$user = $this->userWithRole(Role::Mahasiswa);
$this->actingAs($user)->get(route('mahasiswa.krs'))->assertOk()->assertSee('Kartu Rencana Studi');
$this->actingAs($user)->post(route('mahasiswa.krs.ambil'), ['jadwal' => 1])->assertNotFound();
$this->actingAs($user)->delete(route('mahasiswa.krs.hapus', 1))->assertNotFound();
}
}
@@ -0,0 +1,76 @@
<?php
namespace Tests\Feature\Mahasiswa;
use Tests\Concerns\FakesLegacyDatabase;
use Tests\Concerns\InspectsHtml;
use Tests\TestCase;
/** Dashboard mahasiswa dengan akun DB lama: identitas dan nilai asli, tanpa bagian prototipe. */
class LegacyDashboardTest 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 statValues(): array
{
$nodes = $this->dom($this->get(route('mahasiswa.dashboard')))->query('//*[contains(@class, "stat__value")]');
return array_map(fn ($node): string => trim($node->textContent), iterator_to_array($nodes));
}
public function test_welcome_shows_identity_from_legacy_database(): void
{
$response = $this->get(route('mahasiswa.dashboard'))->assertOk();
$headings = $this->dom($response)->query('//h1');
$this->assertSame(1, $headings->length);
$this->assertSame('Selamat Datang, Rina Lestari!', trim($headings->item(0)->textContent));
$response->assertSee('D1041191001')
->assertSee('Teknik Informatika')
->assertSee('Fakultas Teknik')
->assertSee('2019');
}
public function test_stats_and_latest_grades_come_from_real_grades(): void
{
$this->seedLegacyGrades();
// IPK, SKS lulus, semester terakhir (pendek 2019/2020 Genap), IPS terakhir.
$this->assertSame(['3,07', '8', 'Pendek 2019/2020 Genap', '2,00'], $this->statValues());
$this->get(route('mahasiswa.dashboard'))
->assertSee('Dari 11 SKS ditempuh')
->assertSee('Nilai semester terakhir')
->assertSee('Etika Profesi');
}
public function test_prototype_sections_are_hidden(): void
{
$this->seedLegacyGrades();
$this->get(route('mahasiswa.dashboard'))->assertOk()
->assertDontSee('Status KRS')
->assertDontSee('Kuliah hari ini')
->assertDontSee('Tagihan')
->assertDontSee('Pengumuman terbaru')
->assertDontSee('Nilai Mahasiswa Lain');
}
public function test_student_without_grades_sees_empty_values(): void
{
$this->assertSame(['–', '0', '–', '–'], $this->statValues());
$this->get(route('mahasiswa.dashboard'))->assertSee('Belum ada nilai');
}
}
+103
View File
@@ -0,0 +1,103 @@
<?php
namespace Tests\Feature\Mahasiswa;
use Tests\Concerns\FakesLegacyDatabase;
use Tests\Concerns\InspectsHtml;
use Tests\TestCase;
/** KHS dari nilai asli DB lama (t_kst) untuk mahasiswa yang masuk lewat provider legacy. */
class LegacyKhsTest 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'));
}
public function test_latest_semester_is_shown_by_default(): void
{
$this->seedLegacyGrades();
$this->login();
$response = $this->get(route('mahasiswa.khs'))->assertOk()
->assertSee('Etika Profesi')
->assertSee('2019/2020 Genap (pendek)')
->assertSee('3,07');
$active = $this->dom($response)->query('//a[@aria-current="page" and contains(@href, "semester=366")]');
$this->assertSame(1, $active->length);
$this->assertSame('Pendek 2019/2020 Genap', trim($active->item(0)->textContent));
}
public function test_semester_numbers_and_ips_follow_legacy_rules(): void
{
$this->seedLegacyGrades();
$this->login();
$this->get(route('mahasiswa.khs', ['semester' => 362]))->assertOk()
->assertSee('Semester 1')
->assertSee('Semester 2')
->assertSee('Algoritma')
->assertSee('72,50')
->assertSee('IPS 3,60');
// (3 SKS x 3,25 + 2 SKS belum terbit x 0) / 5 SKS
$this->get(route('mahasiswa.khs', ['semester' => 365]))->assertOk()
->assertSee('Jaringan Komputer')
->assertSee('IPS 1,95')
->assertSee('1 nilai belum terbit')
->assertDontSee('Skripsi')
->assertDontSee('Statistika');
}
public function test_unpublished_grade_is_hidden(): void
{
$this->seedLegacyGrades();
$this->login();
$response = $this->get(route('mahasiswa.khs', ['semester' => 365]));
$row = $this->dom($response)->query('//tr[td[contains(., "Kalkulus")]]')->item(0);
$this->assertNotNull($row);
$this->assertStringContainsString('Belum terbit', $row->textContent);
$this->assertStringNotContainsString('91', $row->textContent);
}
public function test_other_students_grades_are_never_shown(): void
{
$this->seedLegacyGrades();
$this->login();
foreach ([null, 362, 365, 366] as $semester) {
$this->get(route('mahasiswa.khs', array_filter(['semester' => $semester])))->assertDontSee('Nilai Mahasiswa Lain');
}
}
public function test_unknown_semester_falls_back_to_latest(): void
{
$this->seedLegacyGrades();
$this->login();
$this->get(route('mahasiswa.khs', ['semester' => 999]))->assertOk()->assertSee('Etika Profesi');
}
public function test_student_without_grades_sees_empty_state(): void
{
$this->login();
$this->get(route('mahasiswa.khs'))->assertOk()
->assertSee('Belum ada nilai')
->assertDontSee('Cetak');
}
}
+163
View File
@@ -0,0 +1,163 @@
<?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');
}
}
@@ -0,0 +1,91 @@
<?php
namespace Tests\Feature\Mahasiswa;
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');
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace Tests\Feature\Mahasiswa;
use App\Enums\Role;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;
/** Transkrip untuk akun demo (provider users): akses dan halaman dasar. Data asli diuji di LegacyTranskripTest. */
class TranskripTest extends TestCase
{
use RefreshDatabase;
/** @return array<string, array{Role}> */
public static function otherRoles(): array
{
return [
'superuser' => [Role::Superuser],
'admin' => [Role::Admin],
'operator' => [Role::Operator],
'dosen' => [Role::Dosen],
];
}
public function test_guest_is_redirected_to_login(): void
{
$this->get(route('mahasiswa.transkrip'))->assertRedirect(route('login'));
}
#[DataProvider('otherRoles')]
public function test_other_roles_are_forbidden(Role $role): void
{
$this->actingAs($this->userWithRole($role))->get(route('mahasiswa.transkrip'))->assertForbidden();
}
public function test_mahasiswa_sees_the_page(): void
{
$this->actingAs($this->userWithRole(Role::Mahasiswa))
->get(route('mahasiswa.transkrip'))
->assertOk()
->assertSee('Transkrip nilai')
->assertSee('Unduh PDF');
}
}