X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/548dcd4db1754fc0f05cd578c6993b78dd279193..refs/pull/2238/head:/tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php index 5c37b6179..1f1d5ece7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,10 +1,6 @@ actingAs($this->getAdmin()); + $this->assertTrue(session()->has($key), "Session does not contain a [{$key}] entry"); + return $this; } /** - * 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 + * Override of the get method so we can get visibility of custom TestResponse methods. + * @param string $uri + * @param array $headers + * @return TestResponse */ - public function asEditor() + public function get($uri, array $headers = []) { - return $this->actingAs($this->getEditor()); + return parent::get($uri, $headers); } - /** - * Get a editor user. - * @return mixed + * Create the test response instance from the given response. + * + * @param \Illuminate\Http\Response $response + * @return TestResponse */ - public function getEditor() { - if($this->editor === null) { - $editorRole = Role::getRole('editor'); - $this->editor = $editorRole->users->first(); - } - return $this->editor; - } - - /** - * Get an instance of a user with 'viewer' permissions - * @param $attributes - * @return mixed - */ - protected function getViewer($attributes = []) + protected function createTestResponse($response) { - $user = \BookStack\Role::getRole('viewer')->users()->first(); - if (!empty($attributes)) $user->forceFill($attributes)->save(); - return $user; + return TestResponse::fromBaseResponse($response); } /** - * Create and return a new book. - * @param array $input - * @return Book + * Assert that an activity entry exists of the given key. + * Checks the activity belongs to the given entity if provided. */ - 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); - } - - /** - * Quickly sets an array of settings. - * @param $settingsArray - */ - protected function setSettings($settingsArray) + protected function assertActivityExists(string $key, Entity $entity = null) { - $settings = app(SettingService::class); - foreach ($settingsArray as $key => $value) { - $settings->put($key, $value); + $detailsToCheck = ['key' => $key]; + + if ($entity) { + $detailsToCheck['entity_type'] = $entity->getMorphClass(); + $detailsToCheck['entity_id'] = $entity->id; } + + $this->assertDatabaseHas('activities', $detailsToCheck); } } \ No newline at end of file