]> BookStack Code Mirror - bookstack/commitdiff
Fixed crash on public entitiy viewing
authorDan Brown <redacted>
Tue, 1 Dec 2015 21:14:39 +0000 (21:14 +0000)
committerDan Brown <redacted>
Tue, 1 Dec 2015 21:14:39 +0000 (21:14 +0000)
app/Services/ViewService.php
tests/PublicViewTest.php [new file with mode: 0644]

index 55e32fe1c89b190f962b0f57c5ab8c76e09fdf77..475500927091bd469e8d4744c47fd5db13be4212 100644 (file)
@@ -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);
 
diff --git a/tests/PublicViewTest.php b/tests/PublicViewTest.php
new file mode 100644 (file)
index 0000000..b5141f0
--- /dev/null
@@ -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());
+    }
+
+}
\ No newline at end of file