86 lines
4.0 KiB
PHP
86 lines
4.0 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;
|
|
|
|
/**
|
|
* Hapus pegawai (t_pegawai + t_dosen) berdata asli di Portal > Pegawai. Tambah dan ubah: LegacyEmployeeDetailTest; Portal >
|
|
* Mahasiswa hanya baca (ubah di halaman detail: LegacyStudentDetailTest).
|
|
* Akun staf fakultas memegang prodi 21 dan 22 (fakultas 5); prodi 99 di luar cakupan.
|
|
*/
|
|
class LegacyStudentEmployeeCrudTest extends TestCase
|
|
{
|
|
use FakesLegacyDatabase;
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->useLegacyDatabase();
|
|
$this->seedLegacyOverview();
|
|
$this->seedLegacyEmployees();
|
|
$this->seedLegacyCurriculum();
|
|
$this->seedLegacyPortal();
|
|
$this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf'])
|
|
->assertRedirect(route('operator.dashboard'));
|
|
}
|
|
|
|
private function db(): ConnectionInterface
|
|
{
|
|
return DB::connection('untan');
|
|
}
|
|
|
|
public function test_guests_and_other_roles_cannot_write(): void
|
|
{
|
|
$this->post(route('logout'));
|
|
$this->post(route('operator.list-pegawai.destroy'))->assertRedirect(route('login'));
|
|
|
|
Auth::forgetGuards();
|
|
config(['auth.guards.web.provider' => 'users']);
|
|
$this->actingAs(User::factory()->mahasiswa()->create())->post(route('operator.list-pegawai.destroy'), ['ids' => [11]])->assertForbidden();
|
|
$this->assertSame(1, $this->db()->table('t_pegawai')->where('idpegawai', 11)->count());
|
|
}
|
|
|
|
public function test_pages_wire_the_real_buttons(): void
|
|
{
|
|
$this->get(route('operator.halaman', 'list_pegawai'))->assertOk()
|
|
->assertSee('Hapus pegawai?')->assertSee('askRemove([row.id])', false)->assertSee('startInsert()', false)->assertSee('link(row)', false)
|
|
->assertDontSee('startEdit(row)', false)->assertDontSee('startView(row)', false)->assertDontSee('window.print()', false)
|
|
->assertDontSee("demo('", false)->assertDontSee('Aksi'.': tampilan prototipe');
|
|
}
|
|
|
|
public function test_employee_delete_only_when_unreferenced(): void
|
|
{
|
|
$url = route('operator.list-pegawai.destroy');
|
|
$new = 30;
|
|
$this->db()->table('t_pegawai')->insert(['idpegawai' => $new, 'nip' => '199201012020121001', 'nama' => 'Hendra Saputra']);
|
|
$this->db()->table('t_dosen')->insert(['idpegawai' => $new, 'idprogdi' => 21]);
|
|
|
|
// 11 membimbing mahasiswa (idpa), 21 memegang jabatan aktif: ditolak, baris yang boleh ikut batal.
|
|
$this->postJson($url, ['ids' => [$new, 11]])->assertStatus(422)->assertJsonPath('message', 'Pegawai Siti Aminah masih dirujuk jabatan, jadwal, bimbingan, skripsi, atau akun login sehingga tidak boleh dihapus.');
|
|
$this->assertSame(1, $this->db()->table('t_pegawai')->where('idpegawai', $new)->count());
|
|
$this->postJson($url, ['ids' => [21]])->assertStatus(422);
|
|
|
|
$this->db()->table('t_account')->insert(['iduser' => 901, 'username' => 'p', 'passwd' => 'q', 'identitas' => 24, 'jenis' => 0]);
|
|
$this->postJson($url, ['ids' => [24]])->assertStatus(422);
|
|
$this->assertSame(3, $this->db()->table('t_pegawai')->whereIn('idpegawai', [11, 21, 24])->count());
|
|
|
|
// Di luar cakupan atau tidak ada.
|
|
$this->postJson($url, ['ids' => [22, 9999]])->assertStatus(422)->assertJsonPath('message', 'Pegawai tidak ditemukan.');
|
|
$this->assertSame(1, $this->db()->table('t_pegawai')->where('idpegawai', 22)->count());
|
|
$this->postJson($url, [])->assertStatus(422)->assertJsonValidationErrors('ids');
|
|
|
|
$this->postJson($url, ['ids' => [$new]])->assertOk()->assertJsonPath('message', '1 pegawai dihapus.');
|
|
$this->assertSame(0, $this->db()->table('t_pegawai')->where('idpegawai', $new)->count());
|
|
$this->assertSame(0, $this->db()->table('t_dosen')->where('idpegawai', $new)->count());
|
|
}
|
|
}
|