109 lines
5.6 KiB
PHP
109 lines
5.6 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature\Operator;
|
||
|
||
use App\Models\User;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Tests\Concerns\FakesLegacyDatabase;
|
||
use Tests\Concerns\InspectsHtml;
|
||
use Tests\TestCase;
|
||
|
||
/**
|
||
* Perkuliahan > Data Kelas > Periode Kuliah Aktif dari DB lama: periode aktif tiap prodi akun (t_periodekuliahaktif),
|
||
* ubah per prodi seperti Setup Periode Kuliah Aktif SIAKAD lama yang dibatasi unit akun.
|
||
*/
|
||
class LegacyPeriodeAktifTest extends TestCase
|
||
{
|
||
use FakesLegacyDatabase;
|
||
use InspectsHtml;
|
||
use RefreshDatabase;
|
||
|
||
protected function setUp(): void
|
||
{
|
||
parent::setUp();
|
||
|
||
$this->useLegacyDatabase();
|
||
$this->seedLegacyOverview();
|
||
// Prodi di luar unit akun dengan periode aktif lama: tidak tampil dan tidak boleh diubah.
|
||
DB::connection('untan')->table('t_bagian')->insert(['idbagian' => 23, 'idbagian_induk' => 5, 'idjenisbagian' => 3, 'namabagian' => 'Prodi Lain']);
|
||
DB::connection('untan')->table('t_periodekuliahaktif')->insert(['idprogdi' => 23, 'idperiode' => 365]);
|
||
}
|
||
|
||
private function login(): void
|
||
{
|
||
$this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf'])
|
||
->assertRedirect(route('operator.dashboard'));
|
||
}
|
||
|
||
/** @return list<array{0: int, 1: string, 2: string, 3: string, 4: int|string}> */
|
||
private function rows(array $query = []): array
|
||
{
|
||
return array_map(
|
||
fn (array $r): array => [$r['id'], $r['prodi'], $r['periode'], $r['kode'], $r['form']['periode']],
|
||
$this->getJson(route('operator.periode-aktif.data', $query))->assertOk()->json('rows'),
|
||
);
|
||
}
|
||
|
||
public function test_daftar_periode_aktif_prodi_akun(): void
|
||
{
|
||
$this->login();
|
||
$page = $this->get(route('operator.halaman', 'set_periodeaktif'))->assertOk()
|
||
->assertSee('Periode kuliah aktif asli')->assertSee('Ubah periode kuliah aktif');
|
||
$this->assertSame(
|
||
['Program Studi', 'Periode Aktif', 'Kode', 'Diperbarui', 'Oleh', 'Aksi'],
|
||
array_map(fn ($th): string => $this->textOf($th), iterator_to_array($this->dom($page)->query("//*[@aria-label='Daftar Periode Kuliah Aktif']//thead/tr/th"))),
|
||
);
|
||
$this->assertSame(0, $this->dom($page)->query("//*[@aria-label='Daftar Periode Kuliah Aktif']//button[contains(., 'Tambah')]")->length, 'Tanpa Tambah: baris adalah prodi akun.');
|
||
$this->assertSame(1, $this->dom($page)->query("//dialog//select[@name='form_periode']/option[@value='371']")->length, 'Pilihan periode di modal.');
|
||
|
||
$this->assertSame([
|
||
[21, 'Teknik Informatika', '2020/2021 Ganjil', '20201', 368],
|
||
[22, 'Teknik Sipil', '2020/2021 Ganjil', '20201', 368],
|
||
], $this->rows(), 'Hanya prodi akun; prodi 23 tidak tampil.');
|
||
$this->assertSame([[22, 'Teknik Sipil', '2020/2021 Ganjil', '20201', 368]], $this->rows(['q' => 'sipil']));
|
||
}
|
||
|
||
public function test_ubah_periode_aktif_prodi_sendiri(): void
|
||
{
|
||
$this->login();
|
||
$db = DB::connection('untan');
|
||
|
||
$this->putJson(route('operator.periode-aktif.update', 21), ['periode' => 371])
|
||
->assertOk()->assertJsonPath('message', 'Periode aktif Teknik Informatika diperbarui.');
|
||
$row = $db->table('t_periodekuliahaktif')->where('idprogdi', 21)->first();
|
||
$this->assertSame(371, (int) $row->idperiode);
|
||
$this->assertSame('SIAKAD', $row->cname);
|
||
$this->assertSame('198001012005011', $row->uname, 'uname dipotong 15 karakter seperti aplikasi lama.');
|
||
$this->assertNotNull($row->tanggal);
|
||
$this->assertSame(368, (int) $db->table('t_periodekuliahaktif')->where('idprogdi', 22)->value('idperiode'), 'Prodi lain tidak berubah.');
|
||
$this->assertSame([21, 'Teknik Informatika', '2020/2021 Genap', '20202', 371], $this->rows()[0]);
|
||
|
||
// Prodi akun tanpa baris aktif tampil "–" dan disisipkan saat diubah (periode pendek juga boleh).
|
||
$db->table('t_periodekuliahaktif')->where('idprogdi', 22)->delete();
|
||
$this->assertSame([22, 'Teknik Sipil', '–', '–', ''], $this->rows()[1]);
|
||
$this->putJson(route('operator.periode-aktif.update', 22), ['periode' => 366])->assertOk();
|
||
$this->assertSame(366, (int) $db->table('t_periodekuliahaktif')->where('idprogdi', 22)->value('idperiode'));
|
||
$this->assertSame([22, 'Teknik Sipil', '2019/2020 Genap (pendek)', '20193', 366], $this->rows()[1]);
|
||
}
|
||
|
||
public function test_tolak_prodi_lain_dan_periode_tidak_dikenal(): void
|
||
{
|
||
$this->login();
|
||
$db = DB::connection('untan');
|
||
|
||
$this->putJson(route('operator.periode-aktif.update', 23), ['periode' => 371])->assertNotFound();
|
||
$this->assertSame(365, (int) $db->table('t_periodekuliahaktif')->where('idprogdi', 23)->value('idperiode'), 'Prodi di luar unit akun tidak tersentuh.');
|
||
$this->putJson(route('operator.periode-aktif.update', 21), ['periode' => 999])->assertStatus(422)->assertJsonPath('message', 'Periode tidak ditemukan.');
|
||
$this->putJson(route('operator.periode-aktif.update', 21), [])->assertStatus(422);
|
||
$this->assertSame(368, (int) $db->table('t_periodekuliahaktif')->where('idprogdi', 21)->value('idperiode'));
|
||
}
|
||
|
||
public function test_akun_demo_role_lain_dan_tamu(): void
|
||
{
|
||
$this->get(route('operator.halaman', 'set_periodeaktif'))->assertRedirect(route('login'));
|
||
$this->actingAs(User::factory()->operator()->create())->getJson(route('operator.periode-aktif.data'))->assertNotFound();
|
||
$this->actingAs(User::factory()->dosen()->create())->getJson(route('operator.periode-aktif.data'))->assertForbidden();
|
||
}
|
||
}
|