'sqlite', 'database.connections.sqlite.database' => ':memory:', 'session.driver' => 'array', 'cache.default' => 'array']); DB::purge('sqlite'); DB::statement('CREATE TABLE users (id INTEGER PRIMARY KEY, username TEXT, password TEXT, status TEXT, remember_token TEXT, created_at TEXT, updated_at TEXT)'); Route::middleware('web')->get('/account-status-test', function () { return response('allowed'); }); } private function account($status) { return User::create(['username' => 'status-test', 'password' => Hash::make('test-password'), 'status' => $status]); } public function test_inactive_and_banned_accounts_cannot_log_in() { foreach (['inactive', 'banned'] as $status) { DB::table('users')->delete(); $this->account($status); $this->post('/login', ['username' => 'status-test', 'password' => 'test-password']) ->assertSessionHasErrors('username'); $this->assertGuest('web'); } } public function test_active_account_can_log_in() { $user = $this->account('active'); $this->post('/login', ['username' => 'status-test', 'password' => 'test-password']) ->assertRedirect('/home'); $this->assertAuthenticatedAs($user, 'web'); } public function test_inactive_session_is_logged_out_and_cleared() { $user = $this->account('inactive'); $this->actingAs($user, 'web')->withSession(['private-data' => 'remove']) ->get('/account-status-test')->assertRedirect('/login')->assertSessionMissing('private-data'); $this->assertGuest('web'); } public function test_inactive_json_session_is_denied() { $this->actingAs($this->account('inactive'), 'web') ->getJson('/account-status-test')->assertStatus(403); $this->assertGuest('web'); } public function test_active_session_and_guest_can_continue() { $this->get('/account-status-test')->assertOk(); $this->actingAs($this->account('active'), 'web')->get('/account-status-test')->assertOk(); } }