]> BookStack Code Mirror - bookstack/commitdiff
Added 404 page and extra tests
authorDan Brown <redacted>
Tue, 29 Sep 2015 20:25:03 +0000 (21:25 +0100)
committerDan Brown <redacted>
Tue, 29 Sep 2015 20:25:03 +0000 (21:25 +0100)
app/Repos/BookRepo.php
resources/views/books/sort.blade.php
resources/views/errors/404.blade.php [new file with mode: 0644]
resources/views/public.blade.php
tests/EntityTest.php

index 9d37cf9528b04779b2659a05a6e546ce82588fd6..aacf96b0606dc6b7fa51ca793c21f91036e2abdc 100644 (file)
@@ -91,9 +91,12 @@ class BookRepo
 
     public function findSuitableSlug($name, $currentId = false)
     {
-        $slug = Str::slug($name);
+        $originalSlug = Str::slug($name);
+        $slug = $originalSlug;
+        $count = 2;
         while($this->doesSlugExist($slug, $currentId)) {
-            $slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
+            $slug = $originalSlug . '-' . $count;
+            $count++;
         }
         return $slug;
     }
index f5c847fe2ecb577d81b460e44807a745b7243e33..e4e68d66278d1693e3fdbd1c0ee972c93eed6d6c 100644 (file)
 
             </div>
 
-            <div class="col-md-4">
-                <h3>Show Other Books</h3>
-                @foreach($books as $otherBook)
-                    @if($otherBook->id !== $book->id)
-                    <div id="additional-books">
-                        <a href="/books/{{ $otherBook->slug }}/sort-item" class="text-book"><i class="zmdi zmdi-book"></i>{{ $otherBook->name }}</a>
-                    </div>
-                    @endif
-                @endforeach
-            </div>
+            @if(count($books) > 1)
+                <div class="col-md-4">
+                    <h3>Show Other Books</h3>
+                    @foreach($books as $otherBook)
+                        @if($otherBook->id !== $book->id)
+                        <div id="additional-books">
+                            <a href="/books/{{ $otherBook->slug }}/sort-item" class="text-book"><i class="zmdi zmdi-book"></i>{{ $otherBook->name }}</a>
+                        </div>
+                        @endif
+                    @endforeach
+                </div>
+            @endif
 
         </div>
 
diff --git a/resources/views/errors/404.blade.php b/resources/views/errors/404.blade.php
new file mode 100644 (file)
index 0000000..8f66e2d
--- /dev/null
@@ -0,0 +1,9 @@
+@extends('public')
+
+@section('content')
+
+
+    <h1>Page Not Found</h1>
+    <p>The page you were looking for could not be found.</p>
+
+@stop
\ No newline at end of file
index f252ce38c732f10f3199d80a9471b7ef33786b6b..73c8384fc2473300bcad33290915ae0964121ef0 100644 (file)
@@ -37,7 +37,7 @@
                     <div class="links text-center">
                         @yield('header-buttons')
                     </div>
-                    @if($signedIn)
+                    @if(isset($signedIn) && $signedIn)
                         <img class="avatar" src="{{$currentUser->getAvatar(30)}}" alt="{{ $currentUser->name }}">
                         <div class="dropdown-container" data-dropdown>
                                 <span class="user-name" data-dropdown-toggle>
index ddbed731e4e401793b7854d32bdc5adad6c5c4d7..493f99cac396c7c27e867c30124174fdb6c9e851 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Illuminate\Support\Facades\DB;
+
 class EntityTest extends TestCase
 {
 
@@ -113,6 +115,12 @@ class EntityTest extends TestCase
             ->seePageIs('/books/my-first-book')
             ->see($book->name)->see($book->description);
 
+        // Ensure duplicate names are given different slugs
+        $this->asAdmin()
+            ->visit('/books/create')
+            ->submitForm('Save Book', $book->toArray())
+            ->seePageIs('/books/my-first-book-2');
+
         $book = \BookStack\Book::where('slug', '=', 'my-first-book')->first();
         return $book;
     }