1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace Tests\Browser;
7
8use App\Models\User;
9use Laravel\Dusk\Browser;
10use Tests\DuskTestCase;
11
12class LoginTest extends DuskTestCase
13{
14 /**
15 * Test sign in.
16 *
17 * @return void
18 */
19 public function testLogin()
20 {
21 $user = User::factory()->create();
22
23 $this->browse(function (Browser $browser) use ($user) {
24 $browser->visit('/')
25 ->clickLink('Sign in')
26 ->type('username', $user->user_email)
27 ->type('password', 'password') // User factory generates users with the password hardcoded as 'password'
28 ->press('Sign in')
29 ->waitFor('.user-home')
30 ->assertPathIs('/')
31 ->assertSee('dashboard')
32 ->assertSee('account settings')
33 ->assertDontSee('Incorrect sign in');
34 });
35 }
36
37 /**
38 * Test sign out.
39 *
40 * @return void
41 */
42 public function testLogout()
43 {
44 $user = User::factory()->create();
45
46 $this->browse(function (Browser $browser) use ($user) {
47 $browser->loginAs($user)
48 ->visit('/')
49 ->click('.js-user-login--menu') // bring up user menu
50 ->click('.js-user-header-popup .js-logout-link') // click the logout 'button'
51 ->acceptDialog()
52 ->waitFor('.landing-hero__bg-container')
53 ->assertPathIs('/')
54 ->assertVisible('.landing-hero');
55 });
56 }
57}