Integrasi Login dan menu Dasar SIAKAD Operator dan Mahasiswa
This commit is contained in:
@@ -0,0 +1,478 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Concerns;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Tiruan DB SIAKAD lama (koneksi `untan`) di SQLite memori dan login lewat provider `legacy`.
|
||||
* f_encr() didaftarkan sebagai fungsi SQLite: geser +5 per karakter plus penanda chr(5), seperti aslinya.
|
||||
*
|
||||
* Akun: 1 staf fakultas, 2 dosen, 3 superuser dibekukan, 4 pegawai tanpa otoritas, 5 mahasiswa, 6 superuser.
|
||||
* Tabel nilai dibuat kosong; isi dengan seedLegacyGrades() bila perlu.
|
||||
*/
|
||||
trait FakesLegacyDatabase
|
||||
{
|
||||
/** Hasil f_maxsks tiruan. */
|
||||
protected int $legacyMaxSks = 24;
|
||||
|
||||
protected static function legacyEncode(string $value): string
|
||||
{
|
||||
return implode('', array_map(fn (string $char): string => chr(ord($char) + 5), str_split($value))).chr(5);
|
||||
}
|
||||
|
||||
protected function useLegacyDatabase(): void
|
||||
{
|
||||
config([
|
||||
'database.connections.untan' => ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => ''],
|
||||
'auth.guards.web.provider' => 'legacy',
|
||||
]);
|
||||
DB::purge('untan');
|
||||
Auth::forgetGuards();
|
||||
|
||||
$pdo = DB::connection('untan')->getPdo();
|
||||
$functions = [
|
||||
'f_encr' => [fn (?string $value): ?string => $value === null ? null : static::legacyEncode($value), 1],
|
||||
'f_maxsks' => [fn (...$args): int => $this->legacyMaxSks, 4],
|
||||
'f_inputlirs_new' => [fn (...$args): string => $this->fakeInputLirs(...$args), 10],
|
||||
'f_hapuslirs' => [fn (...$args): string => $this->fakeHapusLirs(...$args), 6],
|
||||
];
|
||||
foreach ($functions as $name => [$callback, $arity]) {
|
||||
method_exists($pdo, 'createFunction') ? $pdo->createFunction($name, $callback, $arity) : $pdo->sqliteCreateFunction($name, $callback, $arity);
|
||||
}
|
||||
|
||||
$this->createLegacySchema();
|
||||
$this->seedLegacyData();
|
||||
}
|
||||
|
||||
private function createLegacySchema(): void
|
||||
{
|
||||
$schema = Schema::connection('untan');
|
||||
|
||||
$schema->create('t_account', function (Blueprint $table) {
|
||||
$table->integer('iduser')->primary();
|
||||
$table->string('username', 50)->unique();
|
||||
$table->string('passwd', 50);
|
||||
$table->integer('identitas');
|
||||
$table->smallInteger('jenis');
|
||||
$table->smallInteger('status')->default(0);
|
||||
$table->timestamp('lastlogin')->nullable();
|
||||
// cip dan tanggal NOT NULL seperti DB asli.
|
||||
$table->string('cname', 20)->nullable();
|
||||
$table->string('cip', 20)->default('10.0.0.1/32');
|
||||
$table->string('uname', 15)->nullable();
|
||||
$table->timestamp('tanggal')->useCurrent();
|
||||
});
|
||||
$schema->create('t_pegawai', function (Blueprint $table) {
|
||||
$table->integer('idpegawai')->primary();
|
||||
$table->string('nip');
|
||||
$table->string('nipnasional')->nullable();
|
||||
$table->string('nidn')->nullable();
|
||||
$table->string('nama');
|
||||
$table->string('gelardepan')->nullable();
|
||||
$table->string('gelarbelakang')->nullable();
|
||||
$table->string('email')->nullable();
|
||||
});
|
||||
$schema->create('t_mahasiswa', function (Blueprint $table) {
|
||||
$table->integer('idmahasiswa')->primary();
|
||||
$table->string('nim');
|
||||
$table->string('nama');
|
||||
$table->string('email_mhs')->nullable();
|
||||
$table->integer('idangkatan')->nullable();
|
||||
$table->integer('idprogdi')->nullable();
|
||||
$table->integer('idprogram')->nullable();
|
||||
$table->integer('idkurikulum')->nullable();
|
||||
$table->integer('idpa')->nullable();
|
||||
$table->smallInteger('stataktif')->default(1);
|
||||
});
|
||||
$schema->create('t_angkatanmhs', function (Blueprint $table) {
|
||||
$table->integer('idangkatan')->primary();
|
||||
$table->integer('tahun');
|
||||
$table->smallInteger('semester')->nullable();
|
||||
});
|
||||
$schema->create('t_periodekuliah', function (Blueprint $table) {
|
||||
$table->integer('idperiode')->primary();
|
||||
$table->char('thakad', 9);
|
||||
$table->smallInteger('semester');
|
||||
$table->smallInteger('perkuliahan');
|
||||
});
|
||||
$schema->create('t_mastermk', function (Blueprint $table) {
|
||||
$table->integer('idmastermk')->primary();
|
||||
$table->string('namamk');
|
||||
});
|
||||
$schema->create('t_matakuliah', function (Blueprint $table) {
|
||||
$table->integer('idmatakuliah')->primary();
|
||||
$table->integer('idmastermk')->nullable();
|
||||
$table->string('kodemk');
|
||||
$table->string('namamk');
|
||||
$table->smallInteger('sks');
|
||||
$table->smallInteger('semester')->nullable();
|
||||
$table->double('nilailulus')->nullable();
|
||||
$table->smallInteger('tipe')->nullable();
|
||||
});
|
||||
$schema->create('t_transkrip', function (Blueprint $table) {
|
||||
$table->increments('idtranskrip');
|
||||
$table->integer('idmahasiswa');
|
||||
$table->integer('idmatakuliah');
|
||||
$table->double('nilaimutu')->nullable();
|
||||
$table->string('nilaihuruf')->nullable();
|
||||
});
|
||||
$schema->create('t_jadwal', function (Blueprint $table) {
|
||||
$table->integer('idjadwal')->primary();
|
||||
$table->integer('idmatakuliah');
|
||||
$table->integer('idperiode');
|
||||
$table->string('kelas')->default('A');
|
||||
$table->smallInteger('kapasitas')->default(0);
|
||||
$table->boolean('flag_cetak')->default(false);
|
||||
$table->integer('idprogdi')->nullable();
|
||||
});
|
||||
$schema->create('t_kst', function (Blueprint $table) {
|
||||
$table->increments('idkst');
|
||||
$table->integer('idmahasiswa');
|
||||
$table->integer('idjadwal');
|
||||
$table->integer('idmatakuliah');
|
||||
$table->integer('idperiode');
|
||||
$table->double('nilaitotal')->nullable();
|
||||
$table->double('nilaimutu')->nullable();
|
||||
$table->string('nilaihuruf')->nullable();
|
||||
$table->smallInteger('stat')->nullable()->default(0);
|
||||
$table->string('cname', 20)->nullable();
|
||||
$table->string('uname', 20)->nullable();
|
||||
$table->timestamp('tanggal')->nullable();
|
||||
$table->unique(['idmahasiswa', 'idmatakuliah', 'idperiode']);
|
||||
});
|
||||
// KRS: periode aktif prodi, masa pengisian, registrasi, kurikulum, dan detail jadwal kelas.
|
||||
$schema->create('t_periodekuliahaktif', function (Blueprint $table) {
|
||||
$table->integer('idprogdi');
|
||||
$table->integer('idperiode');
|
||||
});
|
||||
$schema->create('t_periodelirs', function (Blueprint $table) {
|
||||
$table->increments('idperiodelirs');
|
||||
$table->integer('idprogdi');
|
||||
$table->integer('idperiode');
|
||||
$table->integer('idangkatan');
|
||||
$table->date('mulai');
|
||||
$table->date('selesai');
|
||||
});
|
||||
$schema->create('t_histori_mahasiswa', function (Blueprint $table) {
|
||||
$table->increments('idhistori');
|
||||
$table->integer('idmahasiswa');
|
||||
$table->integer('idperiode');
|
||||
$table->smallInteger('stat_akd_akhir')->nullable();
|
||||
$table->double('ips')->nullable();
|
||||
});
|
||||
$schema->create('t_kurikulum', function (Blueprint $table) {
|
||||
$table->integer('idkurikulum')->primary();
|
||||
$table->integer('idprogdi');
|
||||
$table->integer('idprogram');
|
||||
});
|
||||
$schema->create('t_jadwalkurikulum', function (Blueprint $table) {
|
||||
$table->increments('idjadwalkurikulum');
|
||||
$table->integer('idjadwal');
|
||||
$table->integer('idkurikulum');
|
||||
});
|
||||
$schema->create('t_jadwaltemu', function (Blueprint $table) {
|
||||
$table->increments('idjadwaltemu');
|
||||
$table->integer('idjadwal');
|
||||
$table->smallInteger('hari');
|
||||
$table->time('mulai');
|
||||
$table->time('selesai');
|
||||
});
|
||||
$schema->create('t_ruang', function (Blueprint $table) {
|
||||
$table->integer('idruang')->primary();
|
||||
$table->string('namaruang');
|
||||
});
|
||||
$schema->create('t_jadwalruangkuliah', function (Blueprint $table) {
|
||||
$table->increments('idjadwalruang');
|
||||
$table->integer('idjadwaltemu');
|
||||
$table->integer('idruang');
|
||||
});
|
||||
$schema->create('t_jadwaldosen', function (Blueprint $table) {
|
||||
$table->increments('idjadwaldosen');
|
||||
$table->integer('idjadwal');
|
||||
$table->integer('iddosen');
|
||||
$table->smallInteger('dosenke')->default(1);
|
||||
});
|
||||
$schema->create('t_dosen', function (Blueprint $table) {
|
||||
$table->integer('idpegawai')->primary();
|
||||
$table->integer('idjabatanfungsional')->nullable();
|
||||
});
|
||||
$schema->create('t_jabatanfungsional', function (Blueprint $table) {
|
||||
$table->integer('idjabatanfungsional')->primary();
|
||||
$table->string('jabatan');
|
||||
});
|
||||
$schema->create('t_otoritas', function (Blueprint $table) {
|
||||
$table->integer('idotoritas')->primary();
|
||||
$table->string('otoritas');
|
||||
});
|
||||
$schema->create('t_otoritasuser', function (Blueprint $table) {
|
||||
$table->increments('idotoritasuser');
|
||||
$table->integer('iduser');
|
||||
$table->integer('idotoritas');
|
||||
});
|
||||
$schema->create('t_unituser', function (Blueprint $table) {
|
||||
$table->increments('idunituser');
|
||||
$table->integer('iduser');
|
||||
$table->integer('idfak')->nullable();
|
||||
$table->integer('idprogdi')->nullable();
|
||||
});
|
||||
$schema->create('t_bagian', function (Blueprint $table) {
|
||||
$table->integer('idbagian')->primary();
|
||||
$table->integer('idbagian_induk')->default(0);
|
||||
$table->smallInteger('idjenisbagian')->nullable();
|
||||
$table->string('namabagian');
|
||||
});
|
||||
}
|
||||
|
||||
private function seedLegacyData(): void
|
||||
{
|
||||
$db = DB::connection('untan');
|
||||
$pegawai = fn (int $id, string $nip, string $nama, string $depan = '', string $belakang = '', ?string $nidn = null): array => [
|
||||
'idpegawai' => $id, 'nip' => $nip, 'nipnasional' => null, 'nidn' => $nidn, 'nama' => $nama,
|
||||
'gelardepan' => $depan, 'gelarbelakang' => $belakang, 'email' => null,
|
||||
];
|
||||
$account = fn (int $id, string $username, string $password, int $identitas, int $jenis, int $status = 0): array => [
|
||||
'iduser' => $id, 'username' => static::legacyEncode($username), 'passwd' => static::legacyEncode($password),
|
||||
'identitas' => $identitas, 'jenis' => $jenis, 'status' => $status,
|
||||
];
|
||||
|
||||
$db->table('t_pegawai')->insert([
|
||||
$pegawai(10, '198001012005011001', 'Budi Santoso', 'Dr.', ', S.T., M.T.'),
|
||||
$pegawai(11, '197501012000031002', 'Siti Aminah', '', 'M.Pd.', '0001017501'),
|
||||
$pegawai(12, '196001011990011001', 'Akun Beku'),
|
||||
$pegawai(13, '199001012015011001', 'Tanpa Otoritas'),
|
||||
$pegawai(14, '197001011995011001', 'Admin Pusat'),
|
||||
]);
|
||||
$db->table('t_angkatanmhs')->insert(['idangkatan' => 150, 'tahun' => 2019, 'semester' => 1]);
|
||||
$db->table('t_mahasiswa')->insert(['idmahasiswa' => 500, 'nim' => 'D1041191001', 'nama' => 'Rina Lestari', 'email_mhs' => null, 'idangkatan' => 150, 'idprogdi' => 21]);
|
||||
$db->table('t_jabatanfungsional')->insert(['idjabatanfungsional' => 3, 'jabatan' => 'Lektor']);
|
||||
$db->table('t_dosen')->insert(['idpegawai' => 11, 'idjabatanfungsional' => 3]);
|
||||
$db->table('t_otoritas')->insert([['idotoritas' => 7, 'otoritas' => 'Staff Fakultas'], ['idotoritas' => 1, 'otoritas' => 'Administrator Pusat']]);
|
||||
$db->table('t_otoritasuser')->insert([['iduser' => 1, 'idotoritas' => 7], ['iduser' => 3, 'idotoritas' => 1], ['iduser' => 6, 'idotoritas' => 1]]);
|
||||
// t_jenisbagian: 1 fakultas, 2 jurusan, 3 program studi.
|
||||
$db->table('t_bagian')->insert([
|
||||
['idbagian' => 5, 'idbagian_induk' => 0, 'idjenisbagian' => 1, 'namabagian' => 'Fakultas Teknik'],
|
||||
['idbagian' => 20, 'idbagian_induk' => 5, 'idjenisbagian' => 2, 'namabagian' => 'Teknik Elektro'],
|
||||
['idbagian' => 21, 'idbagian_induk' => 20, 'idjenisbagian' => 3, 'namabagian' => 'Teknik Informatika'],
|
||||
]);
|
||||
$db->table('t_unituser')->insert(['iduser' => 1, 'idfak' => 5, 'idprogdi' => null]);
|
||||
|
||||
$db->table('t_account')->insert([
|
||||
$account(1, '198001012005011001', 'rahasia-staf', 10, 0),
|
||||
$account(2, '197501012000031002', 'rahasia-dosen', 11, 0),
|
||||
$account(3, '196001011990011001', 'rahasia-beku', 12, 0, status: 1),
|
||||
$account(4, '199001012015011001', 'rahasia-pegawai', 13, 0),
|
||||
$account(5, 'D1041191001', 'rahasia-mhs', 500, 1),
|
||||
$account(6, '197001011995011001', 'rahasia-super', 14, 0),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nilai mahasiswa 500 (angkatan 2019 ganjil): 2019/2020 Ganjil (362), Genap (365), Genap pendek (366).
|
||||
*
|
||||
* Dihitung: Algoritma A (3), Basis Data B (2), Jaringan Komputer B+ (3), Etika Profesi C (3, batas lulus 2,25).
|
||||
* Algoritma diulang di semester pendek dengan C: transkrip memakai A. Tidak dihitung: Kalkulus (belum terbit),
|
||||
* Skripsi (tipe 2 tanpa nilai), Statistika (batal), dan nilai mahasiswa 501.
|
||||
* KHS: IPS 362 = 3,60; 365 = 1,95 (Kalkulus dihitung 0); 366 = 2,00. Transkrip: 11 SKS, lulus 8, IPK 3,07.
|
||||
*/
|
||||
protected function seedLegacyGrades(): void
|
||||
{
|
||||
$db = DB::connection('untan');
|
||||
|
||||
$db->table('t_periodekuliah')->insert([
|
||||
['idperiode' => 362, 'thakad' => '2019/2020', 'semester' => 1, 'perkuliahan' => 1],
|
||||
['idperiode' => 365, 'thakad' => '2019/2020', 'semester' => 2, 'perkuliahan' => 1],
|
||||
['idperiode' => 366, 'thakad' => '2019/2020', 'semester' => 2, 'perkuliahan' => 2],
|
||||
]);
|
||||
|
||||
$courses = [
|
||||
// id => [kode, nama, sks, tipe, batas lulus, master]
|
||||
1 => ['IF101', 'Algoritma', 3, 0, 1, 1],
|
||||
2 => ['IF102', 'Basis Data', 2, 0, 1, 2],
|
||||
3 => ['IF201', 'Jaringan Komputer', 3, 0, 1, 3],
|
||||
4 => ['IF202', 'Kalkulus', 2, 0, 1, 4],
|
||||
5 => ['IF900', 'Skripsi', 6, 2, 1, 5],
|
||||
6 => ['IF203', 'Statistika', 3, 0, 1, 6],
|
||||
7 => ['IF301', 'Etika Profesi', 3, 0, 2.25, 7],
|
||||
8 => ['IF999', 'Nilai Mahasiswa Lain', 3, 0, 1, 8],
|
||||
9 => ['IF101P', 'Algoritma', 3, 0, 1, 1],
|
||||
];
|
||||
foreach ($courses as $id => [$kode, $nama, $sks, $tipe, $lulus, $master]) {
|
||||
$db->table('t_mastermk')->insertOrIgnore(['idmastermk' => $master, 'namamk' => $nama]);
|
||||
$db->table('t_matakuliah')->insert([
|
||||
'idmatakuliah' => $id, 'idmastermk' => $master, 'kodemk' => $kode, 'namamk' => $nama,
|
||||
'sks' => $sks, 'semester' => $id, 'nilailulus' => $lulus, 'tipe' => $tipe,
|
||||
]);
|
||||
}
|
||||
|
||||
// idjadwal = idmatakuliah
|
||||
foreach ([1 => 362, 2 => 362, 3 => 365, 4 => 365, 5 => 365, 6 => 365, 7 => 366, 8 => 365, 9 => 366] as $id => $periode) {
|
||||
$db->table('t_jadwal')->insert(['idjadwal' => $id, 'idmatakuliah' => $id, 'idperiode' => $periode, 'flag_cetak' => $id !== 4]);
|
||||
}
|
||||
|
||||
$kst = fn (int $mhs, int $mk, int $periode, ?float $total, ?float $mutu, ?string $huruf, int $stat = 3): array => [
|
||||
'idmahasiswa' => $mhs, 'idjadwal' => $mk, 'idmatakuliah' => $mk, 'idperiode' => $periode,
|
||||
'nilaitotal' => $total, 'nilaimutu' => $mutu, 'nilaihuruf' => $huruf, 'stat' => $stat,
|
||||
];
|
||||
$db->table('t_kst')->insert([
|
||||
$kst(500, 1, 362, 85, 4, 'A'),
|
||||
$kst(500, 2, 362, 72.5, 3, 'B'),
|
||||
$kst(500, 3, 365, 78, 3.25, 'B+'),
|
||||
$kst(500, 4, 365, 91, 4, 'A'),
|
||||
$kst(500, 5, 365, null, null, null),
|
||||
$kst(500, 6, 365, 88, 4, 'A', stat: 2),
|
||||
$kst(500, 7, 366, 60, 2, 'C'),
|
||||
$kst(500, 9, 366, 61, 2, 'C'),
|
||||
$kst(501, 8, 365, 95, 4, 'A'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* KRS mahasiswa 500 pada periode aktif prodi 21: 2020/2021 Ganjil (368), kurikulum 900, dosen PA Siti Aminah.
|
||||
*
|
||||
* Sudah diambil: 301 Sistem Basis Data (3 SKS, menunggu) dan 302 Pemrograman Web (3 SKS, disetujui, sudah bernilai).
|
||||
* Tersedia: 303 Kecerdasan Buatan (penuh, kuota 2), 304 Jaringan Lanjut (2 SKS), 305 Kerja Praktik (4 SKS),
|
||||
* 306 Kelas Bentrok (2 SKS, ditolak f_inputlirs_new tiruan). 307 hanya untuk kurikulum prodi lain.
|
||||
*/
|
||||
protected function seedLegacyKrs(bool $open = true, bool $registered = true): void
|
||||
{
|
||||
$db = DB::connection('untan');
|
||||
|
||||
$db->table('t_mahasiswa')->where('idmahasiswa', 500)->update(['idprogram' => 1, 'idkurikulum' => 900, 'idpa' => 11]);
|
||||
$db->table('t_periodekuliah')->insert(['idperiode' => 368, 'thakad' => '2020/2021', 'semester' => 1, 'perkuliahan' => 1]);
|
||||
$db->table('t_periodekuliahaktif')->insert(['idprogdi' => 21, 'idperiode' => 368]);
|
||||
$db->table('t_periodelirs')->insert([
|
||||
'idprogdi' => 21, 'idperiode' => 368, 'idangkatan' => 150,
|
||||
'mulai' => now()->subDays($open ? 3 : 20)->toDateString(),
|
||||
'selesai' => now()->addDays($open ? 3 : -10)->toDateString(),
|
||||
]);
|
||||
$db->table('t_histori_mahasiswa')->insert(['idmahasiswa' => 500, 'idperiode' => 368, 'stat_akd_akhir' => $registered ? 1 : 0]);
|
||||
$db->table('t_kurikulum')->insert([['idkurikulum' => 900, 'idprogdi' => 21, 'idprogram' => 1], ['idkurikulum' => 901, 'idprogdi' => 99, 'idprogram' => 1]]);
|
||||
|
||||
$classes = [
|
||||
// idjadwal => [kode, nama, sks, kapasitas, kurikulum]
|
||||
301 => ['IF311', 'Sistem Basis Data', 3, 40, 900],
|
||||
302 => ['IF312', 'Pemrograman Web', 3, 0, 900],
|
||||
303 => ['IF313', 'Kecerdasan Buatan', 3, 2, 900],
|
||||
304 => ['IF314', 'Jaringan Lanjut', 2, 30, 900],
|
||||
305 => ['IF315', 'Kerja Praktik', 4, 0, 900],
|
||||
306 => ['IF316', 'Kelas Bentrok', 2, 0, 900],
|
||||
307 => ['EK101', 'Kelas Prodi Lain', 3, 0, 901],
|
||||
];
|
||||
foreach ($classes as $id => [$kode, $nama, $sks, $kapasitas, $kurikulum]) {
|
||||
$db->table('t_matakuliah')->insert(['idmatakuliah' => $id, 'kodemk' => $kode, 'namamk' => $nama, 'sks' => $sks, 'tipe' => 0]);
|
||||
$db->table('t_jadwal')->insert(['idjadwal' => $id, 'idmatakuliah' => $id, 'idperiode' => 368, 'kelas' => 'A', 'kapasitas' => $kapasitas]);
|
||||
$db->table('t_jadwalkurikulum')->insert(['idjadwal' => $id, 'idkurikulum' => $kurikulum]);
|
||||
}
|
||||
|
||||
$db->table('t_ruang')->insert([['idruang' => 1, 'namaruang' => 'Lab Komputer 1'], ['idruang' => 2, 'namaruang' => 'B.2.1']]);
|
||||
$db->table('t_jadwaltemu')->insert([
|
||||
['idjadwaltemu' => 1, 'idjadwal' => 301, 'hari' => 1, 'mulai' => '07:30:00', 'selesai' => '09:10:00'],
|
||||
['idjadwaltemu' => 2, 'idjadwal' => 304, 'hari' => 3, 'mulai' => '10:00:00', 'selesai' => '11:40:00'],
|
||||
]);
|
||||
$db->table('t_jadwalruangkuliah')->insert([['idjadwaltemu' => 1, 'idruang' => 1], ['idjadwaltemu' => 2, 'idruang' => 2]]);
|
||||
$db->table('t_jadwaldosen')->insert([['idjadwal' => 301, 'iddosen' => 11, 'dosenke' => 1], ['idjadwal' => 304, 'iddosen' => 10, 'dosenke' => 1]]);
|
||||
|
||||
$kst = fn (int $mhs, int $jadwal, int $stat, ?string $huruf = null): array => [
|
||||
'idmahasiswa' => $mhs, 'idjadwal' => $jadwal, 'idmatakuliah' => $jadwal, 'idperiode' => 368, 'stat' => $stat, 'nilaihuruf' => $huruf,
|
||||
];
|
||||
$db->table('t_kst')->insert([$kst(500, 301, 0), $kst(500, 302, 1, 'B'), $kst(501, 303, 1), $kst(502, 303, 1)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ringkasan dashboard operator (akun 1) untuk prodi 21 Teknik Informatika dan 22 Teknik Sipil.
|
||||
* Periode aktif 2020/2021 Ganjil (368); sebelumnya 2019/2020 Genap (365, 2 aktif). 371 belum berjalan, 366 pendek.
|
||||
*
|
||||
* Periode 368, semua prodi: aktif 3 (500, 502, 510), IPS rerata 3,00 dari 2 mahasiswa, baru 3 (angkatan 2020),
|
||||
* lulus 1 (505), cuti 1 (501), belum berstatus 2 (503 tanpa histori, 511 histori kosong; 504 angkatan 2021 tidak dihitung).
|
||||
* KRS: 3 dari 3 aktif sudah mengisi, 1 menunggu (500); masa pengisian hanya untuk prodi 21 (dibuka).
|
||||
* Kelas: 602 tanpa jadwal dan nilai belum terbit; 603 hanya peserta batal; 604 tugas akhir tanpa jadwal.
|
||||
*/
|
||||
protected function seedLegacyOverview(): void
|
||||
{
|
||||
$db = DB::connection('untan');
|
||||
|
||||
$db->table('t_bagian')->insert(['idbagian' => 22, 'idbagian_induk' => 5, 'idjenisbagian' => 3, 'namabagian' => 'Teknik Sipil']);
|
||||
$db->table('t_unituser')->insert([['iduser' => 1, 'idfak' => 5, 'idprogdi' => 21], ['iduser' => 1, 'idfak' => 5, 'idprogdi' => 22]]);
|
||||
$db->table('t_periodekuliah')->insert([
|
||||
['idperiode' => 365, 'thakad' => '2019/2020', 'semester' => 2, 'perkuliahan' => 1],
|
||||
['idperiode' => 366, 'thakad' => '2019/2020', 'semester' => 2, 'perkuliahan' => 2],
|
||||
['idperiode' => 368, 'thakad' => '2020/2021', 'semester' => 1, 'perkuliahan' => 1],
|
||||
['idperiode' => 371, 'thakad' => '2020/2021', 'semester' => 2, 'perkuliahan' => 1],
|
||||
]);
|
||||
$db->table('t_periodekuliahaktif')->insert([['idprogdi' => 21, 'idperiode' => 368], ['idprogdi' => 22, 'idperiode' => 368]]);
|
||||
$db->table('t_periodelirs')->insert([
|
||||
'idprogdi' => 21, 'idperiode' => 368, 'idangkatan' => 150,
|
||||
'mulai' => now()->subDays(3)->toDateString(), 'selesai' => now()->addDays(3)->toDateString(),
|
||||
]);
|
||||
$db->table('t_angkatanmhs')->insert([['idangkatan' => 160, 'tahun' => 2020, 'semester' => 1], ['idangkatan' => 170, 'tahun' => 2021, 'semester' => 1]]);
|
||||
|
||||
// idmahasiswa => [idprogdi, idangkatan, stataktif]
|
||||
foreach ([501 => [21, 150, 1], 502 => [21, 160, 1], 503 => [21, 150, 1], 504 => [21, 170, 1], 505 => [21, 150, 2], 510 => [22, 160, 1], 511 => [22, 160, 1]] as $id => [$prodi, $angkatan, $stat]) {
|
||||
$db->table('t_mahasiswa')->insert(['idmahasiswa' => $id, 'nim' => 'X'.$id, 'nama' => 'Mahasiswa '.$id, 'idprogdi' => $prodi, 'idangkatan' => $angkatan, 'stataktif' => $stat]);
|
||||
}
|
||||
|
||||
$histori = fn (int $mhs, int $periode, ?int $stat, ?float $ips = null): array => ['idmahasiswa' => $mhs, 'idperiode' => $periode, 'stat_akd_akhir' => $stat, 'ips' => $ips];
|
||||
$db->table('t_histori_mahasiswa')->insert([
|
||||
// IPS 365 belum direkap.
|
||||
$histori(500, 365, 1), $histori(505, 365, 1),
|
||||
$histori(500, 368, 1, 3.5), $histori(501, 368, 2), $histori(502, 368, 1, 0), $histori(505, 368, 3),
|
||||
$histori(510, 368, 1, 2.5), $histori(511, 368, null),
|
||||
]);
|
||||
|
||||
// idjadwal = idmatakuliah => [idprogdi, tipe, terbit, punya jadwal temu]
|
||||
foreach ([601 => [21, 0, true, true], 602 => [22, 0, false, false], 603 => [21, 0, false, false], 604 => [21, 2, true, false]] as $id => [$prodi, $tipe, $terbit, $temu]) {
|
||||
$db->table('t_matakuliah')->insert(['idmatakuliah' => $id, 'kodemk' => 'MK'.$id, 'namamk' => 'Kelas '.$id, 'sks' => 2, 'tipe' => $tipe]);
|
||||
$db->table('t_jadwal')->insert(['idjadwal' => $id, 'idmatakuliah' => $id, 'idperiode' => 368, 'idprogdi' => $prodi, 'flag_cetak' => $terbit]);
|
||||
if ($temu) {
|
||||
$db->table('t_jadwaltemu')->insert(['idjadwal' => $id, 'hari' => 1, 'mulai' => '07:30:00', 'selesai' => '09:10:00']);
|
||||
}
|
||||
}
|
||||
|
||||
$kst = fn (int $mhs, int $jadwal, int $stat): array => ['idmahasiswa' => $mhs, 'idjadwal' => $jadwal, 'idmatakuliah' => $jadwal, 'idperiode' => 368, 'stat' => $stat];
|
||||
$db->table('t_kst')->insert([$kst(500, 601, 0), $kst(502, 601, 1), $kst(502, 604, 1), $kst(510, 602, 1), $kst(501, 603, 2)]);
|
||||
}
|
||||
|
||||
/** Tiruan f_inputlirs_new: jadwal 306 bentrok (pesan bergaya lama dengan "\n" literal); lainnya disisipkan. */
|
||||
private function fakeInputLirs(mixed $idmahasiswa, mixed $idprogdi, mixed $idperiode, mixed $idjadwal, mixed $unused, mixed $kode, mixed $nama, mixed $kelas, mixed $cname, mixed $uname): string
|
||||
{
|
||||
if ((int) $idjadwal === 306) {
|
||||
return ' - 1. Jadwal Matakuliah Bentrok Dengan Sistem Basis Data ( Senin 07:30 - 09:10 ).\n';
|
||||
}
|
||||
|
||||
$db = DB::connection('untan');
|
||||
$db->table('t_kst')->insert([
|
||||
'idmahasiswa' => (int) $idmahasiswa,
|
||||
'idjadwal' => (int) $idjadwal,
|
||||
'idmatakuliah' => (int) $db->table('t_jadwal')->where('idjadwal', $idjadwal)->value('idmatakuliah'),
|
||||
'idperiode' => (int) $idperiode,
|
||||
'cname' => $cname,
|
||||
'uname' => $uname,
|
||||
'tanggal' => now(),
|
||||
]);
|
||||
|
||||
return 'Data berhasil di inputkan';
|
||||
}
|
||||
|
||||
/** Tiruan f_hapuslirs (act 0): hanya milik sendiri dan belum bernilai; '' berarti berhasil. */
|
||||
private function fakeHapusLirs(mixed $idkst, mixed $idmahasiswa, mixed ...$unused): string
|
||||
{
|
||||
$db = DB::connection('untan');
|
||||
$row = $db->table('t_kst')->where('idkst', $idkst)->first();
|
||||
|
||||
if ($row === null || (int) $row->idmahasiswa !== (int) $idmahasiswa) {
|
||||
return 'Tidak Boleh Menghapus LIRS Mahasiswa Lain !';
|
||||
}
|
||||
|
||||
if ($row->nilaihuruf !== null || $row->nilaimutu !== null) {
|
||||
return 'Tidak Boleh Menghapus LIRS ini !';
|
||||
}
|
||||
|
||||
$db->table('t_kst')->where('idkst', $idkst)->delete();
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use App\Models\Legacy\Account;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** Login lewat provider `legacy` terhadap tiruan DB lama (lihat FakesLegacyDatabase). */
|
||||
class LegacyLoginTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->useLegacyDatabase();
|
||||
}
|
||||
|
||||
public function test_staff_logs_in_with_legacy_credentials(): void
|
||||
{
|
||||
$this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf'])
|
||||
->assertRedirect(route('operator.dashboard'));
|
||||
|
||||
$user = Auth::user();
|
||||
$this->assertInstanceOf(Account::class, $user);
|
||||
$this->assertSame('Dr. Budi Santoso, S.T., M.T.', $user->name);
|
||||
$this->assertSame('Staff Fakultas', $user->profile->jabatan);
|
||||
$this->assertSame('Fakultas Teknik', $user->profile->unit_kerja);
|
||||
|
||||
$this->get(route('operator.dashboard'))
|
||||
->assertOk()
|
||||
->assertSee('Selamat Datang, Dr. Budi Santoso, S.T., M.T.!');
|
||||
}
|
||||
|
||||
public function test_session_is_restored_from_legacy_account(): void
|
||||
{
|
||||
$this->post(route('login.store'), ['username' => 'D1041191001', 'password' => 'rahasia-mhs'])
|
||||
->assertRedirect(route('mahasiswa.dashboard'));
|
||||
|
||||
Auth::forgetGuards();
|
||||
|
||||
$this->get(route('mahasiswa.dashboard'))->assertOk()->assertSee('D1041191001');
|
||||
$this->get(route('operator.dashboard'))->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_dosen_without_otoritas_logs_in_as_dosen(): void
|
||||
{
|
||||
$this->post(route('login.store'), ['username' => '197501012000031002', 'password' => 'rahasia-dosen'])
|
||||
->assertRedirect(route('dosen.dashboard'));
|
||||
|
||||
$this->assertSame('0001017501', Auth::user()->profile->nidn);
|
||||
$this->assertSame('Lektor', Auth::user()->profile->jabatan_fungsional);
|
||||
}
|
||||
|
||||
public function test_wrong_password_fails_generically(): void
|
||||
{
|
||||
$this->from(route('login'))
|
||||
->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-dosen'])
|
||||
->assertRedirect(route('login'))
|
||||
->assertSessionHasErrors(['username' => trans('auth.failed')]);
|
||||
|
||||
$this->assertGuest();
|
||||
}
|
||||
|
||||
public function test_frozen_account_fails_generically(): void
|
||||
{
|
||||
$this->from(route('login'))
|
||||
->post(route('login.store'), ['username' => '196001011990011001', 'password' => 'rahasia-beku'])
|
||||
->assertSessionHasErrors(['username' => trans('auth.failed')]);
|
||||
|
||||
$this->assertGuest();
|
||||
}
|
||||
|
||||
public function test_employee_without_role_cannot_log_in(): void
|
||||
{
|
||||
$this->from(route('login'))
|
||||
->post(route('login.store'), ['username' => '199001012015011001', 'password' => 'rahasia-pegawai'])
|
||||
->assertSessionHasErrors(['username' => trans('auth.failed')]);
|
||||
|
||||
$this->assertGuest();
|
||||
}
|
||||
|
||||
public function test_login_does_not_write_to_legacy_database(): void
|
||||
{
|
||||
$before = DB::connection('untan')->table('t_account')->where('iduser', 1)->first();
|
||||
|
||||
$this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf']);
|
||||
|
||||
$this->assertEquals($before, DB::connection('untan')->table('t_account')->where('iduser', 1)->first());
|
||||
}
|
||||
|
||||
public function test_database_error_during_login_does_not_expose_the_password(): void
|
||||
{
|
||||
$account = Auth::createUserProvider('legacy')->retrieveById(1);
|
||||
DB::connection('untan')->statement('drop table t_account');
|
||||
|
||||
try {
|
||||
Auth::createUserProvider('legacy')->validateCredentials($account, ['password' => 'rahasia-staf']);
|
||||
$this->fail('Galat DB seharusnya dilempar.');
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->assertStringNotContainsString('rahasia-staf', $e->getMessage());
|
||||
$this->assertNull($e->getPrevious());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Console;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ResetPasswordCommandTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
|
||||
private const string QUESTION = 'Kata sandi baru (minimal 8 karakter, huruf dan angka)';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->useLegacyDatabase();
|
||||
}
|
||||
|
||||
private function passwd(int $iduser): string
|
||||
{
|
||||
return DB::connection('untan')->table('t_account')->where('iduser', $iduser)->value('passwd');
|
||||
}
|
||||
|
||||
public function test_resets_password_typed_in_terminal(): void
|
||||
{
|
||||
$this->artisan('siakad:reset-password', ['username' => '197001011995011001'])
|
||||
->expectsConfirmation('Atur ulang kata sandi Admin Pusat? Kata sandi lama tidak bisa dikembalikan.', 'yes')
|
||||
->expectsQuestion(self::QUESTION, 'SandiBaru2026')
|
||||
->expectsQuestion('Ulangi kata sandi baru', 'SandiBaru2026')
|
||||
->expectsOutput('Kata sandi Admin Pusat berhasil diatur ulang.')
|
||||
->assertSuccessful();
|
||||
|
||||
$row = DB::connection('untan')->table('t_account')->where('iduser', 6)->first();
|
||||
$this->assertSame(static::legacyEncode('SandiBaru2026'), $row->passwd);
|
||||
$this->assertSame('artisan', $row->uname);
|
||||
$this->assertSame(gethostbyname(gethostname()), $row->cip);
|
||||
|
||||
$this->post(route('login.store'), ['username' => '197001011995011001', 'password' => 'SandiBaru2026'])
|
||||
->assertRedirect(route('superuser.dashboard'));
|
||||
}
|
||||
|
||||
public function test_weak_then_mismatched_then_valid_password(): void
|
||||
{
|
||||
$this->artisan('siakad:reset-password', ['username' => '197001011995011001'])
|
||||
->expectsConfirmation('Atur ulang kata sandi Admin Pusat? Kata sandi lama tidak bisa dikembalikan.', 'yes')
|
||||
->expectsQuestion(self::QUESTION, 'pendek')
|
||||
->expectsQuestion(self::QUESTION, 'SandiBaru2026')
|
||||
->expectsQuestion('Ulangi kata sandi baru', 'SandiLain2026')
|
||||
->expectsQuestion(self::QUESTION, 'SandiBaru2026')
|
||||
->expectsQuestion('Ulangi kata sandi baru', 'SandiBaru2026')
|
||||
->expectsOutput('Konfirmasi kata sandi tidak cocok.')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertSame(static::legacyEncode('SandiBaru2026'), $this->passwd(6));
|
||||
}
|
||||
|
||||
public function test_cancel_changes_nothing(): void
|
||||
{
|
||||
$this->artisan('siakad:reset-password', ['username' => '197001011995011001'])
|
||||
->expectsConfirmation('Atur ulang kata sandi Admin Pusat? Kata sandi lama tidak bisa dikembalikan.', 'no')
|
||||
->assertFailed();
|
||||
|
||||
$this->assertSame(static::legacyEncode('rahasia-super'), $this->passwd(6));
|
||||
}
|
||||
|
||||
public function test_random_password_is_printed_and_works(): void
|
||||
{
|
||||
$this->artisan('siakad:reset-password', ['username' => 'D1041191001', '--acak' => true])
|
||||
->expectsConfirmation('Atur ulang kata sandi Rina Lestari? Kata sandi lama tidak bisa dikembalikan.', 'yes')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertNotSame(static::legacyEncode('rahasia-mhs'), $this->passwd(5));
|
||||
}
|
||||
|
||||
public function test_reset_without_ip_keeps_existing_cip(): void
|
||||
{
|
||||
Auth::createUserProvider('legacy')->retrieveById(6)->resetPassword('SandiBaru2026', 'artisan');
|
||||
|
||||
$this->assertSame('10.0.0.1/32', DB::connection('untan')->table('t_account')->where('iduser', 6)->value('cip'));
|
||||
}
|
||||
|
||||
public function test_database_error_does_not_expose_the_password(): void
|
||||
{
|
||||
$account = Auth::createUserProvider('legacy')->retrieveById(6);
|
||||
DB::connection('untan')->statement('drop table t_account');
|
||||
|
||||
try {
|
||||
$account->resetPassword('SandiBaru2026', 'artisan', '127.0.0.1');
|
||||
$this->fail('Galat DB seharusnya dilempar.');
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->assertStringNotContainsString('SandiBaru2026', $e->getMessage());
|
||||
$this->assertStringNotContainsString(static::legacyEncode('SandiBaru2026'), $e->getMessage());
|
||||
$this->assertNull($e->getPrevious());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_unknown_account_fails(): void
|
||||
{
|
||||
$this->artisan('siakad:reset-password', ['username' => 'tidak-ada'])
|
||||
->expectsOutput('Akun dengan NIP atau NIM ini tidak ditemukan.')
|
||||
->assertFailed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Exceptions\DatabaseUnreachable;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use PDOException;
|
||||
use Tests\Concerns\InspectsHtml;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** Server DB tidak terjangkau (mis. di luar jaringan UNTAN): pesan ramah, bukan galat 500. */
|
||||
class DatabaseUnreachableTest extends TestCase
|
||||
{
|
||||
use InspectsHtml;
|
||||
|
||||
/** Seperti galat PDO asli: SQLSTATE di awal pesan, kode berisi kode driver. */
|
||||
private static function queryFailure(string $sqlState): QueryException
|
||||
{
|
||||
return new QueryException('untan', 'select 1', [], new PDOException("SQLSTATE[{$sqlState}] [7] simulasi", 7));
|
||||
}
|
||||
|
||||
/** Koneksi untan diarahkan ke port tertutup di mesin sendiri: gagal sungguhan dengan SQLSTATE 08006. */
|
||||
private function breakLegacyConnection(): void
|
||||
{
|
||||
config([
|
||||
'database.connections.untan.host' => '127.0.0.1',
|
||||
'database.connections.untan.port' => 1,
|
||||
'auth.guards.web.provider' => 'legacy',
|
||||
]);
|
||||
DB::purge('untan');
|
||||
Auth::forgetGuards();
|
||||
}
|
||||
|
||||
public function test_connection_failure_shows_friendly_page(): void
|
||||
{
|
||||
Route::get('/_uji/db-putus', fn () => throw self::queryFailure('08006'))->middleware('web');
|
||||
|
||||
$response = $this->get('/_uji/db-putus')->assertStatus(503)->assertSee(DatabaseUnreachable::MESSAGE);
|
||||
|
||||
$headings = $this->dom($response)->query('//h1');
|
||||
$this->assertSame(1, $headings->length);
|
||||
$this->assertSame('Tidak dapat terhubung ke server', trim($headings->item(0)->textContent));
|
||||
$response->assertDontSee('select 1');
|
||||
}
|
||||
|
||||
public function test_connection_failure_returns_json_message(): void
|
||||
{
|
||||
Route::get('/_uji/db-putus', fn () => throw self::queryFailure('08001'))->middleware('web');
|
||||
|
||||
$this->getJson('/_uji/db-putus')->assertStatus(503)->assertExactJson(['message' => DatabaseUnreachable::MESSAGE]);
|
||||
}
|
||||
|
||||
public function test_other_database_errors_are_not_disguised(): void
|
||||
{
|
||||
Route::get('/_uji/db-salah', fn () => throw self::queryFailure('42P01'))->middleware('web');
|
||||
|
||||
$this->get('/_uji/db-salah')->assertStatus(500)->assertDontSee(DatabaseUnreachable::MESSAGE);
|
||||
}
|
||||
|
||||
public function test_login_shows_message_under_username_without_counting_a_failed_attempt(): void
|
||||
{
|
||||
$this->breakLegacyConnection();
|
||||
RateLimiter::clear('198001012005011001|127.0.0.1');
|
||||
|
||||
$this->from(route('login'))
|
||||
->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf'])
|
||||
->assertRedirect(route('login'))
|
||||
->assertSessionHasErrors(['username' => DatabaseUnreachable::MESSAGE])
|
||||
->assertSessionHasInput('username', '198001012005011001')
|
||||
->assertSessionMissing('_old_input.password');
|
||||
|
||||
$this->assertGuest();
|
||||
$this->assertSame(0, RateLimiter::attempts('198001012005011001|127.0.0.1'));
|
||||
}
|
||||
|
||||
public function test_real_connection_failure_is_recognised_and_hides_bindings(): void
|
||||
{
|
||||
$this->breakLegacyConnection();
|
||||
|
||||
try {
|
||||
DB::connection('untan')->select('select ?', ['nilai-rahasia']);
|
||||
$this->fail('Koneksi ke port tertutup seharusnya gagal.');
|
||||
} catch (QueryException $e) {
|
||||
$this->assertTrue(DatabaseUnreachable::matches($e), "SQLSTATE {$e->getCode()} bukan galat koneksi.");
|
||||
$this->assertStringNotContainsString('nilai-rahasia', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Operator;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\Concerns\InspectsHtml;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** Dashboard operator dari DB lama; data dari seedLegacyOverview(). */
|
||||
class LegacyDashboardTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
use InspectsHtml;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->useLegacyDatabase();
|
||||
$this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf'])
|
||||
->assertRedirect(route('operator.dashboard'));
|
||||
}
|
||||
|
||||
/** @return list<string> sel baris tabel berjudul $row di dalam tabel berlabel $table */
|
||||
private function row(TestResponse $response, string $table, string $row): array
|
||||
{
|
||||
$cells = $this->dom($response)->query("//*[@aria-label='{$table}']//tr[th[normalize-space()='{$row}']]/td");
|
||||
|
||||
return array_map(fn ($cell): string => $this->textOf($cell), iterator_to_array($cells));
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function optionLabels(TestResponse $response, string $name): array
|
||||
{
|
||||
$nodes = $this->dom($response)->query("//select[@name='{$name}']/option");
|
||||
|
||||
return array_map(fn ($node): string => $this->textOf($node), iterator_to_array($nodes));
|
||||
}
|
||||
|
||||
public function test_dashboard_summarises_the_operators_programs(): void
|
||||
{
|
||||
$this->seedLegacyOverview();
|
||||
|
||||
$response = $this->get(route('operator.dashboard'))->assertOk()
|
||||
->assertSee('Selamat Datang, Dr. Budi Santoso, S.T., M.T.!')
|
||||
->assertSee('Ringkasan berikut diambil dari data akademik 2 program studi yang Anda kelola.')
|
||||
->assertSee('Naik 1 dari 2019/2020 Genap')
|
||||
->assertSee('3,00')
|
||||
->assertSee('Dari 2 mahasiswa yang IPS-nya sudah dihitung')
|
||||
->assertSee('Angkatan 2020')
|
||||
->assertSee('Pada semester ini')
|
||||
->assertSee('1 mahasiswa memiliki KRS yang belum disetujui')
|
||||
->assertSee('2 mahasiswa aktif belum memiliki status semester')
|
||||
->assertSee('1 kelas berpeserta belum memiliki jadwal')
|
||||
->assertSee('1 kelas belum menerbitkan nilai')
|
||||
->assertSee('Pengisian dibuka')
|
||||
->assertSee('3 dari 3')
|
||||
->assertSee('1 mahasiswa masih menunggu persetujuan dosen pembimbing akademik.')
|
||||
->assertDontSee('data contoh')
|
||||
->assertDontSee('Belum ada berita');
|
||||
|
||||
// Hanya semester reguler sampai periode aktif.
|
||||
$this->assertSame(['2020/2021 Ganjil', '2019/2020 Genap'], $this->optionLabels($response, 'periode'));
|
||||
$this->assertSame(['Semua program studi', 'Teknik Informatika', 'Teknik Sipil'], $this->optionLabels($response, 'prodi'));
|
||||
|
||||
// Aktif, cuti, non aktif, lulus, keluar, belum berstatus, total.
|
||||
$this->assertSame(['1', '1', '0', '1', '0', '1', '4'], $this->row($response, 'AKM per angkatan', '2019'));
|
||||
$this->assertSame(['2', '0', '0', '0', '0', '1', '3'], $this->row($response, 'AKM per angkatan', '2020'));
|
||||
$this->assertSame([], $this->row($response, 'AKM per angkatan', '2021'));
|
||||
// Aktif, cuti, non aktif, lulus, belum berstatus, mahasiswa baru.
|
||||
$this->assertSame(['2', '1', '0', '1', '1', '1'], $this->row($response, 'AKM per program studi', 'Teknik Informatika'));
|
||||
$this->assertSame(['1', '0', '0', '0', '1', '2'], $this->row($response, 'AKM per program studi', 'Teknik Sipil'));
|
||||
}
|
||||
|
||||
public function test_program_filter_narrows_the_summary(): void
|
||||
{
|
||||
$this->seedLegacyOverview();
|
||||
|
||||
$response = $this->get(route('operator.dashboard', ['prodi' => 22]))->assertOk()
|
||||
->assertSee('Ringkasan berikut diambil dari data akademik program studi Teknik Sipil.')
|
||||
->assertSee('Naik 1 dari 2019/2020 Genap')
|
||||
->assertSee('1 mahasiswa aktif belum memiliki status semester')
|
||||
->assertSee('Masa pengisian KRS belum diatur untuk 2020/2021 Ganjil.')
|
||||
->assertDontSee('KRS yang belum disetujui')
|
||||
->assertDontSee('Pengisian dibuka');
|
||||
|
||||
$this->assertSame([], $this->row($response, 'AKM per program studi', 'Teknik Informatika'));
|
||||
$this->assertSame('22', $this->attr($this->dom($response)->query("//select[@name='prodi']/option[@selected]"), 'value'));
|
||||
}
|
||||
|
||||
public function test_earlier_period_and_invalid_filters(): void
|
||||
{
|
||||
$this->seedLegacyOverview();
|
||||
|
||||
$this->get(route('operator.dashboard', ['periode' => 365]))->assertOk()
|
||||
->assertSee('Statistik mahasiswa 2019/2020 Genap')
|
||||
->assertSee('Berstatus aktif semester ini')
|
||||
->assertSee('Belum ada kelulusan tercatat')
|
||||
->assertSee('IPS semester ini belum dihitung');
|
||||
|
||||
// Periode di luar daftar (belum berjalan) dan prodi milik akun lain diabaikan.
|
||||
$response = $this->get(route('operator.dashboard', ['periode' => 371, 'prodi' => 99]))->assertOk()
|
||||
->assertSee('Statistik mahasiswa 2020/2021 Ganjil')
|
||||
->assertSee('2 program studi yang Anda kelola');
|
||||
$this->assertSame('368', $this->attr($this->dom($response)->query("//select[@name='periode']/option[@selected]"), 'value'));
|
||||
}
|
||||
|
||||
public function test_account_without_programs_sees_empty_state(): void
|
||||
{
|
||||
$this->seedLegacyOverview();
|
||||
DB::connection('untan')->table('t_unituser')->whereNotNull('idprogdi')->delete();
|
||||
|
||||
$this->get(route('operator.dashboard'))->assertOk()
|
||||
->assertSee('Selamat Datang, Dr. Budi Santoso, S.T., M.T.!')
|
||||
->assertSee('Akun belum terhubung ke program studi')
|
||||
->assertDontSee('Mahasiswa aktif');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Superuser;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** Atur ulang kata sandi akun DB lama: ditulis ke t_account lewat f_encr() beserta kolom audit. */
|
||||
class LegacyResetPasswordTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->useLegacyDatabase();
|
||||
|
||||
$this->post(route('login.store'), ['username' => '197001011995011001', 'password' => 'rahasia-super'])
|
||||
->assertRedirect(route('superuser.dashboard'));
|
||||
}
|
||||
|
||||
public function test_search_finds_legacy_account_by_nip(): void
|
||||
{
|
||||
$this->get(route('superuser.reset-password', ['username' => '198001012005011001']))
|
||||
->assertOk()
|
||||
->assertSee('Dr. Budi Santoso, S.T., M.T.')
|
||||
->assertSee('Fakultas Teknik');
|
||||
}
|
||||
|
||||
public function test_reset_writes_encoded_password_and_audit_columns(): void
|
||||
{
|
||||
$this->put(route('superuser.reset-password.update'), [
|
||||
'username' => '198001012005011001',
|
||||
'password' => 'SandiBaru2026',
|
||||
'password_confirmation' => 'SandiBaru2026',
|
||||
])->assertRedirect(route('superuser.reset-password'));
|
||||
|
||||
$row = DB::connection('untan')->table('t_account')->where('iduser', 1)->first();
|
||||
$this->assertSame(static::legacyEncode('SandiBaru2026'), $row->passwd);
|
||||
$this->assertSame('197001011995011', $row->uname);
|
||||
$this->assertSame('127.0.0.1', $row->cip);
|
||||
$this->assertSame(config('app.name'), $row->cname);
|
||||
$this->assertNotNull($row->tanggal);
|
||||
|
||||
// Akun lain tidak tersentuh.
|
||||
$this->assertSame(static::legacyEncode('rahasia-dosen'), DB::connection('untan')->table('t_account')->where('iduser', 2)->value('passwd'));
|
||||
}
|
||||
|
||||
public function test_owner_logs_in_with_the_new_password(): void
|
||||
{
|
||||
$this->put(route('superuser.reset-password.update'), ['username' => 'D1041191001', 'acak' => '1']);
|
||||
$password = session('generated_password')['password'];
|
||||
|
||||
$this->post(route('logout'));
|
||||
Auth::forgetGuards();
|
||||
|
||||
$this->post(route('login.store'), ['username' => 'D1041191001', 'password' => 'rahasia-mhs'])
|
||||
->assertSessionHasErrors('username');
|
||||
$this->post(route('login.store'), ['username' => 'D1041191001', 'password' => $password])
|
||||
->assertRedirect(route('mahasiswa.dashboard'));
|
||||
}
|
||||
|
||||
public function test_frozen_account_stays_frozen_after_reset(): void
|
||||
{
|
||||
$this->get(route('superuser.reset-password', ['username' => '196001011990011001']))
|
||||
->assertOk()
|
||||
->assertSee('Dibekukan');
|
||||
|
||||
$this->put(route('superuser.reset-password.update'), ['username' => '196001011990011001', 'acak' => '1']);
|
||||
|
||||
$this->assertSame(1, (int) DB::connection('untan')->table('t_account')->where('iduser', 3)->value('status'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Superuser;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\Concerns\InspectsHtml;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ResetPasswordTest extends TestCase
|
||||
{
|
||||
use InspectsHtml;
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @return array<string, array{Role}> */
|
||||
public static function otherRoles(): array
|
||||
{
|
||||
return [
|
||||
'admin' => [Role::Admin],
|
||||
'operator' => [Role::Operator],
|
||||
'dosen' => [Role::Dosen],
|
||||
'mahasiswa' => [Role::Mahasiswa],
|
||||
];
|
||||
}
|
||||
|
||||
private function superuser(): User
|
||||
{
|
||||
return $this->userWithRole(Role::Superuser, ['username' => 'superuser']);
|
||||
}
|
||||
|
||||
private function target(): User
|
||||
{
|
||||
return $this->userWithRole(Role::Mahasiswa, ['name' => 'Rina Lestari', 'username' => 'D1041191001'], ['nim' => 'D1041191001']);
|
||||
}
|
||||
|
||||
public function test_guest_is_redirected_to_login(): void
|
||||
{
|
||||
$this->get(route('superuser.reset-password'))->assertRedirect(route('login'));
|
||||
$this->put(route('superuser.reset-password.update'))->assertRedirect(route('login'));
|
||||
}
|
||||
|
||||
#[DataProvider('otherRoles')]
|
||||
public function test_other_roles_are_forbidden(Role $role): void
|
||||
{
|
||||
$user = $this->userWithRole($role);
|
||||
|
||||
$this->actingAs($user)->get(route('superuser.reset-password'))->assertForbidden();
|
||||
$this->actingAs($user)->put(route('superuser.reset-password.update'), ['username' => $user->username, 'acak' => '1'])->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_superuser_sees_the_page_and_menu_item(): void
|
||||
{
|
||||
$response = $this->actingAs($this->superuser())->get(route('superuser.reset-password'))->assertOk();
|
||||
|
||||
$headings = $this->dom($response)->query('//h1');
|
||||
$this->assertSame(1, $headings->length);
|
||||
$this->assertSame('Atur ulang kata sandi', trim($headings->item(0)->textContent));
|
||||
$this->assertSame(1, $this->dom($response)->query('//a[@aria-current="page" and contains(@href, "reset-kata-sandi")]')->length);
|
||||
}
|
||||
|
||||
public function test_search_shows_the_account(): void
|
||||
{
|
||||
$this->target();
|
||||
|
||||
$this->actingAs($this->superuser())
|
||||
->get(route('superuser.reset-password', ['username' => 'D1041191001']))
|
||||
->assertOk()
|
||||
->assertSee('Rina Lestari')
|
||||
->assertSee('Simpan kata sandi');
|
||||
}
|
||||
|
||||
public function test_search_for_unknown_account_says_so(): void
|
||||
{
|
||||
$this->actingAs($this->superuser())
|
||||
->get(route('superuser.reset-password', ['username' => 'tidak-ada']))
|
||||
->assertOk()
|
||||
->assertSee('Akun tidak ditemukan')
|
||||
->assertDontSee('Simpan kata sandi');
|
||||
}
|
||||
|
||||
public function test_superuser_sets_a_new_password(): void
|
||||
{
|
||||
$target = $this->target();
|
||||
|
||||
$this->actingAs($this->superuser())
|
||||
->put(route('superuser.reset-password.update'), [
|
||||
'username' => 'D1041191001',
|
||||
'password' => 'SandiBaru2026',
|
||||
'password_confirmation' => 'SandiBaru2026',
|
||||
])
|
||||
->assertRedirect(route('superuser.reset-password'))
|
||||
->assertSessionHas('status', 'Kata sandi Rina Lestari berhasil diatur ulang.');
|
||||
|
||||
$this->assertTrue(Hash::check('SandiBaru2026', $target->fresh()->password));
|
||||
}
|
||||
|
||||
public function test_random_password_is_shown_once_and_works(): void
|
||||
{
|
||||
$target = $this->target();
|
||||
$superuser = $this->superuser();
|
||||
|
||||
$this->actingAs($superuser)
|
||||
->put(route('superuser.reset-password.update'), ['username' => 'D1041191001', 'acak' => '1'])
|
||||
->assertRedirect(route('superuser.reset-password'));
|
||||
|
||||
$password = session('generated_password')['password'];
|
||||
$this->assertSame(10, strlen($password));
|
||||
$this->assertTrue(Hash::check($password, $target->fresh()->password));
|
||||
|
||||
$this->actingAs($superuser)->get(route('superuser.reset-password'))->assertSee($password);
|
||||
$this->actingAs($superuser)->get(route('superuser.reset-password'))->assertDontSee($password);
|
||||
}
|
||||
|
||||
public function test_weak_or_mismatched_password_is_rejected(): void
|
||||
{
|
||||
$target = $this->target();
|
||||
$before = $target->password;
|
||||
$superuser = $this->superuser();
|
||||
|
||||
foreach ([
|
||||
['password' => 'pendek1', 'password_confirmation' => 'pendek1'],
|
||||
['password' => 'hanyahuruf', 'password_confirmation' => 'hanyahuruf'],
|
||||
['password' => 'SandiBaru2026', 'password_confirmation' => 'SandiLain2026'],
|
||||
['password' => 'Sandi Baru 2026', 'password_confirmation' => 'Sandi Baru 2026'],
|
||||
] as $input) {
|
||||
$this->actingAs($superuser)
|
||||
->put(route('superuser.reset-password.update'), ['username' => 'D1041191001', ...$input])
|
||||
->assertSessionHasErrors('password');
|
||||
}
|
||||
|
||||
$this->assertSame($before, $target->fresh()->password);
|
||||
}
|
||||
|
||||
public function test_unknown_account_cannot_be_reset(): void
|
||||
{
|
||||
$this->actingAs($this->superuser())
|
||||
->put(route('superuser.reset-password.update'), ['username' => 'tidak-ada', 'acak' => '1'])
|
||||
->assertSessionHasErrors('username')
|
||||
->assertSessionMissing('generated_password');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Support\GradeTone;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class GradeToneTest extends TestCase
|
||||
{
|
||||
/** @return array<string, array{string|null, string}> */
|
||||
public static function grades(): array
|
||||
{
|
||||
return [
|
||||
'A' => ['A', 'success'],
|
||||
'A-' => ['A-', 'success'],
|
||||
'B+' => ['B+', 'info'],
|
||||
'B' => ['B', 'info'],
|
||||
'B-' => ['B-', 'info'],
|
||||
'C+' => ['C+', 'gold'],
|
||||
'C' => ['C', 'gold'],
|
||||
'C-' => ['C-', 'gold'],
|
||||
'D+' => ['D+', 'violet'],
|
||||
'D' => ['D', 'violet'],
|
||||
'E' => ['E', 'danger'],
|
||||
'E+' => ['E+', 'danger'],
|
||||
'huruf kecil berspasi' => [' b+ ', 'info'],
|
||||
'kosong' => [null, 'neutral'],
|
||||
'tak dikenal' => ['T', 'neutral'],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('grades')]
|
||||
public function test_grade_letter_maps_to_badge_tone(?string $grade, string $tone): void
|
||||
{
|
||||
$this->assertSame($tone, GradeTone::for($grade));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Support\Legacy\LegacyRole;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LegacyRoleTest extends TestCase
|
||||
{
|
||||
/** @return array<string, array{int, list<int>, bool, Role|null}> */
|
||||
public static function cases(): array
|
||||
{
|
||||
return [
|
||||
'mahasiswa' => [LegacyRole::JENIS_MAHASISWA, [], false, Role::Mahasiswa],
|
||||
'administrator pusat' => [LegacyRole::JENIS_PEGAWAI, [1], false, Role::Superuser],
|
||||
'superuser mengalahkan dosen' => [LegacyRole::JENIS_PEGAWAI, [1, 2], true, Role::Superuser],
|
||||
'ka puskom' => [LegacyRole::JENIS_PEGAWAI, [22], false, Role::Admin],
|
||||
'sisfo puskom' => [LegacyRole::JENIS_PEGAWAI, [40], true, Role::Admin],
|
||||
'staf fakultas' => [LegacyRole::JENIS_PEGAWAI, [7], false, Role::Operator],
|
||||
'staf nilai merangkap dekan' => [LegacyRole::JENIS_PEGAWAI, [10, 20], true, Role::Operator],
|
||||
'otoritas dosen' => [LegacyRole::JENIS_PEGAWAI, [2], false, Role::Dosen],
|
||||
'tercatat di t_dosen' => [LegacyRole::JENIS_PEGAWAI, [], true, Role::Dosen],
|
||||
'ka progdi yang dosen' => [LegacyRole::JENIS_PEGAWAI, [18], true, Role::Dosen],
|
||||
'pimpinan bukan dosen' => [LegacyRole::JENIS_PEGAWAI, [13], false, Role::Operator],
|
||||
'pegawai tanpa otoritas' => [LegacyRole::JENIS_PEGAWAI, [], false, null],
|
||||
'jenis tak dikenal' => [9, [1], false, null],
|
||||
];
|
||||
}
|
||||
|
||||
/** @param list<int> $otoritas */
|
||||
#[DataProvider('cases')]
|
||||
public function test_legacy_account_maps_to_role(int $jenis, array $otoritas, bool $isDosen, ?Role $expected): void
|
||||
{
|
||||
$this->assertSame($expected, LegacyRole::resolve($jenis, $otoritas, $isDosen));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user