Added logout test

This commit is contained in:
Sergio Brighenti 2020-10-03 17:08:31 +02:00
parent 5af536273e
commit 00ae95e965

View file

@ -1,7 +1,7 @@
<?php
namespace Tests\Feature;
namespace Tests\Feature\Auth;
use Tests\TestCase;
@ -102,4 +102,31 @@ class LoginControllerTest extends TestCase
$redirect = $this->submitForm($form)->getHeaderLine('Location');
$this->assertSame(route('profile'), $redirect);
}
/** @test */
public function it_logout_the_user()
{
$this->createAdminUser();
$response = $this->get(route('login.show'));
$form = $this->getCrawler($response)
->selectButton('Login')
->form([
'username' => 'admin@example.com',
'password' => 'admin',
'remember' => 'on',
], 'POST');
$this->submitForm($form);
$this->assertSame(200, $response->getStatusCode());
$response = $this->post(route('logout'));
$this->assertSame(302, $response->getStatusCode());
$response = $this->get(route('home'));
$this->assertSame(302, $response->getStatusCode());
$this->assertSame(route('login.show'), $response->getHeaderLine('Location'));
$this->assertFalse($this->app->getContainer()->get('session')->get('logged'));
}
}