X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/756ee0b172034de7a36d7307b0b90afb26f81665..refs/pull/806/head:/tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php index 81bd93ec4..e0f160eed 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,104 +1,28 @@ actingAs($this->getAdmin()); - } - - /** - * Get the current admin user. - * @return mixed - */ - public function getAdmin() { - if($this->admin === null) { - $adminRole = Role::getSystemRole('admin'); - $this->admin = $adminRole->users->first(); - } - return $this->admin; - } - - /** - * Set the current user context to be an editor. - * @return $this - */ - public function asEditor() - { - return $this->actingAs($this->getEditor()); - } - - - /** - * Get a editor user. - * @return mixed - */ - public function getEditor() { - if($this->editor === null) { - $editorRole = Role::getRole('editor'); - $this->editor = $editorRole->users->first(); - } - return $this->editor; - } - + use SharedTestHelpers; /** - * Create and return a new book. - * @param array $input - * @return Book + * The base URL to use while testing the application. + * @var string */ - 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); - } - - /** - * Create and return a new test page - * @param array $input - * @return Chapter - */ - public function newPage($input = ['name' => 'test page', 'html' => 'My new test page']) { - $book = Book::first(); - $entityRepo = $this->app[EntityRepo::class]; - $draftPage = $entityRepo->getDraftPage($book); - return $entityRepo->publishPageDraft($draftPage, $input); - } + protected $baseUrl = 'http://localhost'; /** - * Quickly sets an array of settings. - * @param $settingsArray + * Assert a permission error has occurred. + * @param TestResponse $response */ - protected function setSettings($settingsArray) + protected function assertPermissionError(TestResponse $response) { - $settings = app(SettingService::class); - foreach ($settingsArray as $key => $value) { - $settings->put($key, $value); - } + $response->assertRedirect('/'); + $this->assertTrue(session()->has('error')); + session()->remove('error'); } } \ No newline at end of file