Files
huginn/tests/Feature/AuthFlowTest.php
T

67 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature;
use App\Livewire\Auth\Login;
use App\Livewire\Auth\Register;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class AuthFlowTest extends TestCase
{
use RefreshDatabase;
public function test_a_user_can_register(): void
{
Livewire::test(Register::class)
->set('name', 'Test User')
->set('email', 'testuser@example.com')
->set('password', 'correct-horse-battery-staple')
->set('password_confirmation', 'correct-horse-battery-staple')
->call('register')
->assertRedirect(route('sites.index'));
$this->assertAuthenticated();
$this->assertDatabaseHas('users', ['email' => 'testuser@example.com']);
}
public function test_a_user_can_log_in(): void
{
$user = User::factory()->create(['password' => 'correct-horse-battery-staple']);
Livewire::test(Login::class)
->set('email', $user->email)
->set('password', 'correct-horse-battery-staple')
->call('login')
->assertRedirect(route('sites.index'));
$this->assertAuthenticatedAs($user);
}
public function test_login_fails_with_wrong_password(): void
{
$user = User::factory()->create(['password' => 'correct-horse-battery-staple']);
Livewire::test(Login::class)
->set('email', $user->email)
->set('password', 'wrong-password')
->call('login')
->assertHasErrors('email');
$this->assertGuest();
}
public function test_a_user_can_log_out(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->post(route('logout'))
->assertRedirect(route('home'));
$this->assertGuest();
}
}