<?php
+namespace Tests;
+
use BookStack\Actions\Favourite;
+use BookStack\Auth\User;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page;
-use Tests\TestCase;
class FavouriteTest extends TestCase
{
]);
}
+ public function test_favourite_flow_with_own_permissions()
+ {
+ /** @var Book $book */
+ $book = Book::query()->first();
+ $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_book_chapter_shelf_pages_contain_favourite_button()
{
$entities = [
public function test_header_contains_link_to_favourites_page_when_logged_in()
{
$this->setSettings(['app-public' => 'true']);
- $resp = $this->get('/');
+ $resp = $this->get('/');
$this->withHtml($resp)->assertElementNotContains('header', 'My Favourites');
$resp = $this->actingAs($this->getViewer())->get('/');
$this->withHtml($resp)->assertElementContains('header a', 'My Favourites');