Skip to content

Commit d38d1e0

Browse files
committed
Merge branch 'master' into 8.x
2 parents cd995c9 + 7cdd879 commit d38d1e0

4 files changed

Lines changed: 42 additions & 6 deletions

File tree

‎src/Traits/HasRolesAndPermissions.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ trait HasRolesAndPermissions
2727
* remove the many-to-many records when trying to delete.
2828
* Will NOT delete any records if the user model uses soft deletes.
2929
*/
30-
public static function bootLaratrustUserTrait(): void
30+
public static function bootHasRolesAndPermissions(): void
3131
{
3232
$flushCache = function ($user) {
3333
$user->flushCache();

‎tests/Checkers/Model/LaratrustModelCheckerTestCase.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ protected function setUp(): void
2222
parent::setUp();
2323

2424
$this->migrate();
25-
$this->user = User::create(['name' => 'test', 'email' => 'test@test.com']);
26-
$this->other = Other::create(['name' => 'test', 'email' => 'test@test.com']);
2725

2826
$this->app['config']->set('laratrust.use_morph_map', true);
2927
$this->app['config']->set('laratrust.user_models', [
3028
'users' => 'Laratrust\Tests\Models\User',
3129
'others' => 'Laratrust\Tests\Models\Other'
3230
]);
31+
32+
$this->user = User::create(['name' => 'test', 'email' => 'test@test.com']);
33+
$this->other = Other::create(['name' => 'test', 'email' => 'test@test.com']);
3334
}
3435

3536
public function modelDisableTheRolesAndPermissionsCachingAssertions()

‎tests/Models/Other.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
namespace Laratrust\Tests\Models;
66

7-
use Illuminate\Database\Eloquent\Model;
8-
use Laratrust\Traits\LaratrustUserTrait;
7+
use Illuminate\Foundation\Auth\User as Authenticatable;
98
use Illuminate\Database\Eloquent\SoftDeletes;
109
use Laratrust\Contracts\LaratrustUser;
1110
use Laratrust\Traits\HasRolesAndPermissions;
1211

13-
class Other extends Model implements LaratrustUser
12+
class Other extends Authenticatable implements LaratrustUser
1413
{
1514
use HasRolesAndPermissions;
1615
use SoftDeletes;

‎tests/UserTest.php‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,42 @@ public function testAllPermissionsScopedOnTeams()
646646

647647
}
648648

649+
public function testManyToManyRecordsAreRemoved()
650+
{
651+
/*
652+
|------------------------------------------------------------
653+
| Set
654+
|------------------------------------------------------------
655+
*/
656+
$roleA = Role::create(['name' => 'role_a']);
657+
$permissionA = Permission::create(['name' => 'permission_a']);
658+
659+
$teamA = Team::create(['name' => 'team_a']);
660+
661+
$this->user->addRole($roleA, $teamA);
662+
$this->user->givePermission($permissionA);
663+
664+
// force-deleting because the user model has soft-deletes enabled
665+
$this->user->forceDelete();
666+
667+
/*
668+
|------------------------------------------------------------
669+
| Assertion
670+
|------------------------------------------------------------
671+
*/
672+
$this->assertModelMissing($this->user);
673+
674+
$this->assertDatabaseMissing(
675+
$this->app['config']->get('laratrust.tables.role_user'),
676+
['user_id' => $this->user->id]
677+
);
678+
679+
$this->assertDatabaseMissing(
680+
$this->app['config']->get('laratrust.tables.permission_user'),
681+
['user_id' => $this->user->id]
682+
);
683+
}
684+
649685
protected function assertWasAttached($objectName, $result)
650686
{
651687
$relationship = \Illuminate\Support\Str::plural($objectName);

0 commit comments

Comments
 (0)