Tests fixed

This commit is contained in:
Dan Baker 2026-02-22 19:02:59 +00:00
parent 2418edccfd
commit 030c049ca8
13 changed files with 131 additions and 38 deletions

View file

@ -219,7 +219,7 @@ class MagicLoginTokenTest extends TestCase
public function test_token_expiry_is_15_minutes(): void
{
$beforeCreation = now()->addMinutes(15);
$beforeCreation = now()->startOfSecond()->addMinutes(15);
$token = MagicLoginToken::generate('test@example.com', '127.0.0.1', 'TestAgent');
@ -300,4 +300,25 @@ class MagicLoginTokenTest extends TestCase
$this->assertInstanceOf(\Illuminate\Support\Carbon::class, $token->used_at);
}
public function test_4_word_token_format_validation(): void
{
$token = MagicLoginToken::generate('test@example.com', '127.0.0.1', 'TestAgent');
$plainToken = $token->plain_token;
$this->assertMatchesRegularExpression(
'/^[a-z]+-[a-z]+-[a-z]+-[a-z]+$/',
$plainToken,
'Token should be 4 words separated by hyphens'
);
$words = explode('-', $plainToken);
$this->assertCount(4, $words, 'Token should contain exactly 4 words');
foreach ($words as $word) {
$this->assertNotEmpty($word, 'Each word should not be empty');
$this->assertMatchesRegularExpression('/^[a-z]+$/', $word, 'Each word should contain only lowercase letters');
}
}
}