2021-11-30 20:09:29 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Browser;
|
|
|
|
|
2023-01-10 17:03:09 -08:00
|
|
|
use App\Models\Setting;
|
2022-08-12 10:00:26 -07:00
|
|
|
use App\Models\User;
|
2021-11-30 20:09:29 -08:00
|
|
|
use Laravel\Dusk\Browser;
|
|
|
|
use Tests\DuskTestCase;
|
|
|
|
|
|
|
|
class LoginTest extends DuskTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test login
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLoginPageLoadsAndUserCanLogin()
|
|
|
|
{
|
2022-08-12 10:00:26 -07:00
|
|
|
// Create a new user
|
|
|
|
$user = User::factory()->make();
|
|
|
|
|
|
|
|
// We override the existing password to use a hash of one we know
|
|
|
|
$user->password = '$2y$10$8o5W8fgAKJbN3Kz4taepeeRVgKsG8pkZ1L4eJfdEKrn2mgI/JgCJy';
|
|
|
|
|
|
|
|
// We want a user that is a superuser
|
|
|
|
$user->permissions = '{"superuser": 1}';
|
|
|
|
|
|
|
|
$user->save();
|
2023-01-10 17:03:09 -08:00
|
|
|
|
|
|
|
Setting::factory()->create();
|
|
|
|
|
2021-11-30 20:09:29 -08:00
|
|
|
$this->browse(function (Browser $browser) {
|
|
|
|
$browser->visitRoute('login')
|
|
|
|
->assertSee(trans('auth/general.login_prompt'));
|
|
|
|
});
|
|
|
|
|
2022-08-12 10:00:26 -07:00
|
|
|
$this->browse(function ($browser) use ($user) {
|
2021-11-30 20:09:29 -08:00
|
|
|
$browser->visitRoute('login')
|
2022-08-12 10:00:26 -07:00
|
|
|
->type('username', $user->username)
|
2021-11-30 20:09:29 -08:00
|
|
|
->type('password', 'password')
|
|
|
|
->press(trans('auth/general.login'))
|
|
|
|
->assertPathIs('/');
|
2023-01-10 17:03:09 -08:00
|
|
|
$browser->screenshot('dashboard');
|
2021-11-30 20:09:29 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|