-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creación primeros 2 tests de Usuarios
- Loading branch information
Showing
3 changed files
with
54 additions
and
59 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Tests\TestCase; | ||
|
||
// Importamos modelo de módulo -> Usuario | ||
use App\Models\User; | ||
|
||
class UserTest extends TestCase | ||
{ | ||
/** | ||
* A basic feature test example. | ||
*/ | ||
// public function test_example(): void | ||
// { | ||
// $response = $this->get('/'); | ||
|
||
// $response->assertStatus(200); | ||
// } | ||
|
||
// Test: Un usuario puede acceder a la vista de Inicio de Sesión | ||
public function test_a_user_can_view_a_login_form() { | ||
$response = $this->get('/login'); | ||
|
||
$response->assertSuccessful(); | ||
$response->assertViewIs('auth.login'); | ||
} | ||
|
||
// Test: Un usuario puede Iniciar Sesión | ||
public function test_a_user_can_login() { | ||
// Crear un usuario de prueba | ||
$user = User::factory()->create([ | ||
'name' => "name example", | ||
'email' => 'test@example.com', | ||
'password' => bcrypt('password'), // Cifrar contraseña | ||
]); | ||
|
||
// Visitar la página de inicio de sesión | ||
$response = $this->post('/login', [ | ||
'name' => "name example", | ||
'email' => 'test@example.com', | ||
'password' => 'password', | ||
]); | ||
|
||
// Verificar que el usuario esté redirigido después de iniciar sesión | ||
$response->assertRedirect('/home'); // Redirección a la página principal de Administrador | ||
|
||
// Verificar que el usuario esté autenticado | ||
$this->assertAuthenticatedAs($user); | ||
} | ||
} |