1.0.5 fix first login after install .php
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use Database\Seeders\DatabaseSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LoginTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_database_seeder_admin_can_login(): void
|
||||
{
|
||||
$this->seed(DatabaseSeeder::class);
|
||||
|
||||
$response = $this->post('/login', [
|
||||
'email' => 'admin@glastree.local',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect('/dashboard');
|
||||
$this->assertAuthenticated();
|
||||
}
|
||||
|
||||
public function test_admin_user_can_login(): void
|
||||
{
|
||||
User::factory()->create([
|
||||
'name' => 'Admin',
|
||||
'email' => 'admin@example.com',
|
||||
'password' => bcrypt('secret123'),
|
||||
'is_admin' => true,
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
$response = $this->post('/login', [
|
||||
'email' => 'admin@example.com',
|
||||
'password' => 'secret123',
|
||||
]);
|
||||
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect('/dashboard');
|
||||
$this->assertAuthenticated();
|
||||
}
|
||||
|
||||
public function test_login_with_wrong_password_fails(): void
|
||||
{
|
||||
User::factory()->create([
|
||||
'email' => 'admin@example.com',
|
||||
'password' => bcrypt('correct-password'),
|
||||
'is_admin' => true,
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
$response = $this->from('/login')->post('/login', [
|
||||
'email' => 'admin@example.com',
|
||||
'password' => 'wrong-password',
|
||||
]);
|
||||
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect('/login');
|
||||
$this->assertGuest();
|
||||
}
|
||||
|
||||
public function test_suspended_user_cannot_login(): void
|
||||
{
|
||||
User::factory()->create([
|
||||
'email' => 'suspended@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
'status' => 'suspended',
|
||||
]);
|
||||
|
||||
$response = $this->post('/login', [
|
||||
'email' => 'suspended@example.com',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect('/');
|
||||
$this->assertGuest();
|
||||
}
|
||||
|
||||
public function test_login_page_loads(): void
|
||||
{
|
||||
$response = $this->get('/login');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Email');
|
||||
$response->assertSee('Password');
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,11 @@ class ExampleTest extends TestCase
|
||||
/**
|
||||
* A basic test example.
|
||||
*/
|
||||
public function test_the_application_returns_a_successful_response(): void
|
||||
public function test_the_application_root_redirects_to_login(): void
|
||||
{
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('login'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user