]> BookStack Code Mirror - bookstack/blobdiff - tests/FavouriteTest.php
Added "page_include_parse" theme event
[bookstack] / tests / FavouriteTest.php
index 6a5c82eab58f64c3edfe2e4e55a0eb4e16aef2e7..de36c77e1e0117b6f0691ab44abcc0069380963e 100644 (file)
@@ -1,11 +1,13 @@
 <?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
 {
@@ -58,6 +60,30 @@ 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 = [
@@ -76,7 +102,7 @@ class FavouriteTest extends TestCase
     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');