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 * The base URL to use while testing the application.
23 protected $baseUrl = 'http://localhost';
26 * Set the current user context to be an admin.
29 public function asAdmin()
31 return $this->actingAs($this->getAdmin());
35 * Get the current admin user.
38 public function getAdmin() {
39 if($this->admin === null) {
40 $adminRole = Role::getSystemRole('admin');
41 $this->admin = $adminRole->users->first();
47 * Set the current user context to be an editor.
50 public function asEditor()
52 return $this->actingAs($this->getEditor());
60 public function getEditor() {
61 if($this->editor === null) {
62 $editorRole = Role::getRole('editor');
63 $this->editor = $editorRole->users->first();
69 * Create and return a new book.
73 public function newBook($input = ['name' => 'test book', 'description' => 'My new test book']) {
74 return $this->app[EntityRepo::class]->createFromInput('book', $input, false);
78 * Create and return a new test chapter
83 public function newChapter($input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book) {
84 return $this->app[EntityRepo::class]->createFromInput('chapter', $input, $book);
88 * Create and return a new test page
92 public function newPage($input = ['name' => 'test page', 'html' => 'My new test page']) {
93 $book = Book::first();
94 $entityRepo = $this->app[EntityRepo::class];
95 $draftPage = $entityRepo->getDraftPage($book);
96 return $entityRepo->publishPageDraft($draftPage, $input);
100 * Quickly sets an array of settings.
101 * @param $settingsArray
103 protected function setSettings($settingsArray)
105 $settings = app(SettingService::class);
106 foreach ($settingsArray as $key => $value) {
107 $settings->put($key, $value);