File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -450,6 +450,7 @@ public function forgetWildcardPermissionIndex(): void
450
450
public function syncPermissions (...$ permissions )
451
451
{
452
452
if ($ this ->getModel ()->exists ) {
453
+ $ this ->collectPermissions ($ permissions );
453
454
$ this ->permissions ()->detach ();
454
455
$ this ->setRelation ('permissions ' , collect ());
455
456
}
Original file line number Diff line number Diff line change @@ -611,6 +611,23 @@ public function it_can_avoid_sync_duplicated_permissions()
611
611
$ this ->assertTrue ($ this ->testUser ->hasDirectPermission ('edit-blog ' ));
612
612
}
613
613
614
+ /** @test */
615
+ #[Test]
616
+ public function it_can_avoid_detach_on_permission_that_does_not_exist_sync ()
617
+ {
618
+ $ this ->testUser ->syncPermissions ('edit-articles ' );
619
+
620
+ try {
621
+ $ this ->testUser ->syncPermissions ('permission-does-not-exist ' );
622
+ $ this ->fail ('Expected PermissionDoesNotExist exception was not thrown. ' );
623
+ } catch (PermissionDoesNotExist $ e ){
624
+ //
625
+ }
626
+
627
+ $ this ->assertTrue ($ this ->testUser ->hasDirectPermission ('edit-articles ' ));
628
+ $ this ->assertFalse ($ this ->testUser ->checkPermissionTo ('permission-does-not-exist ' ));
629
+ }
630
+
614
631
/** @test */
615
632
#[Test]
616
633
public function it_can_sync_multiple_permissions_by_id ()
Original file line number Diff line number Diff line change @@ -318,6 +318,23 @@ public function it_can_avoid_sync_duplicated_roles()
318
318
$ this ->assertTrue ($ this ->testUser ->hasRole ('testRole2 ' ));
319
319
}
320
320
321
+ /** @test */
322
+ #[Test]
323
+ public function it_can_avoid_detach_on_role_that_does_not_exist_sync ()
324
+ {
325
+ $ this ->testUser ->syncRoles ('testRole ' );
326
+
327
+ try {
328
+ $ this ->testUser ->syncRoles ('role-does-not-exist ' );
329
+ $ this ->fail ('Expected RoleDoesNotExist exception was not thrown. ' );
330
+ } catch (RoleDoesNotExist $ e ){
331
+ //
332
+ }
333
+
334
+ $ this ->assertTrue ($ this ->testUser ->hasRole ('testRole ' ));
335
+ $ this ->assertFalse ($ this ->testUser ->hasRole ('role-does-not-exist ' ));
336
+ }
337
+
321
338
/** @test */
322
339
#[Test]
323
340
public function it_can_sync_multiple_roles ()
You can’t perform that action at this time.
0 commit comments