X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/713827f941497dc7720fbdf7815840e7b11c8a22..refs/pull/635/head:/tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php index d48bb3ef2..81bd93ec4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,39 +1,104 @@ -actingAs($this->getAdmin()); + } + /** - * The base URL to use while testing the application. - * - * @var string + * Get the current admin user. + * @return mixed */ - protected $baseUrl = 'http://localhost'; - private $admin; + public function getAdmin() { + if($this->admin === null) { + $adminRole = Role::getSystemRole('admin'); + $this->admin = $adminRole->users->first(); + } + return $this->admin; + } /** - * Creates the application. - * - * @return \Illuminate\Foundation\Application + * Set the current user context to be an editor. + * @return $this */ - public function createApplication() + 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() + /** + * 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); + } + + /** + * Quickly sets an array of settings. + * @param $settingsArray + */ + protected function setSettings($settingsArray) { - if($this->admin === null) { - $this->admin = \Oxbow\User::find(1); + $settings = app(SettingService::class); + foreach ($settingsArray as $key => $value) { + $settings->put($key, $value); } - return $this->actingAs($this->admin); } -} +} \ No newline at end of file