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;
19 * Set the current user context to be an admin.
22 public function asAdmin()
24 return $this->actingAs($this->getAdmin());
28 * Get the current admin user.
31 public function getAdmin() {
32 if($this->admin === null) {
33 $adminRole = Role::getSystemRole('admin');
34 $this->admin = $adminRole->users->first();
40 * Set the current user context to be an editor.
43 public function asEditor()
45 return $this->actingAs($this->getEditor());
53 public function getEditor() {
54 if($this->editor === null) {
55 $editorRole = Role::getRole('editor');
56 $this->editor = $editorRole->users->first();
62 * Create and return a new book.
66 public function newBook($input = ['name' => 'test book', 'description' => 'My new test book']) {
67 return $this->app[EntityRepo::class]->createFromInput('book', $input, false);
71 * Create and return a new test chapter
76 public function newChapter($input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book) {
77 return $this->app[EntityRepo::class]->createFromInput('chapter', $input, $book);
81 * Create and return a new test page
85 public function newPage($input = ['name' => 'test page', 'html' => 'My new test page']) {
86 $book = Book::first();
87 $entityRepo = $this->app[EntityRepo::class];
88 $draftPage = $entityRepo->getDraftPage($book);
89 return $entityRepo->publishPageDraft($draftPage, $input);