X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/068a8a068c5d7c7ab98a6ee95baae8d321c3c61f..refs/pull/3918/head:/tests/Permissions/RolesTest.php diff --git a/tests/Permissions/RolesTest.php b/tests/Permissions/RolesTest.php index a24d5f8d8..88d400259 100644 --- a/tests/Permissions/RolesTest.php +++ b/tests/Permissions/RolesTest.php @@ -17,7 +17,7 @@ use Tests\TestCase; class RolesTest extends TestCase { - protected $user; + protected User $user; protected function setUp(): void { @@ -163,6 +163,29 @@ class RolesTest extends TestCase $this->assertEquals($this->user->id, $roleA->users()->first()->id); } + public function test_entity_permissions_are_removed_on_delete() + { + /** @var Role $roleA */ + $roleA = Role::query()->create(['display_name' => 'Entity Permissions Delete Test']); + $page = $this->entities->page(); + + $this->entities->setPermissions($page, ['view'], [$roleA]); + + $this->assertDatabaseHas('entity_permissions', [ + 'role_id' => $roleA->id, + 'entity_id' => $page->id, + 'entity_type' => $page->getMorphClass(), + ]); + + $this->asAdmin()->delete("/settings/roles/delete/$roleA->id"); + + $this->assertDatabaseMissing('entity_permissions', [ + 'role_id' => $roleA->id, + 'entity_id' => $page->id, + 'entity_type' => $page->getMorphClass(), + ]); + } + public function test_image_view_notice_shown_on_role_form() { /** @var Role $role */ @@ -520,8 +543,7 @@ class RolesTest extends TestCase public function test_chapter_create_all_permissions() { - /** @var Book $book */ - $book = Book::query()->first(); + $book = $this->entities->book(); $this->checkAccessPermission('chapter-create-all', [ $book->getUrl('/create-chapter'), ], [ @@ -603,10 +625,8 @@ class RolesTest extends TestCase public function test_page_create_own_permissions() { - /** @var Book $book */ - $book = Book::query()->first(); - /** @var Chapter $chapter */ - $chapter = Chapter::query()->first(); + $book = $this->entities->book(); + $chapter = $this->entities->chapter(); $entities = $this->entities->createChainBelongingToUser($this->user); $ownBook = $entities['book']; @@ -652,10 +672,8 @@ class RolesTest extends TestCase public function test_page_create_all_permissions() { - /** @var Book $book */ - $book = Book::query()->first(); - /** @var Chapter $chapter */ - $chapter = Chapter::query()->first(); + $book = $this->entities->book(); + $chapter = $this->entities->chapter(); $createUrl = $book->getUrl('/create-page'); $createUrlChapter = $chapter->getUrl('/create-page'); @@ -806,8 +824,7 @@ class RolesTest extends TestCase public function test_image_delete_own_permission() { $this->giveUserPermissions($this->user, ['image-update-all']); - /** @var Page $page */ - $page = Page::query()->first(); + $page = $this->entities->page(); $image = Image::factory()->create([ 'uploaded_to' => $page->id, 'created_by' => $this->user->id, @@ -826,8 +843,7 @@ class RolesTest extends TestCase { $this->giveUserPermissions($this->user, ['image-update-all']); $admin = $this->getAdmin(); - /** @var Page $page */ - $page = Page::query()->first(); + $page = $this->entities->page(); $image = Image::factory()->create(['uploaded_to' => $page->id, 'created_by' => $admin->id, 'updated_by' => $admin->id]); $this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertStatus(403); @@ -845,8 +861,7 @@ class RolesTest extends TestCase public function test_role_permission_removal() { // To cover issue fixed in f99c8ff99aee9beb8c692f36d4b84dc6e651e50a. - /** @var Page $page */ - $page = Page::query()->first(); + $page = $this->entities->page(); $viewerRole = Role::getRole('viewer'); $viewer = $this->getViewer(); $this->actingAs($viewer)->get($page->getUrl())->assertOk();