X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/7c9937e9240b9656fe865de85a89c97b734656ab..refs/pull/966/head:/tests/BrowserKitTest.php diff --git a/tests/BrowserKitTest.php b/tests/BrowserKitTest.php index 8e02cb5f1..86f61a764 100644 --- a/tests/BrowserKitTest.php +++ b/tests/BrowserKitTest.php @@ -1,6 +1,8 @@ actingAs($this->getAdmin()); - } - - /** - * Get the current admin user. - * @return mixed - */ - public function getAdmin() { - if($this->admin === null) { - $adminRole = Role::getSystemRole('admin'); - $this->admin = $adminRole->users->first(); - } - return $this->admin; - } - - /** - * Set the current editor context to be an editor. - * @return $this - */ - public function asEditor() - { - if ($this->editor === null) { - $this->editor = $this->getEditor(); - } - return $this->actingAs($this->editor); - } /** * Get a user that's not a system user such as the guest user. @@ -99,11 +71,9 @@ abstract class BrowserKitTest extends TestCase { if ($updaterUser === false) $updaterUser = $creatorUser; $book = factory(\BookStack\Book::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]); - $chapter = factory(\BookStack\Chapter::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]); - $page = factory(\BookStack\Page::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id, 'book_id' => $book->id]); - $book->chapters()->saveMany([$chapter]); - $chapter->pages()->saveMany([$page]); - $restrictionService = $this->app[\BookStack\Services\PermissionService::class]; + $chapter = factory(\BookStack\Chapter::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id, 'book_id' => $book->id]); + $page = factory(\BookStack\Page::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id, 'book_id' => $book->id, 'chapter_id' => $chapter->id]); + $restrictionService = $this->app[PermissionService::class]; $restrictionService->buildJointPermissionsForEntity($book); return [ 'book' => $book, @@ -113,18 +83,16 @@ abstract class BrowserKitTest extends TestCase } /** - * Quick way to create a new user - * @param array $attributes - * @return mixed + * Helper for updating entity permissions. + * @param Entity $entity */ - protected function getEditor($attributes = []) + protected function updateEntityPermissions(Entity $entity) { - $user = factory(\BookStack\User::class)->create($attributes); - $role = Role::getRole('editor'); - $user->attachRole($role);; - return $user; + $restrictionService = $this->app[PermissionService::class]; + $restrictionService->buildJointPermissionsForEntity($entity); } + /** * Quick way to create a new user without any permissions * @param array $attributes