mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-23 19:32:29 +01:00
Fixed crash on public entitiy viewing
This commit is contained in:
parent
9969698783
commit
5e21ecc526
@ -27,6 +27,7 @@ class ViewService
|
||||
*/
|
||||
public function add(Entity $entity)
|
||||
{
|
||||
if($this->user === null) return 0;
|
||||
$view = $entity->views()->where('user_id', '=', $this->user->id)->first();
|
||||
// Add view if model exists
|
||||
if ($view) {
|
||||
@ -52,6 +53,7 @@ class ViewService
|
||||
*/
|
||||
public function getUserRecentlyViewed($count = 10, $page = 0, $filterModel = false)
|
||||
{
|
||||
if($this->user === null) return collect();
|
||||
$skipCount = $count * $page;
|
||||
$query = $this->view->where('user_id', '=', auth()->user()->id);
|
||||
|
||||
|
41
tests/PublicViewTest.php
Normal file
41
tests/PublicViewTest.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
class PublicViewTest extends TestCase
|
||||
{
|
||||
|
||||
public function testBooksViewable()
|
||||
{
|
||||
$this->setSettings(['app-public' => 'true']);
|
||||
$books = \BookStack\Book::orderBy('name', 'asc')->take(10)->get();
|
||||
$bookToVisit = $books[1];
|
||||
|
||||
// Check books index page is showing
|
||||
$this->visit('/books')
|
||||
->seeStatusCode(200)
|
||||
->see($books[0]->name)
|
||||
// Check indavidual book page is showing and it's child contents are visible.
|
||||
->click($bookToVisit->name)
|
||||
->seePageIs($bookToVisit->getUrl())
|
||||
->see($bookToVisit->name)
|
||||
->see($bookToVisit->chapters()->first()->name);
|
||||
}
|
||||
|
||||
public function testChaptersViewable()
|
||||
{
|
||||
$this->setSettings(['app-public' => 'true']);
|
||||
$chapterToVisit = \BookStack\Chapter::first();
|
||||
$pageToVisit = $chapterToVisit->pages()->first();
|
||||
|
||||
// Check chapters index page is showing
|
||||
$this->visit($chapterToVisit->getUrl())
|
||||
->seeStatusCode(200)
|
||||
->see($chapterToVisit->name)
|
||||
// Check indavidual chapter page is showing and it's child contents are visible.
|
||||
->see($pageToVisit->name)
|
||||
->click($pageToVisit->name)
|
||||
->see($chapterToVisit->book->name)
|
||||
->see($chapterToVisit->name)
|
||||
->seePageIs($pageToVisit->getUrl());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user