@@ -181,42 +181,62 @@ public function it_can_assign_and_remove_a_role_on_a_permission()
181181
182182 /** @test */
183183 #[Test]
184- public function it_can_assign_a_role_using_an_object ()
184+ public function it_can_assign_and_remove_a_role_using_an_object ()
185185 {
186186 $ this ->testUser ->assignRole ($ this ->testUserRole );
187187
188188 $ this ->assertTrue ($ this ->testUser ->hasRole ($ this ->testUserRole ));
189+
190+ $ this ->testUser ->removeRole ($ this ->testUserRole );
191+
192+ $ this ->assertFalse ($ this ->testUser ->hasRole ($ this ->testUserRole ));
189193 }
190194
191195 /** @test */
192196 #[Test]
193- public function it_can_assign_a_role_using_an_id ()
197+ public function it_can_assign_and_remove_a_role_using_an_id ()
194198 {
195199 $ this ->testUser ->assignRole ($ this ->testUserRole ->getKey ());
196200
197201 $ this ->assertTrue ($ this ->testUser ->hasRole ($ this ->testUserRole ));
202+
203+ $ this ->testUser ->removeRole ($ this ->testUserRole ->getKey ());
204+
205+ $ this ->assertFalse ($ this ->testUser ->hasRole ($ this ->testUserRole ));
198206 }
199207
200208 /** @test */
201209 #[Test]
202- public function it_can_assign_multiple_roles_at_once ()
210+ public function it_can_assign_and_remove_multiple_roles_at_once ()
203211 {
204212 $ this ->testUser ->assignRole ($ this ->testUserRole ->getKey (), 'testRole2 ' );
205213
206214 $ this ->assertTrue ($ this ->testUser ->hasRole ('testRole ' ));
207215
208216 $ this ->assertTrue ($ this ->testUser ->hasRole ('testRole2 ' ));
217+
218+ $ this ->testUser ->removeRole ($ this ->testUserRole ->getKey (), 'testRole2 ' );
219+
220+ $ this ->assertFalse ($ this ->testUser ->hasRole ('testRole ' ));
221+
222+ $ this ->assertFalse ($ this ->testUser ->hasRole ('testRole2 ' ));
209223 }
210224
211225 /** @test */
212226 #[Test]
213- public function it_can_assign_multiple_roles_using_an_array ()
227+ public function it_can_assign_and_remove_multiple_roles_using_an_array ()
214228 {
215229 $ this ->testUser ->assignRole ([$ this ->testUserRole ->getKey (), 'testRole2 ' ]);
216230
217231 $ this ->assertTrue ($ this ->testUser ->hasRole ('testRole ' ));
218232
219233 $ this ->assertTrue ($ this ->testUser ->hasRole ('testRole2 ' ));
234+
235+ $ this ->testUser ->removeRole ([$ this ->testUserRole ->getKey (), 'testRole2 ' ]);
236+
237+ $ this ->assertFalse ($ this ->testUser ->hasRole ('testRole ' ));
238+
239+ $ this ->assertFalse ($ this ->testUser ->hasRole ('testRole2 ' ));
220240 }
221241
222242 /** @test */
@@ -973,14 +993,19 @@ public function it_fires_an_event_when_a_role_is_removed()
973993 Event::fake ();
974994 app ('config ' )->set ('permission.events_enabled ' , true );
975995
976- $ this ->testUser ->assignRole ('testRole ' );
996+ $ this ->testUser ->assignRole ('testRole ' , ' testRole2 ' );
977997
978- $ this ->testUser ->removeRole ('testRole ' );
998+ $ this ->testUser ->removeRole ('testRole ' , ' testRole2 ' );
979999
980- Event::assertDispatched (RoleDetached::class, function ($ event ) {
1000+ $ roleIds = app (Role::class)::whereIn ('name ' , ['testRole ' , 'testRole2 ' ])
1001+ ->pluck ($ this ->testUserRole ->getKeyName ())
1002+ ->toArray ();
1003+
1004+ Event::assertDispatched (RoleDetached::class, function ($ event ) use ($ roleIds ) {
9811005 return $ event ->model instanceof User
9821006 && ! $ event ->model ->hasRole ('testRole ' )
983- && $ event ->rolesOrIds ->name === 'testRole ' ;
1007+ && ! $ event ->model ->hasRole ('testRole2 ' )
1008+ && $ event ->rolesOrIds === $ roleIds ;
9841009 });
9851010 }
9861011
0 commit comments