X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/ee24635e06a8c01d751f80caba47c57f76e8989d..refs/pull/3918/head:/tests/FavouriteTest.php diff --git a/tests/FavouriteTest.php b/tests/FavouriteTest.php index 017dd889f..456f2213c 100644 --- a/tests/FavouriteTest.php +++ b/tests/FavouriteTest.php @@ -1,17 +1,15 @@ first(); + $page = $this->entities->page(); $editor = $this->getEditor(); $resp = $this->actingAs($editor)->get($page->getUrl()); @@ -34,7 +32,7 @@ class FavouriteTest extends TestCase public function test_page_remove_favourite_flow() { - $page = Page::query()->first(); + $page = $this->entities->page(); $editor = $this->getEditor(); Favourite::query()->forceCreate([ 'user_id' => $editor->id, @@ -58,16 +56,34 @@ class FavouriteTest extends TestCase ]); } - public function test_book_chapter_shelf_pages_contain_favourite_button() + public function test_favourite_flow_with_own_permissions() + { + $book = $this->entities->book(); + $user = User::factory()->create(); + $book->owned_by = $user->id; + $book->save(); + + $this->giveUserPermissions($user, ['book-view-own']); + + $this->actingAs($user)->get($book->getUrl()); + $resp = $this->post('/favourites/add', [ + 'type' => get_class($book), + 'id' => $book->id, + ]); + $resp->assertRedirect($book->getUrl()); + + $this->assertDatabaseHas('favourites', [ + 'user_id' => $user->id, + 'favouritable_type' => $book->getMorphClass(), + 'favouritable_id' => $book->id, + ]); + } + + public function test_each_entity_type_shows_favourite_button() { - $entities = [ - Bookshelf::query()->first(), - Book::query()->first(), - Chapter::query()->first(), - ]; $this->actingAs($this->getEditor()); - foreach ($entities as $entity) { + foreach ($this->entities->all() as $entity) { $resp = $this->get($entity->getUrl()); $this->withHtml($resp)->assertElementExists('form[method="POST"][action$="/favourites/add"]'); } @@ -89,8 +105,7 @@ class FavouriteTest extends TestCase $resp = $this->actingAs($editor)->get('/'); $this->withHtml($resp)->assertElementNotExists('#top-favourites'); - /** @var Page $page */ - $page = Page::query()->first(); + $page = $this->entities->page(); $page->favourites()->save((new Favourite())->forceFill(['user_id' => $editor->id])); $resp = $this->get('/'); @@ -100,8 +115,7 @@ class FavouriteTest extends TestCase public function test_favourites_list_page_shows_favourites_and_has_working_pagination() { - /** @var Page $page */ - $page = Page::query()->first(); + $page = $this->entities->page(); $editor = $this->getEditor(); $resp = $this->actingAs($editor)->get('/favourites');