Permalink
Browse files

Add login and logout feature test

  • Loading branch information...
nafiesl committed Nov 28, 2018
1 parent c2feb56 commit eb202bf09ce4d2dd7074c5b7cf4c5b555024efcc
Showing with 63 additions and 0 deletions.
  1. +63 −0 tests/Feature/Auth/LoginTest.php
@@ -0,0 +1,63 @@
<?php
namespace Tests\Feature\Auth;
use App\User; // Tambahkan use model App\User
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class LoginTest extends TestCase
{
// Trait refresh database agar migration
use RefreshDatabase;
/** @test */
public function registered_user_can_login()
{
// Kita memiliki 1 user terdaftar
$user = factory(User::class)->create([
'email' => 'username@example.net',
'password' => bcrypt('secret'),
]);
// Kunjungi halaman /login
$this->visit('/login');
// Submit form login dengan email dan password yang tepat
$this->submitForm('Login', [
'email' => 'username@example.net',
'password' => 'secret',
]);
// Lihat halaman ter-redirect ke URL home (login sukses).
$this->seePageIs('/home');
// Kita melihat halaman tulisan "Dashboard" pada halaman itu.
$this->seeText('Dashboard');
}
/** @test */
public function logged_in_user_can_logout()
{
// Kita memiliki 1 user terdaftar
$user = factory(User::class)->create([
'email' => 'username@example.net',
'password' => bcrypt('secret'),
]);
// Login sebagai user tersebut
$this->actingAs($user);
// Kunjungi halaman '/home'
$this->visit('/home');
// Buat post request ke url '/logout'
$this->post('/logout');
// Kunjungi (lagi) halaman '/home'
$this->visit('/home');
// User ter-redirect ke halaman '/login'
$this->seePageIs('/login');
}
}

0 comments on commit eb202bf

Please sign in to comment.