X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/88049476fe496de3a3b767a4305d985f78a96db8..refs/pull/325/head:/tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php index 67a18777a..d64aef3db 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,39 +1,56 @@ -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; + } + + /** + * 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); } -} +} \ No newline at end of file