Showing
2 changed files
with
43 additions
and
0 deletions
| ... | @@ -27,6 +27,7 @@ class ViewService | ... | @@ -27,6 +27,7 @@ class ViewService |
| 27 | */ | 27 | */ |
| 28 | public function add(Entity $entity) | 28 | public function add(Entity $entity) |
| 29 | { | 29 | { |
| 30 | + if($this->user === null) return 0; | ||
| 30 | $view = $entity->views()->where('user_id', '=', $this->user->id)->first(); | 31 | $view = $entity->views()->where('user_id', '=', $this->user->id)->first(); |
| 31 | // Add view if model exists | 32 | // Add view if model exists |
| 32 | if ($view) { | 33 | if ($view) { |
| ... | @@ -52,6 +53,7 @@ class ViewService | ... | @@ -52,6 +53,7 @@ class ViewService |
| 52 | */ | 53 | */ |
| 53 | public function getUserRecentlyViewed($count = 10, $page = 0, $filterModel = false) | 54 | public function getUserRecentlyViewed($count = 10, $page = 0, $filterModel = false) |
| 54 | { | 55 | { |
| 56 | + if($this->user === null) return collect(); | ||
| 55 | $skipCount = $count * $page; | 57 | $skipCount = $count * $page; |
| 56 | $query = $this->view->where('user_id', '=', auth()->user()->id); | 58 | $query = $this->view->where('user_id', '=', auth()->user()->id); |
| 57 | 59 | ... | ... |
tests/PublicViewTest.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +class PublicViewTest extends TestCase | ||
| 4 | +{ | ||
| 5 | + | ||
| 6 | + public function testBooksViewable() | ||
| 7 | + { | ||
| 8 | + $this->setSettings(['app-public' => 'true']); | ||
| 9 | + $books = \BookStack\Book::orderBy('name', 'asc')->take(10)->get(); | ||
| 10 | + $bookToVisit = $books[1]; | ||
| 11 | + | ||
| 12 | + // Check books index page is showing | ||
| 13 | + $this->visit('/books') | ||
| 14 | + ->seeStatusCode(200) | ||
| 15 | + ->see($books[0]->name) | ||
| 16 | + // Check indavidual book page is showing and it's child contents are visible. | ||
| 17 | + ->click($bookToVisit->name) | ||
| 18 | + ->seePageIs($bookToVisit->getUrl()) | ||
| 19 | + ->see($bookToVisit->name) | ||
| 20 | + ->see($bookToVisit->chapters()->first()->name); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public function testChaptersViewable() | ||
| 24 | + { | ||
| 25 | + $this->setSettings(['app-public' => 'true']); | ||
| 26 | + $chapterToVisit = \BookStack\Chapter::first(); | ||
| 27 | + $pageToVisit = $chapterToVisit->pages()->first(); | ||
| 28 | + | ||
| 29 | + // Check chapters index page is showing | ||
| 30 | + $this->visit($chapterToVisit->getUrl()) | ||
| 31 | + ->seeStatusCode(200) | ||
| 32 | + ->see($chapterToVisit->name) | ||
| 33 | + // Check indavidual chapter page is showing and it's child contents are visible. | ||
| 34 | + ->see($pageToVisit->name) | ||
| 35 | + ->click($pageToVisit->name) | ||
| 36 | + ->see($chapterToVisit->book->name) | ||
| 37 | + ->see($chapterToVisit->name) | ||
| 38 | + ->seePageIs($pageToVisit->getUrl()); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment