Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User login test case #3384

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions tests/Feature/UserLogInTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Modules\User\Entities\User;
use Tests\TestCase;

class UserLogInTest extends TestCase
{
use RefreshDatabase;

/**
* A basic test example.
*
* @return void
*/
public function test_user_login()
{
$password = 'admin';
$user = User::factory()->create([
'name' => 'User',
'email' => '[email protected]',
'password' => Hash::make($password),
]);

$response = $this->post('/login', [
'email' => $user->email,
'password' => $password,
]);

$response->assertRedirect('/home');
$this->assertAuthenticatedAs($user);
}

public function test_user_login_failed_with_wrong_password()
{
$user = User::factory()->create([
'name' => 'admin',
'email' => '[email protected]',
'password' => Hash::make('Admin'),
]);

$response = $this->from('/login')->post('/login', [
'email' => $user->email,
'password' => 'invalid-password',
]);

$response->assertRedirect('/login');
$response->assertSessionHasErrors('email');
$this->assertTrue(session()->hasOldInput('email'));
$this->assertFalse(session()->hasOldInput('password'));
$this->assertGuest();
}
}
Loading