Penambahan Akses Laman Dosen dab perbaikan fix
This commit is contained in:
@@ -39,6 +39,9 @@ trait FakesLegacyDatabase
|
||||
'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],
|
||||
'f_nilai_sp' => [fn (...$args): string => $this->fakeNilaiSp(...$args), 10],
|
||||
'f_bobotnilai' => [fn (...$args): int => $this->fakeBobotNilai(...$args), 15],
|
||||
'f_jadwal_flag_cetak_sp' => [fn (...$args): int => $this->fakeFlagCetak(...$args), 4],
|
||||
];
|
||||
foreach ($functions as $name => [$callback, $arity]) {
|
||||
method_exists($pdo, 'createFunction') ? $pdo->createFunction($name, $callback, $arity) : $pdo->sqliteCreateFunction($name, $callback, $arity);
|
||||
@@ -223,6 +226,23 @@ trait FakesLegacyDatabase
|
||||
$table->integer('idprogdi')->nullable();
|
||||
$table->smallInteger('paketke')->default(0);
|
||||
$table->smallInteger('jmlpertemuan')->nullable();
|
||||
$table->smallInteger('bobotkehadiran')->default(10);
|
||||
$table->smallInteger('bobottugas')->default(20);
|
||||
$table->smallInteger('bobotuts')->default(30);
|
||||
$table->smallInteger('bobotuas')->default(40);
|
||||
foreach (['pka', 'pkb', 'pkc', 'pkd', 'pke'] as $kolom) {
|
||||
$table->smallInteger($kolom)->nullable();
|
||||
}
|
||||
$table->smallInteger('sistempenilaian')->default(0);
|
||||
$table->boolean('filter_kehadiran')->default(false);
|
||||
});
|
||||
$schema->create('t_rangenilai', function (Blueprint $table) {
|
||||
$table->integer('idnilai')->primary();
|
||||
$table->smallInteger('nopola');
|
||||
$table->double('nawal');
|
||||
$table->double('nakhir');
|
||||
$table->string('nhuruf');
|
||||
$table->double('nmutu');
|
||||
});
|
||||
// Keuangan mahasiswa (jenis 1 tagihan, 2 pembayaran) dan aturan/alasan cuti.
|
||||
$schema->create('t_komponenpembayaran', function (Blueprint $table) {
|
||||
@@ -321,6 +341,9 @@ trait FakesLegacyDatabase
|
||||
$table->double('nilaimutu')->nullable();
|
||||
$table->string('nilaihuruf')->nullable();
|
||||
$table->double('absen')->nullable();
|
||||
$table->double('tugas')->nullable();
|
||||
$table->double('uts')->nullable();
|
||||
$table->double('uas')->nullable();
|
||||
$table->smallInteger('stat')->nullable()->default(0);
|
||||
$table->string('cname', 20)->nullable();
|
||||
$table->string('uname', 20)->nullable();
|
||||
@@ -1114,6 +1137,35 @@ trait FakesLegacyDatabase
|
||||
}
|
||||
|
||||
/** Tiruan f_hapuslirs (act 0): hanya milik sendiri dan belum bernilai; '' berarti berhasil. */
|
||||
/** Meniru f_nilai_sp: menulis komponen dan nilai akhir ke t_kst. */
|
||||
private function fakeNilaiSp(mixed $idkst, mixed $absen, mixed $tugas, mixed $uts, mixed $uas, mixed $total, mixed $mutu, mixed $huruf, mixed $cname, mixed $uname): string
|
||||
{
|
||||
DB::connection('untan')->table('t_kst')->where('idkst', $idkst)->update([
|
||||
'absen' => $absen, 'tugas' => $tugas, 'uts' => $uts, 'uas' => $uas,
|
||||
'nilaitotal' => $total, 'nilaimutu' => $mutu, 'nilaihuruf' => $huruf, 'cname' => $cname, 'uname' => $uname,
|
||||
]);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/** Meniru f_bobotnilai (15 argumen): bobot dan jumlah pertemuan kelas. */
|
||||
private function fakeBobotNilai(mixed $idjadwal, mixed $kehadiran, mixed $tugas, mixed $uts, mixed $uas, mixed $pertemuan, mixed ...$unused): int
|
||||
{
|
||||
DB::connection('untan')->table('t_jadwal')->where('idjadwal', $idjadwal)->update([
|
||||
'bobotkehadiran' => $kehadiran, 'bobottugas' => $tugas, 'bobotuts' => $uts, 'bobotuas' => $uas, 'jmlpertemuan' => $pertemuan,
|
||||
]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Meniru f_jadwal_flag_cetak_sp (versi terbit): tandai kelas dikunci. */
|
||||
private function fakeFlagCetak(mixed $idjadwal, mixed ...$unused): int
|
||||
{
|
||||
DB::connection('untan')->table('t_jadwal')->where('idjadwal', $idjadwal)->update(['flag_cetak' => true]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function fakeHapusLirs(mixed $idkst, mixed $idmahasiswa, mixed ...$unused): string
|
||||
{
|
||||
$db = DB::connection('untan');
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** Pemilih peran untuk akun DB lama yang memiliki lebih dari satu role. */
|
||||
class LegacyRoleSwitchTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->useLegacyDatabase();
|
||||
}
|
||||
|
||||
/** Akun 2 (Siti Aminah) tercatat dosen dan juga memegang otoritas Staff Fakultas: dua role, bawaan Operator. */
|
||||
private function loginAsOperatorAndLecturer(): void
|
||||
{
|
||||
DB::connection('untan')->table('t_otoritasuser')->insert(['iduser' => 2, 'idotoritas' => 7]);
|
||||
$this->post(route('login.store'), ['username' => '197501012000031002', 'password' => 'rahasia-dosen'])
|
||||
->assertRedirect(route('operator.dashboard'));
|
||||
}
|
||||
|
||||
/** Uji memakai satu instance aplikasi; di produksi tiap permintaan memuat ulang pengguna, jadi guard dilupakan agar sama. */
|
||||
private function switchTo(string $role): TestResponse
|
||||
{
|
||||
$response = $this->post(route('peran.ganti'), ['role' => $role]);
|
||||
Auth::forgetGuards();
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function test_default_role_is_the_highest_priority_and_menu_lists_both(): void
|
||||
{
|
||||
$this->loginAsOperatorAndLecturer();
|
||||
|
||||
$html = $this->get(route('operator.dashboard'))->assertOk()->getContent();
|
||||
|
||||
$this->assertStringContainsString(route('peran.ganti'), $html);
|
||||
$this->assertStringContainsString('name="role" value="dosen"', $html);
|
||||
$this->assertStringNotContainsString('name="role" value="operator"', $html, 'Peran aktif tidak ditawarkan lagi.');
|
||||
$this->assertStringNotContainsString('belum aktif pada tampilan prototipe', $html);
|
||||
}
|
||||
|
||||
public function test_switching_changes_the_active_role_and_its_access(): void
|
||||
{
|
||||
$this->loginAsOperatorAndLecturer();
|
||||
|
||||
$this->switchTo('dosen')
|
||||
->assertRedirect(route('dosen.dashboard'))
|
||||
->assertSessionHas('status', 'Beralih ke peran Dosen.');
|
||||
|
||||
$this->get(route('dosen.dashboard'))->assertOk()->assertSee('Selamat Datang, Siti Aminah, M.Pd.!');
|
||||
$this->get(route('operator.dashboard'))->assertForbidden();
|
||||
$this->get(route('dashboard'))->assertRedirect(route('dosen.dashboard'));
|
||||
|
||||
// Menu kini menawarkan Operator, bukan Dosen.
|
||||
$html = $this->get(route('dosen.jadwal'))->assertOk()->getContent();
|
||||
$this->assertStringContainsString('name="role" value="operator"', $html);
|
||||
$this->assertStringNotContainsString('name="role" value="dosen"', $html);
|
||||
|
||||
$this->switchTo('operator')->assertRedirect(route('operator.dashboard'));
|
||||
$this->get(route('operator.dashboard'))->assertOk();
|
||||
$this->get(route('dosen.dashboard'))->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_roles_the_account_does_not_own_are_refused(): void
|
||||
{
|
||||
$this->loginAsOperatorAndLecturer();
|
||||
|
||||
foreach (['superuser', 'admin', 'mahasiswa'] as $role) {
|
||||
$this->post(route('peran.ganti'), ['role' => $role])->assertForbidden();
|
||||
}
|
||||
$this->post(route('peran.ganti'), ['role' => 'bukan-peran'])->assertSessionHasErrors('role');
|
||||
$this->post(route('peran.ganti'), [])->assertSessionHasErrors('role');
|
||||
|
||||
$this->get(route('operator.dashboard'))->assertOk();
|
||||
}
|
||||
|
||||
public function test_single_role_account_cannot_switch_and_sees_no_other_roles(): void
|
||||
{
|
||||
$this->post(route('login.store'), ['username' => '197501012000031002', 'password' => 'rahasia-dosen'])
|
||||
->assertRedirect(route('dosen.dashboard'));
|
||||
|
||||
$html = $this->get(route('dosen.dashboard'))->assertOk()->getContent();
|
||||
$this->assertStringNotContainsString('name="role"', $html);
|
||||
|
||||
$this->post(route('peran.ganti'), ['role' => 'operator'])->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_selection_ends_with_the_session(): void
|
||||
{
|
||||
$this->loginAsOperatorAndLecturer();
|
||||
$this->switchTo('dosen');
|
||||
$this->post(route('logout'));
|
||||
|
||||
$this->post(route('login.store'), ['username' => '197501012000031002', 'password' => 'rahasia-dosen'])
|
||||
->assertRedirect(route('operator.dashboard'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** Akun demo (provider users) tidak punya hak akses ganda sungguhan: pemilih peran tetap prototipe. */
|
||||
class RoleSwitchDemoTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_demo_accounts_cannot_use_the_real_switch(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->dosen()->create())
|
||||
->post(route('peran.ganti'), ['role' => 'mahasiswa'])
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_demo_menu_still_shows_the_prototype_notice(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->dosen()->create())
|
||||
->get(route('dosen.dashboard'))
|
||||
->assertOk()
|
||||
->assertSee('belum aktif pada tampilan prototipe');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Dosen;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** Bimbingan akademik, persetujuan KRS, skripsi, riwayat mengajar, dan dashboard asli untuk dosen 11 (Siti Aminah). */
|
||||
class LegacyBimbinganTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->useLegacyDatabase();
|
||||
$this->post(route('login.store'), ['username' => '197501012000031002', 'password' => 'rahasia-dosen'])
|
||||
->assertRedirect(route('dosen.dashboard'));
|
||||
}
|
||||
|
||||
private function db()
|
||||
{
|
||||
return DB::connection('untan');
|
||||
}
|
||||
|
||||
/**
|
||||
* Dosen 11 membimbing 500 (Rina, aktif) dan 501 (Budi, lulus), bukan 502 (PA lain). KRS 2020/2021 Ganjil:
|
||||
* 500 punya 301 menunggu dan 302 disetujui; 501 hanya 302 disetujui. Skripsi: 500 (pembimbing 1, berjalan),
|
||||
* 501 (pembimbing 2, lulus 2021-06-01), 502 (dibimbing orang lain), 503 (riwayat lama tanpa tanggal lulus, mahasiswa tidak aktif).
|
||||
*/
|
||||
private function seedAdvising(): void
|
||||
{
|
||||
$this->seedLegacyKrs();
|
||||
|
||||
$this->db()->table('t_mahasiswa')->insert([
|
||||
['idmahasiswa' => 501, 'nim' => 'D1041191002', 'nama' => 'Budi Hartono', 'idangkatan' => 150, 'idprogdi' => 21, 'idpa' => 11, 'stataktif' => 2, 'idkurikulum' => 900, 'idprogram' => 1],
|
||||
['idmahasiswa' => 502, 'nim' => 'D1041191003', 'nama' => 'Cici Paramita', 'idangkatan' => 150, 'idprogdi' => 21, 'idpa' => 10, 'stataktif' => 1, 'idkurikulum' => 900, 'idprogram' => 1],
|
||||
['idmahasiswa' => 503, 'nim' => 'D1041191004', 'nama' => 'Doni Lama', 'idangkatan' => 150, 'idprogdi' => 21, 'idpa' => 10, 'stataktif' => 4, 'idkurikulum' => 900, 'idprogram' => 1],
|
||||
]);
|
||||
$this->db()->table('t_kst')->insert(['idmahasiswa' => 501, 'idjadwal' => 302, 'idmatakuliah' => 302, 'idperiode' => 368, 'stat' => 3]);
|
||||
|
||||
$this->db()->table('t_skripsi')->insert([
|
||||
['idmahasiswa' => 500, 'judul' => 'Sistem Pakar Diagnosis Penyakit Padi', 'pembimbing1' => 11, 'pembimbing2' => 24, 'tglmulai' => '2020-09-01', 'tgllulus' => null],
|
||||
['idmahasiswa' => 501, 'judul' => 'Aplikasi Peramalan Curah Hujan', 'pembimbing1' => 10, 'pembimbing2' => 11, 'tglmulai' => '2117-01-20', 'tgllulus' => '2021-06-01'],
|
||||
['idmahasiswa' => 502, 'judul' => 'Skripsi Dosen Lain', 'pembimbing1' => 10, 'pembimbing2' => 24, 'tglmulai' => '2020-09-01', 'tgllulus' => null],
|
||||
['idmahasiswa' => 503, 'judul' => 'Riwayat Lama', 'pembimbing1' => 11, 'pembimbing2' => null, 'tglmulai' => null, 'tgllulus' => null],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_advisee_list_contains_only_own_students(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
|
||||
$this->get(route('dosen.bimbingan.index'))->assertOk()
|
||||
->assertSee('Rina Lestari')
|
||||
->assertSee('Budi Hartono')
|
||||
->assertSee('Lulus')
|
||||
->assertDontSee('Cici Paramita')
|
||||
->assertDontSee('Doni Lama');
|
||||
|
||||
$this->get(route('dosen.bimbingan.index', ['status' => 'Lulus']))->assertSee('Budi Hartono')->assertDontSee('Rina Lestari');
|
||||
}
|
||||
|
||||
public function test_lists_use_the_satu_table_format_with_server_pagination(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
foreach (range(1, 12) as $i) {
|
||||
$this->db()->table('t_mahasiswa')->insert(['idmahasiswa' => 600 + $i, 'nim' => sprintf('D10411910%02d', 20 + $i), 'nama' => "Mahasiswa Tambahan {$i}", 'idangkatan' => 150, 'idprogdi' => 21, 'idpa' => 11, 'stataktif' => 1]);
|
||||
}
|
||||
|
||||
// 2 mahasiswa awal + 12 tambahan = 14 data: 10 per halaman = 2 halaman.
|
||||
$this->get(route('dosen.bimbingan.index'))->assertOk()
|
||||
->assertSee('satu-bar', false)
|
||||
->assertSee('Cari mahasiswa bimbingan')
|
||||
->assertSee('Halaman 1 dari 2 (14 data)')
|
||||
->assertSee('10 data')
|
||||
->assertSee('satu-pager', false);
|
||||
|
||||
$this->get(route('dosen.bimbingan.index', ['page' => 2]))->assertSee('Halaman 2 dari 2 (14 data)');
|
||||
$this->get(route('dosen.bimbingan.index', ['per' => 25]))->assertSee('Halaman 1 dari 1 (14 data)');
|
||||
$this->get(route('dosen.bimbingan.index', ['q' => 'Tambahan 7']))->assertSee('Halaman 1 dari 1 (1 data)')->assertSee('Mahasiswa Tambahan 7')->assertDontSee('Mahasiswa Tambahan 8');
|
||||
|
||||
$this->get(route('dosen.persetujuan-krs.index'))->assertOk()->assertSee('satu-foot', false)->assertSee('Halaman 1 dari 1');
|
||||
$this->get(route('dosen.kelas.index'))->assertOk()->assertSee('satu-foot', false)->assertSee('Cari kelas saya');
|
||||
}
|
||||
|
||||
public function test_client_side_tables_have_the_satu_search_and_footer(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
|
||||
foreach ([route('dosen.jadwal'), route('dosen.kelas.show', 301), route('dosen.riwayat-mengajar'), route('dosen.skripsi.index')] as $url) {
|
||||
$this->get($url)->assertOk()
|
||||
->assertSee('satu-bar', false)
|
||||
->assertSee('satuDom', false)
|
||||
->assertSee('Jumlah data per halaman');
|
||||
}
|
||||
}
|
||||
|
||||
public function test_advisee_detail_shows_krs_summary_and_blocks_other_advisors_students(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
|
||||
$this->get(route('dosen.bimbingan.show', 'D1041191001'))->assertOk()
|
||||
->assertSee('Rina Lestari')
|
||||
->assertSee('Teknik Informatika')
|
||||
->assertSee('KRS semester 2020/2021 Ganjil')
|
||||
->assertSee('Menunggu persetujuan')
|
||||
->assertSee('Buka KRS');
|
||||
|
||||
$this->get(route('dosen.bimbingan.show', 'D1041191003'))->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_krs_list_marks_pending_and_approved(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
|
||||
$this->get(route('dosen.persetujuan-krs.index'))->assertOk()
|
||||
->assertSee('Rina Lestari')->assertSee('Menunggu persetujuan')
|
||||
->assertSee('Budi Hartono')->assertSee('Disetujui')
|
||||
->assertDontSee('Cici Paramita');
|
||||
}
|
||||
|
||||
public function test_krs_detail_lists_courses_with_schedule(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
|
||||
$this->get(route('dosen.persetujuan-krs.show', 500))->assertOk()
|
||||
->assertSee('KRS Rina Lestari')
|
||||
->assertSee('Sistem Basis Data (A)')
|
||||
->assertSee('Senin, 07.30–09.10, Lab Komputer 1')
|
||||
->assertSee('Pemrograman Web (A)')
|
||||
->assertSee('Tanpa jadwal tatap muka')
|
||||
->assertSee('Maksimal 24 SKS')
|
||||
->assertSee('Setujui KRS')
|
||||
->assertSee('Kembalikan KRS');
|
||||
|
||||
$this->get(route('dosen.persetujuan-krs.show', 502))->assertNotFound();
|
||||
$this->get(route('dosen.persetujuan-krs.show', 501))->assertOk()->assertDontSee('Setujui KRS');
|
||||
}
|
||||
|
||||
public function test_approving_moves_pending_courses_to_approved(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
|
||||
$this->post(route('dosen.persetujuan-krs.setujui', 500))
|
||||
->assertRedirect(route('dosen.persetujuan-krs.index'))
|
||||
->assertSessionHas('status', 'KRS Rina Lestari disetujui.');
|
||||
|
||||
$this->assertSame(0, $this->db()->table('t_kst')->where('idmahasiswa', 500)->where('stat', 0)->count());
|
||||
$this->assertSame(1, (int) $this->db()->table('t_kst')->where('idmahasiswa', 500)->where('idjadwal', 301)->value('stat'));
|
||||
|
||||
$this->post(route('dosen.persetujuan-krs.setujui', 500))->assertSessionHas('warning', 'KRS ini sudah diproses sebelumnya.');
|
||||
}
|
||||
|
||||
public function test_returning_removes_only_the_pending_courses(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
|
||||
$this->post(route('dosen.persetujuan-krs.tolak', 500))
|
||||
->assertRedirect(route('dosen.persetujuan-krs.index'))
|
||||
->assertSessionHas('info');
|
||||
|
||||
$this->assertSame(0, $this->db()->table('t_kst')->where('idmahasiswa', 500)->where('idjadwal', 301)->count());
|
||||
$this->assertSame(1, $this->db()->table('t_kst')->where('idmahasiswa', 500)->where('idjadwal', 302)->count(), 'Mata kuliah yang sudah disetujui tidak ikut dihapus.');
|
||||
}
|
||||
|
||||
public function test_other_advisors_students_cannot_be_approved_or_returned(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
$this->db()->table('t_kst')->insert(['idmahasiswa' => 502, 'idjadwal' => 301, 'idmatakuliah' => 301, 'idperiode' => 368, 'stat' => 0]);
|
||||
|
||||
$this->post(route('dosen.persetujuan-krs.setujui', 502))->assertNotFound();
|
||||
$this->post(route('dosen.persetujuan-krs.tolak', 502))->assertNotFound();
|
||||
|
||||
$this->assertSame(0, (int) $this->db()->table('t_kst')->where('idmahasiswa', 502)->value('stat'));
|
||||
}
|
||||
|
||||
public function test_thesis_list_splits_ongoing_and_finished_and_drops_stale_rows(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
|
||||
$this->get(route('dosen.skripsi.index'))->assertOk()
|
||||
->assertSee('Sistem Pakar Diagnosis Penyakit Padi')
|
||||
->assertSee('Pembimbing 1')
|
||||
->assertSee('Aplikasi Peramalan Curah Hujan')
|
||||
->assertSee('Pembimbing 2')
|
||||
->assertDontSee('Skripsi Dosen Lain')
|
||||
->assertDontSee('Riwayat Lama')
|
||||
->assertDontSee('2117')
|
||||
->assertDontSee('Catat bimbingan');
|
||||
|
||||
$this->get(route('dosen.skripsi.create'))->assertNotFound();
|
||||
$this->post(route('dosen.skripsi.store'), [])->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_teaching_history_summarises_each_period(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
$this->db()->table('t_kst')->where('idmahasiswa', 500)->where('idjadwal', 301)->update(['stat' => 1, 'absen' => 8, 'nilaihuruf' => 'B', 'nilaimutu' => 3]);
|
||||
$this->db()->table('t_jadwal')->where('idjadwal', 301)->update(['jmlpertemuan' => 16]);
|
||||
|
||||
$this->get(route('dosen.riwayat-mengajar'))->assertOk()
|
||||
->assertSee('2020/2021 Ganjil')
|
||||
->assertSee('Sistem Basis Data')
|
||||
->assertSee('50%')
|
||||
->assertSee('3,00');
|
||||
}
|
||||
|
||||
public function test_dashboard_summarises_real_classes_and_advisees(): void
|
||||
{
|
||||
$this->travelTo('2026-11-09 09:00:00');
|
||||
$this->seedAdvising();
|
||||
$this->db()->table('t_kst')->where('idmahasiswa', 500)->where('idjadwal', 301)->update(['stat' => 1]);
|
||||
|
||||
$response = $this->get(route('dosen.dashboard'))->assertOk()
|
||||
->assertSee('Selamat Datang, Siti Aminah, M.Pd.!')
|
||||
->assertSee('2020/2021 Ganjil')
|
||||
->assertSee('Jadwal hari ini')
|
||||
->assertSee('Sistem Basis Data (A)')
|
||||
->assertSee('07.30–09.10, Lab Komputer 1');
|
||||
|
||||
$this->assertStringNotContainsString('Kecerdasan Buatan', $response->getContent());
|
||||
}
|
||||
|
||||
public function test_dashboard_for_a_lecturer_without_classes_has_no_charts(): void
|
||||
{
|
||||
$this->seedAdvising();
|
||||
$this->db()->table('t_jadwaldosen')->where('iddosen', 11)->delete();
|
||||
|
||||
$this->get(route('dosen.dashboard'))->assertOk()->assertSee('Tidak ada kelas hari ini')->assertDontSee('Kehadiran per kelas');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Dosen;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** Jadwal, kelas, presensi, dan penilaian asli untuk dosen yang masuk lewat provider legacy (dosen 11, Siti Aminah). */
|
||||
class LegacyPengajaranTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->useLegacyDatabase();
|
||||
$this->post(route('login.store'), ['username' => '197501012000031002', 'password' => 'rahasia-dosen'])
|
||||
->assertRedirect(route('dosen.dashboard'));
|
||||
}
|
||||
|
||||
private function db()
|
||||
{
|
||||
return DB::connection('untan');
|
||||
}
|
||||
|
||||
private function kst(int $idmahasiswa, int $idjadwal = 301)
|
||||
{
|
||||
return $this->db()->table('t_kst')->where('idmahasiswa', $idmahasiswa)->where('idjadwal', $idjadwal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dosen 11 mengampu kelas 301 (Sistem Basis Data, Senin 07.30–09.10 di Lab Komputer 1, 16 pertemuan, bobot 10/20/30/40);
|
||||
* dosen 10 mengampu 304. Peserta 301 yang disetujui: 500 (Rina) dan 501 (Budi). Skala pola 7. Masa penilaian prodi 21 dibuka.
|
||||
*/
|
||||
private function seedTeaching(bool $gradingOpen = true): void
|
||||
{
|
||||
$this->seedLegacyKrs();
|
||||
|
||||
$this->db()->table('t_jadwal')->where('idjadwal', 301)->update(['idprogdi' => 21, 'jmlpertemuan' => 16]);
|
||||
$this->db()->table('t_mahasiswa')->insert(['idmahasiswa' => 501, 'nim' => 'D1041191002', 'nama' => 'Budi Hartono', 'idangkatan' => 150, 'idprogdi' => 21, 'idpa' => 11]);
|
||||
$this->kst(500)->update(['stat' => 1]);
|
||||
$this->db()->table('t_kst')->insert(['idmahasiswa' => 501, 'idjadwal' => 301, 'idmatakuliah' => 301, 'idperiode' => 368, 'stat' => 3]);
|
||||
|
||||
$scale = [[80, 100, 'A', 4], [75, 79.99, 'B+', 3.5], [70, 74.99, 'B', 3], [65, 69.99, 'C+', 2.5], [60, 64.99, 'C', 2], [55, 59.99, 'D+', 1.5], [50, 54.99, 'D', 1], [0, 49.99, 'E', 0]];
|
||||
foreach ($scale as $i => [$dari, $sampai, $huruf, $mutu]) {
|
||||
$this->db()->table('t_rangenilai')->insert(['idnilai' => $i + 1, 'nopola' => 7, 'nawal' => $dari, 'nakhir' => $sampai, 'nhuruf' => $huruf, 'nmutu' => $mutu]);
|
||||
}
|
||||
|
||||
$this->db()->table('t_periodenilai')->insert([
|
||||
'idperiode' => 368, 'idprogdi' => 21,
|
||||
'mulai' => now()->subDays($gradingOpen ? 5 : 20)->toDateString(),
|
||||
'akhir' => now()->addDays($gradingOpen ? 5 : -10)->toDateString(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function idkst(int $idmahasiswa): int
|
||||
{
|
||||
return (int) $this->kst($idmahasiswa)->value('idkst');
|
||||
}
|
||||
|
||||
public function test_schedule_and_class_list_show_only_own_classes(): void
|
||||
{
|
||||
$this->seedTeaching();
|
||||
|
||||
$this->get(route('dosen.jadwal'))->assertOk()
|
||||
->assertSee('Jadwal kuliah Anda pada semester 2020/2021 Ganjil.')
|
||||
->assertSee('Sistem Basis Data (A)')
|
||||
->assertSee('07.30–09.10')
|
||||
->assertSee('Lab Komputer 1')
|
||||
->assertSee('2 mahasiswa')
|
||||
->assertDontSee('Jaringan Lanjut');
|
||||
|
||||
$this->get(route('dosen.kelas.index'))->assertOk()
|
||||
->assertSee('Sistem Basis Data (A)')
|
||||
->assertSee('Senin, 07.30–09.10')
|
||||
->assertDontSee('Jaringan Lanjut');
|
||||
}
|
||||
|
||||
public function test_class_detail_lists_approved_students_and_rejects_other_lecturers_classes(): void
|
||||
{
|
||||
$this->seedTeaching();
|
||||
$this->kst(500)->update(['absen' => 16, 'tugas' => 80, 'uts' => 90, 'uas' => 70]);
|
||||
|
||||
$this->get(route('dosen.kelas.show', 301))->assertOk()
|
||||
->assertSee('D1041191001')
|
||||
->assertSee('Rina Lestari')
|
||||
->assertSee('Budi Hartono')
|
||||
->assertSee('16 / 16')
|
||||
->assertDontSee('Peserta contoh');
|
||||
|
||||
$this->get(route('dosen.kelas.show', 304))->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_empty_states_when_the_lecturer_has_no_classes(): void
|
||||
{
|
||||
$this->seedTeaching();
|
||||
$this->db()->table('t_jadwaldosen')->where('iddosen', 11)->delete();
|
||||
|
||||
$this->get(route('dosen.jadwal'))->assertOk()->assertSee('Belum ada kelas yang diampu');
|
||||
$this->get(route('dosen.presensi'))->assertOk()->assertSee('Belum ada kelas yang diampu');
|
||||
$this->get(route('dosen.penilaian'))->assertOk()->assertSee('Belum ada kelas yang diampu');
|
||||
}
|
||||
|
||||
public function test_attendance_is_saved_as_meetings_attended(): void
|
||||
{
|
||||
$this->seedTeaching();
|
||||
|
||||
$this->get(route('dosen.presensi'))->assertOk()->assertSee('Rina Lestari')->assertSee('Belum diisi');
|
||||
|
||||
$this->post(route('dosen.presensi.store'), ['kelas' => 301, 'hadir' => [$this->idkst(500) => 16, $this->idkst(501) => 8]])
|
||||
->assertRedirect(route('dosen.presensi', ['kelas' => 301]))
|
||||
->assertSessionHas('status', 'Presensi 2 mahasiswa tersimpan.');
|
||||
|
||||
$this->assertSame([16, 8], [(int) $this->kst(500)->value('absen'), (int) $this->kst(501)->value('absen')]);
|
||||
$this->get(route('dosen.presensi'))->assertOk()->assertSee('Rina Lestari');
|
||||
}
|
||||
|
||||
public function test_invalid_attendance_is_rejected_without_writing(): void
|
||||
{
|
||||
$this->seedTeaching();
|
||||
$own = $this->idkst(500);
|
||||
$foreign = (int) $this->db()->table('t_kst')->where('idjadwal', 303)->value('idkst');
|
||||
|
||||
$this->post(route('dosen.presensi.store'), ['kelas' => 301, 'hadir' => [$own => 17]])
|
||||
->assertSessionHasErrors(['presensi' => 'Jumlah hadir Rina Lestari harus 0 sampai 16.']);
|
||||
|
||||
$this->post(route('dosen.presensi.store'), ['kelas' => 301, 'hadir' => [$foreign => 5]])
|
||||
->assertSessionHasErrors(['presensi' => 'Ada peserta yang bukan anggota kelas ini.']);
|
||||
|
||||
$this->post(route('dosen.presensi.store'), ['kelas' => 304, 'hadir' => [$own => 5]])->assertNotFound();
|
||||
$this->post(route('dosen.presensi.store'), ['kelas' => 301, 'hadir' => [$own => -1]])->assertSessionHasErrors('hadir.'.$own);
|
||||
|
||||
$this->assertNull($this->kst(500)->value('absen'));
|
||||
$this->assertNull($this->db()->table('t_kst')->where('idjadwal', 303)->value('absen'));
|
||||
}
|
||||
|
||||
public function test_grades_are_calculated_from_attendance_and_class_weights(): void
|
||||
{
|
||||
$this->seedTeaching();
|
||||
$this->post(route('dosen.presensi.store'), ['kelas' => 301, 'hadir' => [$this->idkst(500) => 16, $this->idkst(501) => 8]]);
|
||||
|
||||
$this->post(route('dosen.penilaian.store'), ['kelas' => 301, 'nilai' => [
|
||||
$this->idkst(500) => ['tugas' => 80, 'uts' => 90, 'uas' => 70],
|
||||
$this->idkst(501) => ['tugas' => 60, 'uts' => 50, 'uas' => 40],
|
||||
]])->assertRedirect(route('dosen.penilaian', ['kelas' => 301]))
|
||||
->assertSessionHas('status', 'Nilai 2 mahasiswa tersimpan.');
|
||||
|
||||
// 500: (100x10 + 80x20 + 90x30 + 70x40) / 100 = 81 (A). 501: (50x10 + 60x20 + 50x30 + 40x40) / 100 = 48 (E).
|
||||
$a = $this->kst(500)->first();
|
||||
$this->assertSame([81.0, 4.0, 'A'], [(float) $a->nilaitotal, (float) $a->nilaimutu, $a->nilaihuruf]);
|
||||
$e = $this->kst(501)->first();
|
||||
$this->assertSame([48.0, 0.0, 'E'], [(float) $e->nilaitotal, (float) $e->nilaimutu, $e->nilaihuruf]);
|
||||
$this->assertSame('SIAKAD Untan', $a->cname);
|
||||
$this->assertSame('197501012000031', $a->uname);
|
||||
|
||||
$this->get(route('dosen.penilaian'))->assertOk()->assertSee('81,00')->assertSee('Simpan nilai');
|
||||
}
|
||||
|
||||
public function test_assessment_settings_update_the_class_and_recalculate_complete_grades(): void
|
||||
{
|
||||
$this->seedTeaching();
|
||||
$this->post(route('dosen.presensi.store'), ['kelas' => 301, 'hadir' => [$this->idkst(500) => 16]]);
|
||||
$this->post(route('dosen.penilaian.store'), ['kelas' => 301, 'nilai' => [$this->idkst(500) => ['tugas' => 80, 'uts' => 90, 'uas' => 70]]]);
|
||||
$this->assertSame('A', $this->kst(500)->value('nilaihuruf'));
|
||||
|
||||
$this->get(route('dosen.penilaian'))->assertOk()->assertSee('Pengaturan penilaian')->assertSee('Jumlah pertemuan');
|
||||
|
||||
$this->post(route('dosen.penilaian.pengaturan', 301), ['pertemuan' => 14, 'bobot' => ['kehadiran' => 0, 'tugas' => 30, 'uts' => 30, 'uas' => 40]])
|
||||
->assertRedirect(route('dosen.penilaian', ['kelas' => 301]))
|
||||
->assertSessionHas('status');
|
||||
|
||||
$class = $this->db()->table('t_jadwal')->where('idjadwal', 301)->first();
|
||||
$this->assertSame([14, 0, 30, 30, 40], [(int) $class->jmlpertemuan, (int) $class->bobotkehadiran, (int) $class->bobottugas, (int) $class->bobotuts, (int) $class->bobotuas]);
|
||||
|
||||
// (80x30 + 90x30 + 70x40) / 100 = 79 -> B+ pada skala pola 7.
|
||||
$row = $this->kst(500)->first();
|
||||
$this->assertSame([79.0, 3.5, 'B+'], [(float) $row->nilaitotal, (float) $row->nilaimutu, $row->nilaihuruf]);
|
||||
}
|
||||
|
||||
public function test_assessment_settings_are_validated_and_owned(): void
|
||||
{
|
||||
$this->seedTeaching();
|
||||
$valid = ['pertemuan' => 16, 'bobot' => ['kehadiran' => 10, 'tugas' => 20, 'uts' => 30, 'uas' => 40]];
|
||||
|
||||
$this->post(route('dosen.penilaian.pengaturan', 301), ['pertemuan' => 16, 'bobot' => ['kehadiran' => 10, 'tugas' => 20, 'uts' => 30, 'uas' => 30]])
|
||||
->assertSessionHasErrors(['pengaturan_aksi' => 'Total bobot kehadiran, tugas, UTS, dan UAS harus 100%.']);
|
||||
$this->post(route('dosen.penilaian.pengaturan', 301), ['pertemuan' => 0] + $valid)->assertSessionHasErrors('pertemuan');
|
||||
$this->post(route('dosen.penilaian.pengaturan', 304), $valid)->assertNotFound();
|
||||
$this->assertSame(16, (int) $this->db()->table('t_jadwal')->where('idjadwal', 301)->value('jmlpertemuan'));
|
||||
|
||||
$this->db()->table('t_jadwal')->where('idjadwal', 301)->update(['flag_cetak' => true]);
|
||||
$this->post(route('dosen.penilaian.pengaturan', 301), ['pertemuan' => 12] + $valid)
|
||||
->assertSessionHasErrors(['pengaturan_aksi' => 'Nilai kelas ini sudah dikunci, sehingga pengaturan penilaian tidak dapat diubah.']);
|
||||
}
|
||||
|
||||
public function test_incomplete_components_leave_the_final_grade_empty(): void
|
||||
{
|
||||
$this->seedTeaching();
|
||||
|
||||
// Presensi belum diisi: nilai akhir belum bisa dihitung walau tiga komponen terisi.
|
||||
$this->post(route('dosen.penilaian.store'), ['kelas' => 301, 'nilai' => [$this->idkst(500) => ['tugas' => 80, 'uts' => 90, 'uas' => 70]]]);
|
||||
|
||||
$row = $this->kst(500)->first();
|
||||
$this->assertSame([80.0, 90.0, 70.0], [(float) $row->tugas, (float) $row->uts, (float) $row->uas]);
|
||||
$this->assertNull($row->nilaihuruf);
|
||||
$this->assertNull($row->nilaitotal);
|
||||
}
|
||||
|
||||
public function test_grade_values_are_validated(): void
|
||||
{
|
||||
$this->seedTeaching();
|
||||
|
||||
$this->post(route('dosen.penilaian.store'), ['kelas' => 301, 'nilai' => [$this->idkst(500) => ['tugas' => 101, 'uts' => 'abc']]])
|
||||
->assertSessionHasErrors(['nilai.'.$this->idkst(500).'.tugas', 'nilai.'.$this->idkst(500).'.uts']);
|
||||
|
||||
$this->post(route('dosen.penilaian.store'), ['kelas' => 304, 'nilai' => [1 => ['tugas' => 5]]])->assertNotFound();
|
||||
$this->assertNull($this->kst(500)->value('tugas'));
|
||||
}
|
||||
|
||||
public function test_grading_window_closed_blocks_edits_and_locking(): void
|
||||
{
|
||||
$this->seedTeaching(gradingOpen: false);
|
||||
|
||||
$this->get(route('dosen.penilaian'))->assertOk()->assertSee('Masa penilaian ditutup')->assertDontSee('Simpan nilai')->assertDontSee('Kunci nilai');
|
||||
|
||||
$this->post(route('dosen.penilaian.store'), ['kelas' => 301, 'nilai' => [$this->idkst(500) => ['tugas' => 80]]])
|
||||
->assertSessionHasErrors(['nilai_aksi' => 'Masa penilaian program studi untuk kelas ini sedang ditutup.']);
|
||||
|
||||
$this->post(route('dosen.penilaian.kunci', 301))
|
||||
->assertSessionHasErrors(['nilai_aksi' => 'Masa penilaian program studi untuk kelas ini sedang ditutup.']);
|
||||
|
||||
$this->assertNull($this->kst(500)->value('tugas'));
|
||||
}
|
||||
|
||||
public function test_locking_requires_complete_grades_then_freezes_the_class(): void
|
||||
{
|
||||
$this->seedTeaching();
|
||||
|
||||
$this->post(route('dosen.penilaian.kunci', 301))
|
||||
->assertSessionHasErrors(['nilai_aksi' => 'Nilai belum lengkap untuk 2 peserta. Lengkapi presensi, tugas, UTS, dan UAS dulu.']);
|
||||
$this->assertSame(0, (int) $this->db()->table('t_jadwal')->where('idjadwal', 301)->value('flag_cetak'));
|
||||
|
||||
$this->post(route('dosen.presensi.store'), ['kelas' => 301, 'hadir' => [$this->idkst(500) => 16, $this->idkst(501) => 16]]);
|
||||
$this->post(route('dosen.penilaian.store'), ['kelas' => 301, 'nilai' => [
|
||||
$this->idkst(500) => ['tugas' => 80, 'uts' => 90, 'uas' => 70],
|
||||
$this->idkst(501) => ['tugas' => 80, 'uts' => 80, 'uas' => 80],
|
||||
]]);
|
||||
|
||||
$this->post(route('dosen.penilaian.kunci', 301))->assertRedirect(route('dosen.penilaian', ['kelas' => 301]))
|
||||
->assertSessionHas('status');
|
||||
$this->assertSame(1, (int) $this->db()->table('t_jadwal')->where('idjadwal', 301)->value('flag_cetak'));
|
||||
|
||||
// Setelah dikunci: tampilan hanya baca dan semua penulisan ditolak.
|
||||
$this->get(route('dosen.penilaian'))->assertOk()->assertSee('Nilai sudah dikunci')->assertDontSee('Simpan nilai');
|
||||
$this->post(route('dosen.penilaian.store'), ['kelas' => 301, 'nilai' => [$this->idkst(500) => ['tugas' => 10]]])
|
||||
->assertSessionHasErrors(['nilai_aksi' => 'Nilai kelas ini sudah dikunci dan tidak dapat diubah.']);
|
||||
$this->post(route('dosen.presensi.store'), ['kelas' => 301, 'hadir' => [$this->idkst(500) => 1]])
|
||||
->assertSessionHasErrors(['presensi' => 'Nilai kelas ini sudah dikunci, sehingga presensi tidak dapat diubah.']);
|
||||
$this->assertSame(80.0, (float) $this->kst(500)->value('tugas'));
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,16 @@ class LegacyKelasKurikulumCrudTest extends TestCase
|
||||
$table->integer('idprogdi')->nullable();
|
||||
$table->smallInteger('paketke')->default(0);
|
||||
$table->smallInteger('jmlpertemuan')->nullable();
|
||||
// Kolom penilaian dari skema bersama (FakesLegacyDatabase) ikut disalin.
|
||||
$table->smallInteger('bobotkehadiran')->default(10);
|
||||
$table->smallInteger('bobottugas')->default(20);
|
||||
$table->smallInteger('bobotuts')->default(30);
|
||||
$table->smallInteger('bobotuas')->default(40);
|
||||
foreach (['pka', 'pkb', 'pkc', 'pkd', 'pke'] as $kolom) {
|
||||
$table->smallInteger($kolom)->nullable();
|
||||
}
|
||||
$table->smallInteger('sistempenilaian')->default(0);
|
||||
$table->boolean('filter_kehadiran')->default(false);
|
||||
$table->integer('idpubnilai')->nullable();
|
||||
$table->string('cname')->nullable();
|
||||
$table->string('cip')->nullable();
|
||||
|
||||
@@ -29,6 +29,33 @@ class LegacyRoleTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string, array{int, list<int>, bool, list<Role>}> */
|
||||
public static function allCases(): array
|
||||
{
|
||||
return [
|
||||
'mahasiswa' => [LegacyRole::JENIS_MAHASISWA, [], false, [Role::Mahasiswa]],
|
||||
'hanya administrator pusat' => [LegacyRole::JENIS_PEGAWAI, [1], false, [Role::Superuser]],
|
||||
'superuser yang dosen' => [LegacyRole::JENIS_PEGAWAI, [1, 2], true, [Role::Superuser, Role::Dosen]],
|
||||
'staf yang dosen' => [LegacyRole::JENIS_PEGAWAI, [7], true, [Role::Operator, Role::Dosen]],
|
||||
'ka progdi dosen: dosen dulu, operator karena otoritas lain' => [LegacyRole::JENIS_PEGAWAI, [18], true, [Role::Dosen, Role::Operator]],
|
||||
'staf dan otoritas lain tidak ganda' => [LegacyRole::JENIS_PEGAWAI, [10, 20], false, [Role::Operator]],
|
||||
'admin dan staf' => [LegacyRole::JENIS_PEGAWAI, [22, 7], false, [Role::Admin, Role::Operator]],
|
||||
'dosen saja' => [LegacyRole::JENIS_PEGAWAI, [], true, [Role::Dosen]],
|
||||
'tanpa otoritas' => [LegacyRole::JENIS_PEGAWAI, [], false, []],
|
||||
'jenis tak dikenal' => [9, [1], false, []],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $otoritas
|
||||
* @param list<Role> $expected
|
||||
*/
|
||||
#[DataProvider('allCases')]
|
||||
public function test_account_may_use_every_role_it_holds(int $jenis, array $otoritas, bool $isDosen, array $expected): void
|
||||
{
|
||||
$this->assertSame($expected, LegacyRole::all($jenis, $otoritas, $isDosen));
|
||||
}
|
||||
|
||||
/** @param list<int> $otoritas */
|
||||
#[DataProvider('cases')]
|
||||
public function test_legacy_account_maps_to_role(int $jenis, array $otoritas, bool $isDosen, ?Role $expected): void
|
||||
|
||||
Reference in New Issue
Block a user