Dan Brown

Added 404 page and extra tests

...@@ -91,9 +91,12 @@ class BookRepo ...@@ -91,9 +91,12 @@ class BookRepo
91 91
92 public function findSuitableSlug($name, $currentId = false) 92 public function findSuitableSlug($name, $currentId = false)
93 { 93 {
94 - $slug = Str::slug($name); 94 + $originalSlug = Str::slug($name);
95 + $slug = $originalSlug;
96 + $count = 2;
95 while($this->doesSlugExist($slug, $currentId)) { 97 while($this->doesSlugExist($slug, $currentId)) {
96 - $slug .= '-' . substr(md5(rand(1, 500)), 0, 3); 98 + $slug = $originalSlug . '-' . $count;
99 + $count++;
97 } 100 }
98 return $slug; 101 return $slug;
99 } 102 }
......
...@@ -11,16 +11,18 @@ ...@@ -11,16 +11,18 @@
11 11
12 </div> 12 </div>
13 13
14 - <div class="col-md-4"> 14 + @if(count($books) > 1)
15 - <h3>Show Other Books</h3> 15 + <div class="col-md-4">
16 - @foreach($books as $otherBook) 16 + <h3>Show Other Books</h3>
17 - @if($otherBook->id !== $book->id) 17 + @foreach($books as $otherBook)
18 - <div id="additional-books"> 18 + @if($otherBook->id !== $book->id)
19 - <a href="/books/{{ $otherBook->slug }}/sort-item" class="text-book"><i class="zmdi zmdi-book"></i>{{ $otherBook->name }}</a> 19 + <div id="additional-books">
20 - </div> 20 + <a href="/books/{{ $otherBook->slug }}/sort-item" class="text-book"><i class="zmdi zmdi-book"></i>{{ $otherBook->name }}</a>
21 - @endif 21 + </div>
22 - @endforeach 22 + @endif
23 - </div> 23 + @endforeach
24 + </div>
25 + @endif
24 26
25 </div> 27 </div>
26 28
......
1 +@extends('public')
2 +
3 +@section('content')
4 +
5 +
6 + <h1>Page Not Found</h1>
7 + <p>The page you were looking for could not be found.</p>
8 +
9 +@stop
...\ No newline at end of file ...\ No newline at end of file
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
37 <div class="links text-center"> 37 <div class="links text-center">
38 @yield('header-buttons') 38 @yield('header-buttons')
39 </div> 39 </div>
40 - @if($signedIn) 40 + @if(isset($signedIn) && $signedIn)
41 <img class="avatar" src="{{$currentUser->getAvatar(30)}}" alt="{{ $currentUser->name }}"> 41 <img class="avatar" src="{{$currentUser->getAvatar(30)}}" alt="{{ $currentUser->name }}">
42 <div class="dropdown-container" data-dropdown> 42 <div class="dropdown-container" data-dropdown>
43 <span class="user-name" data-dropdown-toggle> 43 <span class="user-name" data-dropdown-toggle>
......
1 <?php 1 <?php
2 2
3 +use Illuminate\Support\Facades\DB;
4 +
3 class EntityTest extends TestCase 5 class EntityTest extends TestCase
4 { 6 {
5 7
...@@ -113,6 +115,12 @@ class EntityTest extends TestCase ...@@ -113,6 +115,12 @@ class EntityTest extends TestCase
113 ->seePageIs('/books/my-first-book') 115 ->seePageIs('/books/my-first-book')
114 ->see($book->name)->see($book->description); 116 ->see($book->name)->see($book->description);
115 117
118 + // Ensure duplicate names are given different slugs
119 + $this->asAdmin()
120 + ->visit('/books/create')
121 + ->submitForm('Save Book', $book->toArray())
122 + ->seePageIs('/books/my-first-book-2');
123 +
116 $book = \BookStack\Book::where('slug', '=', 'my-first-book')->first(); 124 $book = \BookStack\Book::where('slug', '=', 'my-first-book')->first();
117 return $book; 125 return $book;
118 } 126 }
......