LoggedInFormTest.php
3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
use Tests\BrowserKitTestCase;
/**
 * Class LoggedInFormTest.
 */
class LoggedInFormTest extends BrowserKitTestCase
{
    /**
     * Test that the errors work if nothing is filled in the update account form.
     */
    public function testUpdateProfileRequiredFields()
    {
        if (config('access.users.change_email')) {
            $this->actingAs($this->user)
                 ->visit('/account')
                 ->type('', 'first_name')
                 ->type('', 'last_name')
                 ->type('', 'email')
                 ->press('update-profile')
                 ->seePageIs('/account')
                 ->see('The first name field is required.')
                 ->see('The last name field is required.')
                 ->see('The email field is required.');
        } else {
            $this->actingAs($this->user)
                 ->visit('/account')
                 ->type('', 'first_name')
                 ->type('', 'last_name')
                 ->press('update-profile')
                 ->seePageIs('/account')
                 ->see('The first name field is required.')
                 ->see('The last name field is required.');
        }
    }
    /**
     * Test that we can target the update profile form and update the profile
     * Based on whether the user is allowed to alter their email address or not.
     */
    public function testUpdateProfileForm()
    {
        $rand = rand();
        if (config('access.users.change_email')) {
            $this->actingAs($this->user)
                 ->visit('/account')
                 ->see('My Account')
                 ->type($this->user->first_name.'_'.$rand, 'first_name')
                 ->type($this->user->last_name.'_'.$rand, 'last_name')
                 ->type('2_'.$this->user->email, 'email')
                 ->press('update-profile')
                 ->seePageIs('/account')
                 ->see('Profile successfully updated.')
                 ->seeInDatabase(config('access.users_table'),
                     [
                         'email' => '2_'.$this->user->email,
                         'first_name' => $this->user->first_name.'_'.$rand,
                         'last_name' => $this->user->last_name.'_'.$rand,
                     ]);
        } else {
            $this->actingAs($this->user)
                 ->visit('/account')
                 ->see('My Account')
                 ->type($this->user->first_name.'_'.$rand, 'first_name')
                 ->type($this->user->last_name.'_'.$rand, 'last_name')
                 ->press('update-profile')
                 ->seePageIs('/account')
                 ->see('Profile successfully updated.')
                 ->seeInDatabase(config('access.users_table'),
                     [
                         'first_name' => $this->user->first_name.'_'.$rand,
                         'last_name' => $this->user->last_name.'_'.$rand,
                     ]);
        }
    }
    /**
     * Test that the errors work if nothing is filled in the change password form.
     */
    public function testChangePasswordRequiredFields()
    {
        $this->actingAs($this->user)
             ->visit('/account')
             ->type('', 'old_password')
             ->type('', 'password')
             ->type('', 'password_confirmation')
             ->press('change-password')
             ->seePageIs('/account')
             ->see('The old password field is required.')
             ->see('The password field is required.');
    }
    /**
     * Test that the frontend change password form works.
     */
    public function testChangePasswordForm()
    {
        $password = '87654321';
        $this->actingAs($this->user)
             ->visit('/account')
             ->see('My Account')
             ->type('1234', 'old_password')
             ->type($password, 'password')
             ->type($password, 'password_confirmation')
             ->press('change-password')
             ->seePageIs('/account')
             ->see('Password successfully updated.');
    }
}