@@ -181,42 +181,62 @@ public function it_can_assign_and_remove_a_role_on_a_permission()
181
181
182
182
/** @test */
183
183
#[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 ()
185
185
{
186
186
$ this ->testUser ->assignRole ($ this ->testUserRole );
187
187
188
188
$ this ->assertTrue ($ this ->testUser ->hasRole ($ this ->testUserRole ));
189
+
190
+ $ this ->testUser ->removeRole ($ this ->testUserRole );
191
+
192
+ $ this ->assertFalse ($ this ->testUser ->hasRole ($ this ->testUserRole ));
189
193
}
190
194
191
195
/** @test */
192
196
#[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 ()
194
198
{
195
199
$ this ->testUser ->assignRole ($ this ->testUserRole ->getKey ());
196
200
197
201
$ this ->assertTrue ($ this ->testUser ->hasRole ($ this ->testUserRole ));
202
+
203
+ $ this ->testUser ->removeRole ($ this ->testUserRole ->getKey ());
204
+
205
+ $ this ->assertFalse ($ this ->testUser ->hasRole ($ this ->testUserRole ));
198
206
}
199
207
200
208
/** @test */
201
209
#[Test]
202
- public function it_can_assign_multiple_roles_at_once ()
210
+ public function it_can_assign_and_remove_multiple_roles_at_once ()
203
211
{
204
212
$ this ->testUser ->assignRole ($ this ->testUserRole ->getKey (), 'testRole2 ' );
205
213
206
214
$ this ->assertTrue ($ this ->testUser ->hasRole ('testRole ' ));
207
215
208
216
$ 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 ' ));
209
223
}
210
224
211
225
/** @test */
212
226
#[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 ()
214
228
{
215
229
$ this ->testUser ->assignRole ([$ this ->testUserRole ->getKey (), 'testRole2 ' ]);
216
230
217
231
$ this ->assertTrue ($ this ->testUser ->hasRole ('testRole ' ));
218
232
219
233
$ 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 ' ));
220
240
}
221
241
222
242
/** @test */
@@ -973,14 +993,19 @@ public function it_fires_an_event_when_a_role_is_removed()
973
993
Event::fake ();
974
994
app ('config ' )->set ('permission.events_enabled ' , true );
975
995
976
- $ this ->testUser ->assignRole ('testRole ' );
996
+ $ this ->testUser ->assignRole ('testRole ' , ' testRole2 ' );
977
997
978
- $ this ->testUser ->removeRole ('testRole ' );
998
+ $ this ->testUser ->removeRole ('testRole ' , ' testRole2 ' );
979
999
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 ) {
981
1005
return $ event ->model instanceof User
982
1006
&& ! $ event ->model ->hasRole ('testRole ' )
983
- && $ event ->rolesOrIds ->name === 'testRole ' ;
1007
+ && ! $ event ->model ->hasRole ('testRole2 ' )
1008
+ && $ event ->rolesOrIds === $ roleIds ;
984
1009
});
985
1010
}
986
1011
0 commit comments