5 use BookStack\Repos\EntityRepo;
7 use BookStack\Services\SettingService;
8 use Illuminate\Foundation\Testing\DatabaseTransactions;
9 use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
11 abstract class TestCase extends BaseTestCase
13 use CreatesApplication;
14 use DatabaseTransactions;
20 * Set the current user context to be an admin.
23 public function asAdmin()
25 return $this->actingAs($this->getAdmin());
29 * Get the current admin user.
32 public function getAdmin() {
33 if($this->admin === null) {
34 $adminRole = Role::getSystemRole('admin');
35 $this->admin = $adminRole->users->first();
41 * Set the current user context to be an editor.
44 public function asEditor()
46 return $this->actingAs($this->getEditor());
54 public function getEditor() {
55 if($this->editor === null) {
56 $editorRole = Role::getRole('editor');
57 $this->editor = $editorRole->users->first();
63 * Create and return a new book.
67 public function newBook($input = ['name' => 'test book', 'description' => 'My new test book']) {
68 return $this->app[EntityRepo::class]->createFromInput('book', $input, false);
72 * Create and return a new test chapter
77 public function newChapter($input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book) {
78 return $this->app[EntityRepo::class]->createFromInput('chapter', $input, $book);
82 * Create and return a new test page
86 public function newPage($input = ['name' => 'test page', 'html' => 'My new test page']) {
87 $book = Book::first();
88 $entityRepo = $this->app[EntityRepo::class];
89 $draftPage = $entityRepo->getDraftPage($book);
90 return $entityRepo->publishPageDraft($draftPage, $input);
94 * Quickly sets an array of settings.
95 * @param $settingsArray
97 protected function setSettings($settingsArray)
99 $settings = app(SettingService::class);
100 foreach ($settingsArray as $key => $value) {
101 $settings->put($key, $value);