mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
80 lines
1.9 KiB
PHP
80 lines
1.9 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Tests\Feature;
|
||
|
|
||
|
use App\Models\Account;
|
||
|
use App\Models\User;
|
||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||
|
use Tests\TestCase;
|
||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
||
|
class LoginTest extends TestCase
|
||
|
{
|
||
|
|
||
|
use DatabaseTransactions;
|
||
|
|
||
|
public function testLoginFormDisplayed()
|
||
|
{
|
||
|
$response = $this->get('/login');
|
||
|
$response->assertStatus(200);
|
||
|
}
|
||
|
/**
|
||
|
* A valid user can be logged in.
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function testLoginAValidUser()
|
||
|
{
|
||
|
$account = factory(Account::class)->create();
|
||
|
$user = factory(User::class)->create([
|
||
|
'account_id' => $account->id,
|
||
|
]);
|
||
|
|
||
|
$response = $this->post('/login', [
|
||
|
'email' => config('ninja.testvars.username'),
|
||
|
'password' => config('ninja.testvars.password')
|
||
|
]);
|
||
|
|
||
|
$response->assertStatus(302);
|
||
|
$this->assertAuthenticatedAs($user);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* An invalid user cannot be logged in.
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function testDoesNotLoginAnInvalidUser()
|
||
|
{
|
||
|
$account = factory(Account::class)->create();
|
||
|
$user = factory(User::class)->create([
|
||
|
'account_id' => $account->id,
|
||
|
]);
|
||
|
|
||
|
$response = $this->post('/login', [
|
||
|
'email' => config('ninja.testvars.username'),
|
||
|
'password' => 'invalid'
|
||
|
]);
|
||
|
|
||
|
$response->assertSessionHasErrors();
|
||
|
$this->assertGuest();
|
||
|
}
|
||
|
/**
|
||
|
* A logged in user can be logged out.
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function testLogoutAnAuthenticatedUser()
|
||
|
{
|
||
|
$account = factory(Account::class)->create();
|
||
|
$user = factory(User::class)->create([
|
||
|
'account_id' => $account->id,
|
||
|
]);
|
||
|
|
||
|
$response = $this->actingAs($user)->post('/logout');
|
||
|
$response->assertStatus(302);
|
||
|
$this->assertGuest();
|
||
|
}
|
||
|
}
|