X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/fd3929e8099d45160f242bea18556ed78ef0eaf8..refs/pull/524/head:/tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php index 3f7d846f7..81bd93ec4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,40 +1,93 @@ -actingAs($this->getAdmin()); + } /** - * Creates the application. - * - * @return \Illuminate\Foundation\Application + * Get the current admin user. + * @return mixed */ - public function createApplication() + public function getAdmin() { + if($this->admin === null) { + $adminRole = Role::getSystemRole('admin'); + $this->admin = $adminRole->users->first(); + } + return $this->admin; + } + + /** + * Set the current user context to be an editor. + * @return $this + */ + public function asEditor() { - $app = require __DIR__.'/../bootstrap/app.php'; + return $this->actingAs($this->getEditor()); + } - $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); - return $app; + /** + * 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; } - public function asAdmin() - { - if($this->admin === null) { - $this->admin = \BookStack\User::find(1); - } - return $this->actingAs($this->admin); + /** + * 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); } /** @@ -43,9 +96,9 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase */ protected function setSettings($settingsArray) { - $settings = app('BookStack\Services\SettingService'); + $settings = app(SettingService::class); foreach ($settingsArray as $key => $value) { $settings->put($key, $value); } } -} +} \ No newline at end of file