Files
siakad/tests/Feature/Superuser/LegacyResetPasswordTest.php
T

77 lines
2.9 KiB
PHP

<?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'));
}
}