Files
ppeasy_vg12/tests/Unit/Support/Authorization/PasswordChangeManagerTest.php
T
2026-10-09 08:21:06 +02:00

54 lines
1.8 KiB
PHP

<?php
use App\Models\User;
use App\Support\Authorization\PasswordChangeManager;
use Illuminate\Cache\CacheManager;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\UpdatesSettings;
uses(RefreshDatabase::class);
uses(UpdatesSettings::class);
beforeEach(function () {
$this->artisan('db:seed');
$this->manager = new PasswordChangeManager(app(CacheManager::class));
});
test('force password change returns false when feature disabled', function () {
$this->setSettings(['password-change.enabled' => false]);
$user = User::factory()->create(['force_password_change' => true]);
$this->assertFalse($this->manager->forcePasswordChange($user));
$this->assertFalse($this->manager->isPasswordChangeForcedForUser($user));
});
test('force password change returns false when user flag false', function () {
$this->setSettings(['password-change.enabled' => true]);
$user = User::factory()->create(['force_password_change' => false]);
$this->assertFalse($this->manager->forcePasswordChange($user));
});
test('force password change sets cache when enabled and flagged', function () {
$this->setSettings(['password-change.enabled' => true]);
$user = User::factory()->create(['force_password_change' => true]);
$this->assertTrue($this->manager->forcePasswordChange($user));
$this->assertTrue($this->manager->isPasswordChangeForcedForUser($user));
});
test('lift password change request clears cache', function () {
$this->setSettings(['password-change.enabled' => true]);
$user = User::factory()->create(['force_password_change' => true]);
$this->manager->forcePasswordChange($user);
$this->manager->liftPasswordChangeRequest($user);
$this->assertFalse($this->manager->isPasswordChangeForcedForUser($user));
});