Improve tests
This commit is contained in:
parent
427debaba4
commit
48d1c9a00b
18 changed files with 267 additions and 14 deletions
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminTest extends TestCase
|
||||
|
@ -31,4 +32,51 @@ class AdminTest extends TestCase
|
|||
]);
|
||||
$response->assertRedirect('/login');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function loginSucceeds(): void
|
||||
{
|
||||
User::factory([
|
||||
'name' => 'admin',
|
||||
'password' => bcrypt('password'),
|
||||
])->create();
|
||||
|
||||
$response = $this->post('/login', [
|
||||
'name' => 'admin',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function whenLoggedInRedirectsToAdminPage(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$response = $this->actingAs($user)->get('/login');
|
||||
$response->assertRedirect('/');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function loggedOutUsersSimplyRedirected(): void
|
||||
{
|
||||
$response = $this->get('/logout');
|
||||
$response->assertRedirect('/');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function loggedInUsersShownLogoutForm(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$response = $this->actingAs($user)->get('/logout');
|
||||
$response->assertViewIs('logout');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function loggedInUsersCanLogout(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$response = $this->actingAs($user)->post('/logout');
|
||||
$response->assertRedirect('/');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue