252 lines
17 KiB
PHP
252 lines
17 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Operator;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\ConnectionInterface;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\Concerns\FakesLegacyDatabase;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* CRUD Perkuliahan > Administrasi berdata asli: Pembimbing Akademik (t_mahasiswa.idpa), Cekal (t_mahasiswa_cekal),
|
|
* Berhenti Studi (t_cuti), Mahasiswa Keluar (t_mahasiswa.stataktif), dan halaman turunan yang tetap hanya baca.
|
|
*/
|
|
class LegacyAdministrasiCrudTest extends TestCase
|
|
{
|
|
use FakesLegacyDatabase;
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->useLegacyDatabase();
|
|
$this->seedLegacyOverview();
|
|
$this->seedLegacyEmployees();
|
|
$this->seedLegacyCurriculum();
|
|
$this->seedLegacyAdministration();
|
|
|
|
$db = DB::connection('untan');
|
|
// 700 di prodi 99 (di luar akun); dosen 40 aktif di prodi 22; 41 aktif tetapi home base prodi 99.
|
|
$db->table('t_mahasiswa')->insert(['idmahasiswa' => 700, 'nim' => 'X700', 'nama' => 'Mahasiswa 700', 'idprogdi' => 99, 'idangkatan' => 150, 'stataktif' => 1, 'idprogram' => 1, 'jalur_masuk' => 1]);
|
|
$db->table('t_pegawai')->insert([
|
|
['idpegawai' => 40, 'nip' => '198801012012011040', 'nama' => 'Dosen Sipil', 'gelardepan' => '', 'gelarbelakang' => 'M.T.', 'statusaktif' => 1],
|
|
['idpegawai' => 41, 'nip' => '198801012012011041', 'nama' => 'Dosen Luar', 'gelardepan' => '', 'gelarbelakang' => '', 'statusaktif' => 1],
|
|
]);
|
|
$db->table('t_dosen')->insert([['idpegawai' => 40, 'idprogdi' => 22], ['idpegawai' => 41, 'idprogdi' => 99]]);
|
|
$db->table('xs_alasan_cuti')->insert([['idjalasan' => 1, 'alasan' => 'Ekonomi'], ['idjalasan' => 2, 'alasan' => 'Sakit']]);
|
|
|
|
$this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf'])
|
|
->assertRedirect(route('operator.dashboard'));
|
|
}
|
|
|
|
private function db(): ConnectionInterface
|
|
{
|
|
return DB::connection('untan');
|
|
}
|
|
|
|
private function rows(string $route, array $query = []): array
|
|
{
|
|
return $this->getJson(route($route, $query))->assertOk()->json('rows');
|
|
}
|
|
|
|
public function test_tamu_dan_role_lain_ditolak(): void
|
|
{
|
|
$routes = [
|
|
['post', route('operator.pembimbing-akademik.store')], ['post', route('operator.pembimbing-akademik.destroy')], ['put', route('operator.pembimbing-akademik.update', 500)],
|
|
['post', route('operator.cekal.store')], ['post', route('operator.cekal.destroy')], ['put', route('operator.cekal.update', 500)],
|
|
['post', route('operator.berhenti-studi.store')], ['post', route('operator.berhenti-studi.destroy')], ['put', route('operator.berhenti-studi.update', 'c-1')],
|
|
['post', route('operator.mahasiswa-keluar.store')], ['post', route('operator.mahasiswa-keluar.destroy')], ['put', route('operator.mahasiswa-keluar.update', 506)],
|
|
];
|
|
|
|
$this->post(route('logout'));
|
|
foreach ($routes as [$method, $url]) {
|
|
$this->{$method.'Json'}($url, [])->assertUnauthorized();
|
|
}
|
|
|
|
Auth::forgetGuards();
|
|
$dosen = User::factory()->dosen()->create();
|
|
foreach ($routes as [$method, $url]) {
|
|
$this->actingAs($dosen)->{$method.'Json'}($url, [])->assertForbidden();
|
|
}
|
|
}
|
|
|
|
public function test_halaman_menampilkan_tombol_tulis_sungguhan(): void
|
|
{
|
|
$this->get(route('operator.halaman', 'list_mhspa'))->assertOk()
|
|
->assertSee('Tambah pembimbing akademik')->assertSee('startInsert()', false)->assertSee('Lepas pembimbing akademik?')->assertDontSee("demo('Aksi')", false);
|
|
$this->get(route('operator.halaman', 'set_cekal'))->assertOk()->assertSee('Tambah cekal')->assertSee('startInsert()', false)->assertSee('Cabut cekal?');
|
|
$this->get(route('operator.halaman', 'set_berhentistudi'))->assertOk()->assertSee('Tambah pengajuan cuti')->assertSee('Hapus pengajuan cuti?');
|
|
$this->get(route('operator.halaman', 'list_mhskeluar'))->assertOk()->assertSee('Tambah mahasiswa keluar')->assertSee('Batalkan status keluar?');
|
|
}
|
|
|
|
public function test_halaman_turunan_tidak_punya_tombol_prototipe(): void
|
|
{
|
|
foreach (['set_semester', 'list_evaluasimhs', 'set_transfermhs', 'list_ekivnilai'] as $slug) {
|
|
$this->get(route('operator.halaman', $slug))->assertOk()->assertDontSee("demo('", false);
|
|
}
|
|
}
|
|
|
|
public function test_pembimbing_akademik_crud(): void
|
|
{
|
|
$dosen = $this->get(route('operator.halaman', 'list_mhspa'))->assertOk()->getContent();
|
|
$this->assertStringContainsString('198801012012011040 - Dosen Sipil, M.T.', $dosen, 'Dosen aktif prodi akun ditawarkan.');
|
|
$this->assertStringNotContainsString('Dosen Luar', $dosen);
|
|
|
|
$row = collect($this->rows('operator.pembimbing-akademik.data'))->firstWhere('nama', 'X501 - Mahasiswa 501');
|
|
$this->assertSame(['nim' => 'X501', 'dosen' => ''], $row['form']);
|
|
|
|
$this->postJson(route('operator.pembimbing-akademik.store'), ['nim' => ' x501 ', 'dosen' => 11])
|
|
->assertCreated()->assertJsonPath('id', 501);
|
|
$this->assertSame(11, (int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', 501)->value('idpa'));
|
|
$row = collect($this->rows('operator.pembimbing-akademik.data'))->firstWhere('nama', 'X501 - Mahasiswa 501');
|
|
$this->assertSame(['197501012000031002 - Siti Aminah, M.Pd.', 11], [$row['pa'], $row['form']['dosen']]);
|
|
|
|
$this->putJson(route('operator.pembimbing-akademik.update', 501), ['dosen' => 40])->assertOk()->assertJsonPath('message', 'Pembimbing akademik diperbarui.');
|
|
$this->assertSame(40, (int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', 501)->value('idpa'));
|
|
|
|
$this->postJson(route('operator.pembimbing-akademik.destroy'), ['ids' => [501, 502]])->assertOk()->assertJsonPath('message', '1 pembimbing akademik dilepas.');
|
|
$this->assertNull($this->db()->table('t_mahasiswa')->where('idmahasiswa', 501)->value('idpa'));
|
|
}
|
|
|
|
public function test_pembimbing_akademik_validasi_dan_penjagaan(): void
|
|
{
|
|
$this->postJson(route('operator.pembimbing-akademik.store'), [])->assertStatus(422)->assertJsonValidationErrors(['nim', 'dosen']);
|
|
$this->postJson(route('operator.pembimbing-akademik.store'), ['nim' => 'X700', 'dosen' => 11])
|
|
->assertStatus(422)->assertJsonPath('message', 'NIM X700 tidak ditemukan pada mahasiswa aktif program studi Anda.');
|
|
$this->postJson(route('operator.pembimbing-akademik.store'), ['nim' => 'X506', 'dosen' => 11])->assertStatus(422);
|
|
foreach ([41, 20, 22, 24, 999] as $dosen) {
|
|
$this->postJson(route('operator.pembimbing-akademik.store'), ['nim' => 'X501', 'dosen' => $dosen])
|
|
->assertStatus(422)->assertJsonPath('message', 'Dosen harus dipilih dari dosen aktif program studi Anda.');
|
|
}
|
|
$this->putJson(route('operator.pembimbing-akademik.update', 700), ['dosen' => 11])->assertStatus(422);
|
|
$this->putJson(route('operator.pembimbing-akademik.update', 501), [])->assertStatus(422)->assertJsonValidationErrors(['dosen']);
|
|
|
|
$this->db()->table('t_mahasiswa')->where('idmahasiswa', 700)->update(['idpa' => 41]);
|
|
$this->postJson(route('operator.pembimbing-akademik.destroy'), ['ids' => [700]])->assertStatus(422);
|
|
$this->postJson(route('operator.pembimbing-akademik.destroy'), ['ids' => []])->assertStatus(422)->assertJsonValidationErrors(['ids']);
|
|
$this->assertSame(41, (int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', 700)->value('idpa'), 'Mahasiswa prodi lain tidak tersentuh.');
|
|
$this->assertNull($this->db()->table('t_mahasiswa')->where('idmahasiswa', 501)->value('idpa'));
|
|
}
|
|
|
|
public function test_cekal_crud(): void
|
|
{
|
|
$row = collect($this->rows('operator.cekal.data'))->firstWhere('nim', 'X501');
|
|
$this->assertSame(['nim' => 'X501', 'cekal' => 0], $row['form']);
|
|
|
|
$this->postJson(route('operator.cekal.store'), ['nim' => 'x501', 'cekal' => 1])->assertCreated()->assertJsonPath('id', 501);
|
|
$cekal = $this->db()->table('t_mahasiswa_cekal')->where('idmahasiswa', 501)->first();
|
|
$this->assertSame('X501', $cekal->nim);
|
|
$this->assertSame('Ya', collect($this->rows('operator.cekal.data'))->firstWhere('nim', 'X501')['cekal']);
|
|
|
|
$this->postJson(route('operator.cekal.store'), ['nim' => 'X501', 'cekal' => 1])->assertStatus(422)->assertJsonPath('message', 'Mahasiswa sudah berstatus cekal.');
|
|
$this->assertSame(1, $this->db()->table('t_mahasiswa_cekal')->where('idmahasiswa', 501)->count());
|
|
|
|
$this->putJson(route('operator.cekal.update', 502), ['cekal' => 1])->assertOk();
|
|
$this->assertTrue($this->db()->table('t_mahasiswa_cekal')->where('idmahasiswa', 502)->exists());
|
|
$this->putJson(route('operator.cekal.update', 502), ['cekal' => 0])->assertOk();
|
|
$this->assertFalse($this->db()->table('t_mahasiswa_cekal')->where('idmahasiswa', 502)->exists());
|
|
|
|
$this->postJson(route('operator.cekal.destroy'), ['ids' => [501, 503, 504]])->assertOk()->assertJsonPath('message', '2 cekal dicabut.');
|
|
$this->assertSame(0, $this->db()->table('t_mahasiswa_cekal')->count());
|
|
}
|
|
|
|
public function test_cekal_validasi_dan_penjagaan(): void
|
|
{
|
|
$this->postJson(route('operator.cekal.store'), [])->assertStatus(422)->assertJsonValidationErrors(['nim', 'cekal']);
|
|
$this->postJson(route('operator.cekal.store'), ['nim' => 'X501', 'cekal' => 0])->assertStatus(422);
|
|
$this->postJson(route('operator.cekal.store'), ['nim' => 'X700', 'cekal' => 1])->assertStatus(422);
|
|
$this->postJson(route('operator.cekal.store'), ['nim' => 'TIDAKADA', 'cekal' => 1])->assertStatus(422);
|
|
$this->putJson(route('operator.cekal.update', 700), ['cekal' => 1])->assertStatus(422);
|
|
$this->putJson(route('operator.cekal.update', 506), ['cekal' => 1])->assertStatus(422);
|
|
|
|
$this->db()->table('t_mahasiswa_cekal')->insert(['idmahasiswa' => 700, 'nim' => 'X700']);
|
|
$this->postJson(route('operator.cekal.destroy'), ['ids' => [700]])->assertStatus(422);
|
|
$this->assertTrue($this->db()->table('t_mahasiswa_cekal')->where('idmahasiswa', 700)->exists(), 'Cekal prodi lain tidak dicabut.');
|
|
$this->assertTrue($this->db()->table('t_mahasiswa_cekal')->where('idmahasiswa', 503)->exists(), 'Cekal 503 (seed) utuh.');
|
|
}
|
|
|
|
public function test_berhenti_studi_cuti_crud(): void
|
|
{
|
|
$rows = collect($this->rows('operator.berhenti-studi.data'));
|
|
$cuti = $rows->firstWhere('id', 'c-2');
|
|
$this->assertSame(['nim' => 'X505', 'periode' => 368, 'alasan' => 1, 'status' => 0], $cuti['form']);
|
|
$this->assertNull($rows->firstWhere('id', 'm-506')['form'], 'Mutasi DIKTI tidak dapat diubah.');
|
|
|
|
$id = $this->postJson(route('operator.berhenti-studi.store'), ['nim' => 'x504', 'periode' => 371, 'alasan' => 2, 'status' => 2])
|
|
->assertCreated()->json('id');
|
|
$leave = $this->db()->table('t_cuti')->where('idcuti', $id)->first();
|
|
$this->assertSame([504, 371, 371, 2, 2, now()->toDateString(), now()->toDateString()], [(int) $leave->idmahasiswa, (int) $leave->mulai, (int) $leave->sampai, (int) $leave->alasancuti, (int) $leave->stat, $leave->tglmohon, $leave->tglverifikasi]);
|
|
$row = collect($this->rows('operator.berhenti-studi.data'))->firstWhere('id', "c-{$id}");
|
|
$this->assertSame(['Cuti', 'Disetujui'], [$row['jenis'], $row['status']]);
|
|
|
|
$this->postJson(route('operator.berhenti-studi.store'), ['nim' => 'X504', 'periode' => 371, 'status' => 0])
|
|
->assertStatus(422)->assertJsonPath('message', 'Mahasiswa sudah memiliki pengajuan cuti pada periode itu.');
|
|
|
|
$this->putJson(route('operator.berhenti-studi.update', "c-{$id}"), ['periode' => 368, 'alasan' => 1, 'status' => 3])->assertOk();
|
|
$leave = $this->db()->table('t_cuti')->where('idcuti', $id)->first();
|
|
$this->assertSame([368, 3, 1], [(int) $leave->mulai, (int) $leave->stat, (int) $leave->alasancuti]);
|
|
$this->putJson(route('operator.berhenti-studi.update', 'c-2'), ['periode' => 368, 'status' => 0])->assertOk();
|
|
$this->assertNull($this->db()->table('t_cuti')->where('idcuti', 2)->value('tglverifikasi'));
|
|
|
|
$this->postJson(route('operator.berhenti-studi.destroy'), ['ids' => ["c-{$id}"]])->assertOk()->assertJsonPath('message', '1 pengajuan cuti dihapus.');
|
|
$this->assertFalse($this->db()->table('t_cuti')->where('idcuti', $id)->exists());
|
|
}
|
|
|
|
public function test_berhenti_studi_validasi_dan_penjagaan(): void
|
|
{
|
|
$this->postJson(route('operator.berhenti-studi.store'), [])->assertStatus(422)->assertJsonValidationErrors(['nim', 'periode', 'status']);
|
|
$base = ['nim' => 'X504', 'periode' => 371, 'status' => 0];
|
|
$this->postJson(route('operator.berhenti-studi.store'), ['nim' => 'X700'] + $base)->assertStatus(422);
|
|
$this->postJson(route('operator.berhenti-studi.store'), ['periode' => 9999] + $base)->assertStatus(422)->assertJsonPath('message', 'Periode tidak ditemukan.');
|
|
$this->postJson(route('operator.berhenti-studi.store'), ['status' => 9] + $base)->assertStatus(422)->assertJsonPath('message', 'Status pengajuan tidak dikenal.');
|
|
$this->postJson(route('operator.berhenti-studi.store'), ['alasan' => 77] + $base)->assertStatus(422)->assertJsonPath('message', 'Alasan cuti tidak ditemukan.');
|
|
$this->assertSame(2, $this->db()->table('t_cuti')->count(), 'Tidak ada cuti baru yang tersimpan.');
|
|
|
|
$this->db()->table('t_cuti')->insert(['idcuti' => 9, 'idmahasiswa' => 700, 'mulai' => 368, 'sampai' => 368, 'stat' => 0]);
|
|
$this->putJson(route('operator.berhenti-studi.update', 'c-9'), ['periode' => 371, 'status' => 2])->assertStatus(422)->assertJsonPath('message', 'Pengajuan cuti tidak ditemukan.');
|
|
$this->postJson(route('operator.berhenti-studi.destroy'), ['ids' => ['c-9']])->assertStatus(422);
|
|
$this->assertTrue($this->db()->table('t_cuti')->where('idcuti', 9)->exists(), 'Cuti prodi lain utuh.');
|
|
|
|
$this->putJson(route('operator.berhenti-studi.update', 'm-506'), ['periode' => 368, 'status' => 2])->assertStatus(422);
|
|
$this->postJson(route('operator.berhenti-studi.destroy'), ['ids' => ['m-506']])->assertStatus(422);
|
|
$this->assertSame(1, $this->db()->table('t_mutasi_dikti')->count(), 'Mutasi DIKTI tidak terhapus.');
|
|
}
|
|
|
|
public function test_mahasiswa_keluar_crud(): void
|
|
{
|
|
$row = collect($this->rows('operator.mahasiswa-keluar.data'))->firstWhere('nim', 'X506');
|
|
$this->assertSame(['nim' => 'X506', 'status' => 3], $row['form']);
|
|
|
|
$this->postJson(route('operator.mahasiswa-keluar.store'), ['nim' => 'x504', 'status' => 5])->assertCreated()->assertJsonPath('id', 504);
|
|
$this->assertSame(5, (int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', 504)->value('stataktif'));
|
|
$this->assertSame('Pindah', collect($this->rows('operator.mahasiswa-keluar.data'))->firstWhere('nim', 'X504')['status']);
|
|
|
|
$this->putJson(route('operator.mahasiswa-keluar.update', 504), ['status' => 4])->assertOk();
|
|
$this->assertSame(4, (int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', 504)->value('stataktif'));
|
|
|
|
$this->postJson(route('operator.mahasiswa-keluar.destroy'), ['ids' => [504, 506, 505]])->assertOk()->assertJsonPath('message', '2 mahasiswa dikembalikan sebagai masih kuliah.');
|
|
$this->assertSame([1, 1, 2], array_map(fn (int $id): int => (int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', $id)->value('stataktif'), [504, 506, 505]), 'Lulusan (505) tidak tersentuh.');
|
|
}
|
|
|
|
public function test_mahasiswa_keluar_validasi_dan_penjagaan(): void
|
|
{
|
|
$this->postJson(route('operator.mahasiswa-keluar.store'), [])->assertStatus(422)->assertJsonValidationErrors(['nim', 'status']);
|
|
$this->postJson(route('operator.mahasiswa-keluar.store'), ['nim' => 'X504', 'status' => 1])->assertStatus(422)->assertJsonPath('message', 'Status keluar tidak dikenal.');
|
|
$this->postJson(route('operator.mahasiswa-keluar.store'), ['nim' => 'X504', 'status' => 2])->assertStatus(422);
|
|
$this->postJson(route('operator.mahasiswa-keluar.store'), ['nim' => 'X700', 'status' => 3])->assertStatus(422);
|
|
$this->postJson(route('operator.mahasiswa-keluar.store'), ['nim' => 'X506', 'status' => 3])->assertStatus(422)->assertJsonPath('message', 'NIM X506 tidak ditemukan pada mahasiswa aktif program studi Anda.');
|
|
$this->putJson(route('operator.mahasiswa-keluar.update', 504), ['status' => 4])->assertStatus(422)->assertJsonPath('message', 'Mahasiswa keluar tidak ditemukan.');
|
|
$this->putJson(route('operator.mahasiswa-keluar.update', 506), ['status' => 1])->assertStatus(422);
|
|
|
|
$this->db()->table('t_mahasiswa')->where('idmahasiswa', 700)->update(['stataktif' => 4]);
|
|
$this->postJson(route('operator.mahasiswa-keluar.destroy'), ['ids' => [700]])->assertStatus(422);
|
|
$this->putJson(route('operator.mahasiswa-keluar.update', 700), ['status' => 3])->assertStatus(422);
|
|
$this->assertSame(4, (int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', 700)->value('stataktif'), 'Prodi lain tidak tersentuh.');
|
|
$this->assertSame([1, 3], array_map(fn (int $id): int => (int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', $id)->value('stataktif'), [504, 506]));
|
|
}
|
|
}
|