X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/fd3929e8099d45160f242bea18556ed78ef0eaf8..refs/pull/479/head:/tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php index 3f7d846f7..b008080d9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,51 +1,91 @@ -make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); - - return $app; + return $this->actingAs($this->getAdmin()); } - public function asAdmin() - { + /** + * Get the current admin user. + * @return mixed + */ + public function getAdmin() { if($this->admin === null) { - $this->admin = \BookStack\User::find(1); + $adminRole = Role::getSystemRole('admin'); + $this->admin = $adminRole->users->first(); } - return $this->actingAs($this->admin); + return $this->admin; } /** - * Quickly sets an array of settings. - * @param $settingsArray + * Set the current user context to be an editor. + * @return $this */ - protected function setSettings($settingsArray) + public function asEditor() { - $settings = app('BookStack\Services\SettingService'); - foreach ($settingsArray as $key => $value) { - $settings->put($key, $value); + return $this->actingAs($this->getEditor()); + } + + + /** + * Get a editor user. + * @return mixed + */ + public function getEditor() { + if($this->editor === null) { + $editorRole = Role::getRole('editor'); + $this->editor = $editorRole->users->first(); } + return $this->editor; + } + + /** + * Create and return a new book. + * @param array $input + * @return Book + */ + public function newBook($input = ['name' => 'test book', 'description' => 'My new test book']) { + return $this->app[EntityRepo::class]->createFromInput('book', $input, false); + } + + /** + * Create and return a new test chapter + * @param array $input + * @param Book $book + * @return Chapter + */ + public function newChapter($input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book) { + return $this->app[EntityRepo::class]->createFromInput('chapter', $input, $book); + } + + /** + * Create and return a new test page + * @param array $input + * @return Chapter + */ + public function newPage($input = ['name' => 'test page', 'html' => 'My new test page']) { + $book = Book::first(); + $entityRepo = $this->app[EntityRepo::class]; + $draftPage = $entityRepo->getDraftPage($book); + return $entityRepo->publishPageDraft($draftPage, $input); } -} +} \ No newline at end of file