5 use BookStack\Repos\EntityRepo;
7 use Illuminate\Foundation\Testing\DatabaseTransactions;
8 use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
10 abstract class TestCase extends BaseTestCase
12 use CreatesApplication;
13 use DatabaseTransactions;
18 * Set the current user context to be an admin.
21 public function asAdmin()
23 return $this->actingAs($this->getAdmin());
27 * Get the current admin user.
30 public function getAdmin() {
31 if($this->admin === null) {
32 $adminRole = Role::getSystemRole('admin');
33 $this->admin = $adminRole->users->first();
39 * Create and return a new book.
43 public function newBook($input = ['name' => 'test book', 'description' => 'My new test book']) {
44 return $this->app[EntityRepo::class]->createFromInput('book', $input, false);
48 * Create and return a new test chapter
53 public function newChapter($input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book) {
54 return $this->app[EntityRepo::class]->createFromInput('chapter', $input, $book);