77 lines
2.1 KiB
PHP
77 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Feature;
|
||
|
|
|
||
|
|
use Tests\TestCase;
|
||
|
|
use App\Models\Planner;
|
||
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
|
||
|
|
class RegistrationTest extends TestCase
|
||
|
|
{
|
||
|
|
use RefreshDatabase;
|
||
|
|
|
||
|
|
public function test_registration_screen_can_be_rendered()
|
||
|
|
{
|
||
|
|
$response = $this->get('/register');
|
||
|
|
|
||
|
|
$response->assertStatus(200);
|
||
|
|
$response->assertViewIs('auth.register');
|
||
|
|
$response->assertSee('Register');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_new_users_can_register()
|
||
|
|
{
|
||
|
|
$response = $this->post('/register', [
|
||
|
|
'name' => 'Test User',
|
||
|
|
'email' => 'test@example.com',
|
||
|
|
'password' => 'password',
|
||
|
|
'password_confirmation' => 'password',
|
||
|
|
]);
|
||
|
|
|
||
|
|
$this->assertAuthenticated();
|
||
|
|
$response->assertRedirect('/dashboard');
|
||
|
|
|
||
|
|
// Check user was created
|
||
|
|
$this->assertDatabaseHas('planners', [
|
||
|
|
'email' => 'test@example.com',
|
||
|
|
'name' => 'Test User',
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_registration_fails_with_existing_email()
|
||
|
|
{
|
||
|
|
$existingUser = Planner::factory()->create([
|
||
|
|
'email' => 'existing@example.com',
|
||
|
|
]);
|
||
|
|
|
||
|
|
$response = $this->post('/register', [
|
||
|
|
'name' => 'Another User',
|
||
|
|
'email' => 'existing@example.com',
|
||
|
|
'password' => 'password',
|
||
|
|
'password_confirmation' => 'password',
|
||
|
|
]);
|
||
|
|
|
||
|
|
$response->assertRedirect();
|
||
|
|
$response->assertSessionHasErrors('email');
|
||
|
|
$this->assertGuest();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_registration_fails_with_password_mismatch()
|
||
|
|
{
|
||
|
|
$response = $this->post('/register', [
|
||
|
|
'name' => 'Test User',
|
||
|
|
'email' => 'test@example.com',
|
||
|
|
'password' => 'password',
|
||
|
|
'password_confirmation' => 'different',
|
||
|
|
]);
|
||
|
|
|
||
|
|
$response->assertRedirect();
|
||
|
|
$response->assertSessionHasErrors('password');
|
||
|
|
$this->assertGuest();
|
||
|
|
|
||
|
|
// Check user was not created
|
||
|
|
$this->assertDatabaseMissing('planners', [
|
||
|
|
'email' => 'test@example.com',
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|