Skip to content

Commit

Permalink
Added 404 page and extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddanbrown committed Sep 29, 2015
1 parent fd3929e commit 144eb69
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
7 changes: 5 additions & 2 deletions app/Repos/BookRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ public function doesSlugExist($slug, $currentId = false)

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;
}
Expand Down
22 changes: 12 additions & 10 deletions resources/views/books/sort.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@

</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>

Expand Down
9 changes: 9 additions & 0 deletions resources/views/errors/404.blade.php
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion resources/views/public.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 8 additions & 0 deletions tests/EntityTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Illuminate\Support\Facades\DB;

class EntityTest extends TestCase
{

Expand Down Expand Up @@ -113,6 +115,12 @@ public function bookCreation()
->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;
}
Expand Down

0 comments on commit 144eb69

Please sign in to comment.