X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/387047f26207e97ab05c315e65bcc961ea71880a..refs/pull/1756/head:/tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php index f3f36ca1c..939a1a91e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,9 +1,5 @@ actingAs($this->getAdmin()); - } + protected $baseUrl = 'http://localhost'; /** - * Get the current admin user. - * @return mixed + * Assert a permission error has occurred. + * @param TestResponse $response + * @return TestCase */ - public function getAdmin() { - if($this->admin === null) { - $adminRole = Role::getSystemRole('admin'); - $this->admin = $adminRole->users->first(); - } - return $this->admin; + protected function assertPermissionError(TestResponse $response) + { + $response->assertRedirect('/'); + $this->assertSessionHas('error'); + session()->remove('error'); + return $this; } /** - * Set the current user context to be an editor. + * Assert the session contains a specific entry. + * @param string $key * @return $this */ - public function asEditor() + protected function assertSessionHas(string $key) { - 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; + $this->assertTrue(session()->has($key), "Session does not contain a [{$key}] entry"); + return $this; } /** - * Create and return a new book. - * @param array $input - * @return Book + * Override of the get method so we can get visibility of custom TestResponse methods. + * @param string $uri + * @param array $headers + * @return TestResponse */ - public function newBook($input = ['name' => 'test book', 'description' => 'My new test book']) { - return $this->app[EntityRepo::class]->createFromInput('book', $input, false); + public function get($uri, array $headers = []) + { + return parent::get($uri, $headers); } /** - * Create and return a new test chapter - * @param array $input - * @param Book $book - * @return Chapter + * Create the test response instance from the given response. + * + * @param \Illuminate\Http\Response $response + * @return TestResponse */ - public function newChapter($input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book) { - return $this->app[EntityRepo::class]->createFromInput('chapter', $input, $book); + protected function createTestResponse($response) + { + return TestResponse::fromBaseResponse($response); } } \ No newline at end of file