X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/b56f7355aa3a44c8529073fc2a3e760d0404f2ad..refs/pull/4467/head:/tests/Entity/ChapterTest.php diff --git a/tests/Entity/ChapterTest.php b/tests/Entity/ChapterTest.php index fc8adb01d..7fa32c252 100644 --- a/tests/Entity/ChapterTest.php +++ b/tests/Entity/ChapterTest.php @@ -96,15 +96,12 @@ class ChapterTest extends TestCase public function test_copy_does_not_copy_non_visible_pages() { - /** @var Chapter $chapter */ - $chapter = Chapter::query()->whereHas('pages')->first(); + $chapter = $this->entities->chapterHasPages(); // Hide pages to all non-admin roles /** @var Page $page */ foreach ($chapter->pages as $page) { - $page->restricted = true; - $page->save(); - $this->entities->regenPermissions($page); + $this->permissions->setEntityPermissions($page, [], []); } $this->asEditor()->post($chapter->getUrl('/copy'), [ @@ -118,10 +115,9 @@ class ChapterTest extends TestCase public function test_copy_does_not_copy_pages_if_user_cant_page_create() { - /** @var Chapter $chapter */ - $chapter = Chapter::query()->whereHas('pages')->first(); - $viewer = $this->getViewer(); - $this->giveUserPermissions($viewer, ['chapter-create-all']); + $chapter = $this->entities->chapterHasPages(); + $viewer = $this->users->viewer(); + $this->permissions->grantUserRolePermissions($viewer, ['chapter-create-all']); // Lacking permission results in no copied pages $this->actingAs($viewer)->post($chapter->getUrl('/copy'), [ @@ -132,7 +128,7 @@ class ChapterTest extends TestCase $newChapter = Chapter::query()->where('name', '=', 'My copied chapter')->first(); $this->assertEquals(0, $newChapter->pages()->count()); - $this->giveUserPermissions($viewer, ['page-create-all']); + $this->permissions->grantUserRolePermissions($viewer, ['page-create-all']); // Having permission rules in copied pages $this->actingAs($viewer)->post($chapter->getUrl('/copy'), [ @@ -148,7 +144,7 @@ class ChapterTest extends TestCase { $chapter = $this->entities->chapter(); - $resp = $this->actingAs($this->getViewer())->get($chapter->getUrl()); + $resp = $this->actingAs($this->users->viewer())->get($chapter->getUrl()); $this->withHtml($resp)->assertLinkNotExists($chapter->book->getUrl('sort')); $resp = $this->asEditor()->get($chapter->getUrl());