@@ -40,6 +40,166 @@ public function tearDown(): void
4040 parent ::tearDown ();
4141 }
4242
43+ public function testIsProtectedByLogin (): void
44+ {
45+ $ this ->browse (function (Browser $ browser ): void {
46+ $ browser ->visit ('/profile ' )
47+ ->assertUrlIs (config ('app.url ' ) . '/login ' );
48+ });
49+ }
50+
51+ public function testCanChangeNameAndEmail (): void
52+ {
53+ $ this ->users ['admin ' ] = $ this ->makeAdminUser (
54+ 'admin ' ,
55+ 'admin ' ,
56+ 'admin@example.com ' ,
57+ null ,
58+ 'testing ' ,
59+ );
60+
61+ $ this ->browse (function (Browser $ browser ): void {
62+ $ browser ->loginAs ($ this ->users ['admin ' ])
63+ ->visit ('/profile ' )
64+ ->assertInputValue ('@fname-input ' , 'admin ' )
65+ ->assertInputValue ('@lname-input ' , 'admin ' )
66+ ->assertInputValue ('@email-input ' , 'admin@example.com ' )
67+ ->assertInputValue ('@institution-input ' , 'testing ' )
68+
69+ ->clear ('@fname-input ' )
70+ ->type ('@fname-input ' , 'first name here ' )
71+ ->clear ('@lname-input ' )
72+ ->type ('@lname-input ' , 'last name here ' )
73+ ->clear ('@email-input ' )
74+ ->type ('@email-input ' , 'emailtest@example.com ' )
75+ ->clear ('@institution-input ' )
76+ ->type ('@institution-input ' , 'Kitware (Test) ' )
77+
78+ ->click ('@update-profile-button ' )
79+ ->waitForTextIn ('#app ' , 'Your profile has been updated ' );
80+ });
81+
82+ $ user = User::where ('email ' , 'emailtest@example.com ' )->firstOrFail ();
83+
84+ $ this ->browse (function (Browser $ browser ) use ($ user ): void {
85+ $ browser ->logout ()
86+ ->loginAs ($ user )
87+ ->visit ('/profile ' )
88+
89+ ->assertInputValue ('@fname-input ' , 'first name here ' )
90+ ->clear ('@fname-input ' )
91+ ->type ('@fname-input ' , 'admin ' )
92+ ->assertInputValue ('@lname-input ' , 'last name here ' )
93+ ->clear ('@lname-input ' )
94+ ->type ('@lname-input ' , 'admin ' )
95+ ->assertInputValue ('@email-input ' , 'emailtest@example.com ' )
96+ ->clear ('@email-input ' )
97+ ->type ('@email-input ' , 'admin@example.com ' )
98+ ->assertInputValue ('@institution-input ' , 'Kitware (Test) ' )
99+ ->clear ('@institution-input ' )
100+ ->type ('@institution-input ' , 'testing ' )
101+
102+ ->click ('@update-profile-button ' )
103+ ->waitForTextIn ('#app ' , 'Your profile has been updated ' );
104+ });
105+
106+ $ user = User::where ('email ' , 'admin@example.com ' )->firstOrFail ();
107+
108+ $ this ->browse (function (Browser $ browser ) use ($ user ): void {
109+ $ browser ->logout ()
110+ ->loginAs ($ user )
111+ ->visit ('/profile ' )
112+ ->assertInputValue ('@fname-input ' , 'admin ' )
113+ ->assertInputValue ('@lname-input ' , 'admin ' )
114+ ->assertInputValue ('@email-input ' , 'admin@example.com ' )
115+ ->assertInputValue ('@institution-input ' , 'testing ' );
116+ });
117+ }
118+
119+ public function testIncorrectPasswordPreventsPasswordReset (): void
120+ {
121+ $ this ->users ['admin ' ] = $ this ->makeAdminUser ();
122+
123+ $ this ->browse (function (Browser $ browser ): void {
124+ $ browser ->loginAs ($ this ->users ['admin ' ])
125+ ->visit ('/profile ' )
126+ ->assertInputValue ('@oldpasswd-input ' , '' )
127+ ->assertInputValue ('@passwd-input ' , '' )
128+ ->assertInputValue ('@passwd2-input ' , '' )
129+
130+ ->type ('@oldpasswd-input ' , 'incorrect password ' )
131+ ->type ('@passwd-input ' , 'new password ' )
132+ ->type ('@passwd2-input ' , 'new password ' )
133+ ->click ('@update-password-button ' )
134+ ->waitForTextIn ('#app ' , 'Your old password is incorrect ' );
135+ });
136+ }
137+
138+ public function testShortPasswordPreventsPasswordReset (): void
139+ {
140+ $ password = Str::random (10 );
141+ $ this ->users ['admin ' ] = clone $ this ->makeAdminUser ();
142+ $ this ->users ['admin ' ]->password = bcrypt ($ password );
143+ $ this ->users ['admin ' ]->save ();
144+
145+ $ this ->browse (function (Browser $ browser ) use ($ password ): void {
146+ $ browser ->loginAs ($ this ->users ['admin ' ])
147+ ->visit ('/profile ' )
148+ ->assertInputValue ('@oldpasswd-input ' , '' )
149+ ->assertInputValue ('@passwd-input ' , '' )
150+ ->assertInputValue ('@passwd2-input ' , '' )
151+
152+ ->type ('@oldpasswd-input ' , $ password )
153+ ->type ('@passwd-input ' , 'a ' )
154+ ->type ('@passwd2-input ' , 'a ' )
155+ ->click ('@update-password-button ' )
156+ ->waitForTextIn ('#app ' , 'Password must be at least 5 characters ' );
157+ });
158+ }
159+
160+ public function testCanChangePassword (): void
161+ {
162+ $ password = Str::random (10 );
163+ $ this ->users ['admin ' ] = clone $ this ->makeAdminUser ();
164+ $ this ->users ['admin ' ]->password = bcrypt ($ password );
165+ $ this ->users ['admin ' ]->save ();
166+
167+ $ this ->browse (function (Browser $ browser ) use ($ password ): void {
168+ $ browser ->loginAs ($ this ->users ['admin ' ])
169+ ->visit ('/profile ' )
170+ ->assertInputValue ('@oldpasswd-input ' , '' )
171+ ->assertInputValue ('@passwd-input ' , '' )
172+ ->assertInputValue ('@passwd2-input ' , '' )
173+
174+ ->type ('@oldpasswd-input ' , $ password )
175+ ->type ('@passwd-input ' , 'new password ' )
176+ ->type ('@passwd2-input ' , 'new password ' )
177+ ->click ('@update-password-button ' )
178+ ->waitForTextIn ('#app ' , 'Your password has been updated ' );
179+ });
180+
181+ $ user = User::where ('email ' , $ this ->users ['admin ' ]->email )->firstOrFail ();
182+ $ this ->assertTrue (password_verify ('new password ' , $ user ->password ));
183+
184+ $ this ->browse (function (Browser $ browser ) use ($ user ): void {
185+ $ browser ->logout ()
186+ ->loginAs ($ user )
187+ ->visit ('/profile ' )
188+ ->assertInputValue ('@oldpasswd-input ' , '' )
189+ ->assertInputValue ('@passwd-input ' , '' )
190+ ->assertInputValue ('@passwd2-input ' , '' )
191+
192+ ->type ('@oldpasswd-input ' , 'new password ' )
193+ ->type ('@passwd-input ' , '12345 ' )
194+ ->type ('@passwd2-input ' , '12345 ' )
195+ ->click ('@update-password-button ' )
196+ ->waitForTextIn ('#app ' , 'Your password has been updated ' );
197+ });
198+
199+ $ user = User::where ('email ' , $ this ->users ['admin ' ]->email )->firstOrFail ();
200+ $ this ->assertTrue (password_verify ('12345 ' , $ user ->password ));
201+ }
202+
43203 public function testCreateFullAccessToken (): void
44204 {
45205 $ this ->users ['admin ' ] = $ this ->makeAdminUser ();
0 commit comments