1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-06 12:02:45 +03:00

Added more tests to increase test coverage

This commit is contained in:
Dan Brown
2016-01-02 14:48:35 +00:00
parent f60a0c3b76
commit d3709de035
10 changed files with 97 additions and 33 deletions

View File

@@ -31,11 +31,7 @@ abstract class Entity extends Model
if ($matches) return true;
if ($entity->isA('chapter') && $this->isA('book')) {
return $entity->book_id === $this->id;
}
if ($entity->isA('page') && $this->isA('book')) {
if (($entity->isA('chapter') || $entity->isA('page')) && $this->isA('book')) {
return $entity->book_id === $this->id;
}
@@ -64,15 +60,6 @@ abstract class Entity extends Model
return $this->morphMany('BookStack\View', 'viewable');
}
/**
* Get just the views for the current user.
* @return mixed
*/
public function userViews()
{
return $this->views()->where('user_id', '=', auth()->user()->id);
}
/**
* Allows checking of the exact class, Used to check entity type.
* Cleaner method for is_a.

View File

@@ -62,9 +62,9 @@ class SearchController extends Controller
return redirect()->back();
}
$searchTerm = $request->get('term');
$whereTerm = [['book_id', '=', $bookId]];
$pages = $this->pageRepo->getBySearch($searchTerm, $whereTerm);
$chapters = $this->chapterRepo->getBySearch($searchTerm, $whereTerm);
$searchWhereTerms = [['book_id', '=', $bookId]];
$pages = $this->pageRepo->getBySearch($searchTerm, $searchWhereTerms);
$chapters = $this->chapterRepo->getBySearch($searchTerm, $searchWhereTerms);
return view('search/book', ['pages' => $pages, 'chapters' => $chapters, 'searchTerm' => $searchTerm]);
}

View File

@@ -116,9 +116,11 @@ class UserController extends Controller
$this->validate($request, [
'name' => 'required',
'email' => 'required|email|unique:users,email,' . $id,
'password' => 'min:5',
'password-confirm' => 'same:password',
'password' => 'min:5|required_with:password_confirm',
'password-confirm' => 'same:password|required_with:password',
'role' => 'exists:roles,id'
], [
'password-confirm.required_with' => 'Password confirmation required'
]);
$user = $this->user->findOrFail($id);
@@ -132,6 +134,7 @@ class UserController extends Controller
$password = $request->get('password');
$user->password = bcrypt($password);
}
$user->save();
return redirect('/users');
}

View File

@@ -43,6 +43,16 @@ class Role extends Model
*/
public static function getDefault()
{
return static::where('name', '=', static::$default)->first();
return static::getRole(static::$default);
}
/**
* Get the role object for the specified role.
* @param $roleName
* @return mixed
*/
public static function getRole($roleName)
{
return static::where('name', '=', $roleName)->first();
}
}