Files
breadcrumb-the-shire/tests/Service/User/UserPasswordPolicyServiceTest.php
2026-03-04 15:56:58 +01:00

60 lines
1.8 KiB
PHP

<?php
namespace MintyPHP\Tests\Service\User;
use MintyPHP\Service\User\UserPasswordPolicyService;
use PHPUnit\Framework\TestCase;
class UserPasswordPolicyServiceTest extends TestCase
{
public function testMinLengthMatchesHints(): void
{
$service = new UserPasswordPolicyService();
$this->assertSame(12, $service->minLength());
$hints = $service->hints();
$this->assertNotEmpty($hints);
$this->assertSame('min', (string) ($hints[0]['rule'] ?? ''));
}
public function testValidateRejectsWeakPassword(): void
{
$service = new UserPasswordPolicyService();
$errors = $service->validate('abc', 'abc', true, 'foo@example.com');
$this->assertNotEmpty($errors);
}
public function testValidateRequiresPasswordWhenRequired(): void
{
$service = new UserPasswordPolicyService();
$errors = $service->validate('', '', true, 'test@example.com');
$this->assertNotEmpty($errors);
}
public function testValidateRejectsMismatch(): void
{
$service = new UserPasswordPolicyService();
$errors = $service->validate('Abcd1234$efg', 'Abcd1234$xxx', true, 'test@example.com');
$this->assertNotEmpty($errors);
}
public function testValidateAcceptsStrongPassword(): void
{
$service = new UserPasswordPolicyService();
$errors = $service->validate('StrongPass1!', 'StrongPass1!', true, 'test@example.com');
$this->assertSame([], $errors);
}
public function testValidateRejectsPasswordContainingEmail(): void
{
$service = new UserPasswordPolicyService();
$errors = $service->validate('test@example.comA1!', 'test@example.comA1!', true, 'test@example.com');
$this->assertNotEmpty($errors);
}
}