33namespace Tests \Auth ;
44
55use BookStack \Auth \Access \Mfa \MfaSession ;
6+ use BookStack \Auth \Role ;
67use BookStack \Auth \User ;
78use BookStack \Entities \Models \Page ;
89use BookStack \Notifications \ConfirmEmail ;
@@ -43,7 +44,10 @@ public function test_registration_showing()
4344 public function test_normal_registration ()
4445 {
4546 // Set settings and get user instance
46- $ this ->setSettings (['registration-enabled ' => 'true ' ]);
47+ /** @var Role $registrationRole */
48+ $ registrationRole = Role::query ()->first ();
49+ $ this ->setSettings (['registration-enabled ' => 'true ' , 'registration-role ' => $ registrationRole ->id ]);
50+ /** @var User $user */
4751 $ user = User::factory ()->make ();
4852
4953 // Test form and ensure user is created
@@ -57,7 +61,12 @@ public function test_normal_registration()
5761 $ resp = $ this ->get ('/ ' );
5862 $ resp ->assertOk ();
5963 $ resp ->assertSee ($ user ->name );
64+
6065 $ this ->assertDatabaseHas ('users ' , ['name ' => $ user ->name , 'email ' => $ user ->email ]);
66+
67+ $ user = User::query ()->where ('email ' , '= ' , $ user ->email )->first ();
68+ $ this ->assertEquals (1 , $ user ->roles ()->count ());
69+ $ this ->assertEquals ($ registrationRole ->id , $ user ->roles ()->first ()->id );
6170 }
6271
6372 public function test_empty_registration_redirects_back_with_errors ()
@@ -189,6 +198,14 @@ public function test_restricted_registration_with_confirmation_disabled()
189198 $ this ->assertNull (auth ()->user ());
190199 }
191200
201+ public function test_registration_role_unset_by_default ()
202+ {
203+ $ this ->assertFalse (setting ('registration-role ' ));
204+
205+ $ resp = $ this ->asAdmin ()->get ('/settings ' );
206+ $ resp ->assertElementContains ('select[name="setting-registration-role"] option[value="0"][selected] ' , '-- None -- ' );
207+ }
208+
192209 public function test_logout ()
193210 {
194211 $ this ->asAdmin ()->get ('/ ' )->assertOk ();
0 commit comments