Unverified Commit 9f46d982 authored by Viral Solani's avatar Viral Solani Committed by GitHub

Merge pull request #142 from viralsolani/develop

Test Cases & Major Refactoring
parents 741aea63 1b867e39
......@@ -12,6 +12,10 @@ DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
# Access
ENABLE_REGISTRATION=true
REQUIRES_APPROVAL=false
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
......
......@@ -17,6 +17,25 @@ function generateUuid()
return uuid::uuid4();
}
if (!function_exists('homeRoute')) {
/**
* Return the route to the "home" page depending on authentication/authorization status.
*
* @return string
*/
function homeRoute()
{
if (access()->allow('view-backend')) {
return 'admin.dashboard';
} elseif (auth()->check()) {
return 'frontend.user.dashboard';
}
return 'frontend.index';
}
}
/*
* Global helpers file with misc functions.
*/
......
......@@ -57,49 +57,49 @@ class BlogCategoriesController extends Controller
$this->blogcategory->create($request->all());
return redirect()
->route('admin.blogcategories.index')
->route('admin.blogCategories.index')
->with('flash_success', trans('alerts.backend.blogcategories.created'));
}
/**
* @param \App\Models\BlogCategories\BlogCategory $blogcategory
* @param \App\Models\BlogCategories\BlogCategory $blogCategory
* @param \App\Http\Requests\Backend\BlogCategories\EditBlogCategoriesRequest $request
*
* @return mixed
*/
public function edit(BlogCategory $blogcategory, EditBlogCategoriesRequest $request)
public function edit(BlogCategory $blogCategory, EditBlogCategoriesRequest $request)
{
return view('backend.blogcategories.edit')
->with('blogcategory', $blogcategory);
->with('blogcategory', $blogCategory);
}
/**
* @param \App\Models\BlogCategories\BlogCategory $blogcategory
* @param \App\Models\BlogCategories\BlogCategory $blogCategory
* @param \App\Http\Requests\Backend\BlogCategories\UpdateBlogCategoriesRequest $request
*
* @return mixed
*/
public function update(BlogCategory $blogcategory, UpdateBlogCategoriesRequest $request)
public function update(BlogCategory $blogCategory, UpdateBlogCategoriesRequest $request)
{
$this->blogcategory->update($blogcategory, $request->all());
$this->blogcategory->update($blogCategory, $request->all());
return redirect()
->route('admin.blogcategories.index')
->route('admin.blogCategories.index')
->with('flash_success', trans('alerts.backend.blogcategories.updated'));
}
/**
* @param \App\Models\BlogCategories\BlogCategory $blogcategory
* @param \App\Models\BlogCategories\BlogCategory $blogCategory
* @param \App\Http\Requests\Backend\BlogCategories\DeleteBlogCategoriesRequest $request
*
* @return mixed
*/
public function destroy(BlogCategory $blogcategory, DeleteBlogCategoriesRequest $request)
public function destroy(BlogCategory $blogCategory, DeleteBlogCategoriesRequest $request)
{
$this->blogcategory->delete($blogcategory);
$this->blogcategory->delete($blogCategory);
return redirect()
->route('admin.blogcategories.index')
->route('admin.blogCategories.index')
->with('flash_success', trans('alerts.backend.blogcategories.deleted'));
}
}
......@@ -60,49 +60,49 @@ class BlogTagsController extends Controller
$this->blogtag->create($request->except('token'));
return redirect()
->route('admin.blogtags.index')
->route('admin.blogTags.index')
->with('flash_success', trans('alerts.backend.blogtags.created'));
}
/**
* @param \App\Models\BlogTags\BlogTag $blogtag
* @param \App\Models\BlogTags\BlogTag $blogTag
* @param \App\Http\Requests\Backend\BlogTags\EditBlogTagsRequest $request
*
* @return mixed
*/
public function edit(BlogTag $blogtag, EditBlogTagsRequest $request)
public function edit(BlogTag $blogTag, EditBlogTagsRequest $request)
{
return view('backend.blogtags.edit')
->with('blogtag', $blogtag);
->with('blogtag', $blogTag);
}
/**
* @param \App\Models\BlogTags\BlogTag $blogtag
* @param \App\Models\BlogTags\BlogTag $blogTag
* @param \App\Http\Requests\Backend\BlogTags\UpdateBlogTagsRequest $request
*
* @return mixed
*/
public function update(BlogTag $blogtag, UpdateBlogTagsRequest $request)
public function update(BlogTag $blogTag, UpdateBlogTagsRequest $request)
{
$this->blogtag->update($blogtag, $request->except(['_method', '_token']));
$this->blogtag->update($blogTag, $request->except(['_method', '_token']));
return redirect()
->route('admin.blogtags.index')
->route('admin.blogTags.index')
->with('flash_success', trans('alerts.backend.blogtags.updated'));
}
/**
* @param \App\Models\BlogTags\BlogTag $blogtag
* @param \App\Models\BlogTags\BlogTag $blogTag
* @param \App\Http\Requests\Backend\BlogTags\DeleteBlogTagsRequest $request
*
* @return mixed
*/
public function destroy(BlogTag $blogtag, DeleteBlogTagsRequest $request)
public function destroy(BlogTag $blogTag, DeleteBlogTagsRequest $request)
{
$this->blogtag->delete($blogtag);
$this->blogtag->delete($blogTag);
return redirect()
->route('admin.blogtags.index')
->route('admin.blogTags.index')
->with('flash_success', trans('alerts.backend.blogtags.deleted'));
}
}
......@@ -5,7 +5,6 @@ namespace App\Http\Controllers\Backend\Pages;
use App\Http\Controllers\Controller;
use App\Http\Requests\Backend\Pages\ManagePageRequest;
use App\Repositories\Backend\Pages\PagesRepository;
use Carbon\Carbon;
use Yajra\DataTables\Facades\DataTables;
/**
......@@ -32,17 +31,17 @@ class PagesTableController extends Controller
{
return Datatables::of($this->pages->getForDataTable())
->escapeColumns(['title'])
->addColumn('status', function ($pages) {
return $pages->status_label;
->addColumn('status', function ($page) {
return $page->status_label;
})
->addColumn('created_at', function ($pages) {
return Carbon::parse($pages->created_at)->toDateString();
->addColumn('created_at', function ($page) {
return $page->created_at->toDateString();
})
->addColumn('updated_at', function ($pages) {
return Carbon::parse($pages->updated_at)->toDateString();
->addColumn('created_by', function ($page) {
return $page->created_by;
})
->addColumn('actions', function ($pages) {
return $pages->action_buttons;
->addColumn('actions', function ($page) {
return $page->action_buttons;
})
->make(true);
}
......
......@@ -7,7 +7,6 @@ use App\Http\Requests\Backend\Settings\ManageSettingsRequest;
use App\Http\Requests\Backend\Settings\UpdateSettingsRequest;
use App\Models\Settings\Setting;
use App\Repositories\Backend\Settings\SettingsRepository;
use Illuminate\Http\Request;
/**
* Class SettingsController.
......@@ -50,22 +49,4 @@ class SettingsController extends Controller
->route('admin.settings.edit', $setting->id)
->with('flash_success', trans('alerts.backend.settings.updated'));
}
/**
* @param Setting $setting
* @param Request $request
* Remove logo or favicon icon
*
* @return mixed
*/
public function removeIcon(Request $request)
{
$this->settings->removeicon($request->data);
return json_encode(
[
'status' => true,
]
);
}
}
<?php
namespace App\Http\Controllers\Backend\Settings;
use App\Http\Controllers\Controller;
use App\Models\Settings\Setting;
use App\Repositories\Backend\Settings\SettingsRepository;
use Illuminate\Http\Request;
/**
* Class SettingsLogoController.
*/
class SettingsLogoController extends Controller
{
protected $settings;
/**
* @param \App\Repositories\Backend\Settings\SettingsRepository $settings
*/
public function __construct(SettingsRepository $settings)
{
$this->settings = $settings;
}
/**
* Remove logo or favicon icon.
*
* @param \App\Models\Settings\Setting $setting
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
public function destroy(Setting $setting, Request $request)
{
$this->settings->removeLogo($setting, $request->data);
return json_encode([
'status' => true,
]);
}
}
......@@ -50,7 +50,7 @@ class RegisterController extends Controller
*/
public function register(RegisterRequest $request)
{
if (config('access.users.confirm_email')) {
/*if (config('access.users.confirm_email')) {
$user = $this->user->create($request->all());
event(new UserRegistered($user));
......@@ -59,6 +59,22 @@ class RegisterController extends Controller
access()->login($this->user->create($request->all()));
event(new UserRegistered(access()->user()));
return redirect($this->redirectPath());
}*/
if (config('access.users.confirm_email') || config('access.users.requires_approval')) {
$user = $this->user->create($request->only('first_name', 'last_name', 'email', 'password', 'is_term_accept'));
event(new UserRegistered($user));
return redirect($this->redirectPath())->withFlashSuccess(
config('access.users.requires_approval') ?
trans('exceptions.frontend.auth.confirmation.created_pending') :
trans('exceptions.frontend.auth.confirmation.created_confirm')
);
} else {
access()->login($this->user->create($request->only('first_name', 'last_name', 'email', 'password', 'is_term_accept')));
event(new UserRegistered(access()->user()));
return redirect($this->redirectPath());
}
}
......
......@@ -50,9 +50,20 @@ class ResetPasswordController extends Controller
*/
public function showResetForm($token = null)
{
return view('frontend.auth.passwords.reset')
->withToken($token)
->withEmail($this->user->getEmailForPasswordToken($token));
if (!$token) {
return redirect()->route('frontend.auth.password.email');
}
$user = $this->user->findByPasswordResetToken($token);
if ($user && app()->make('auth.password.broker')->tokenExists($user, $token)) {
return view('frontend.auth.passwords.reset')
->withToken($token)
->withEmail($user->email);
}
return redirect()->route('frontend.auth.password.email')
->withFlashDanger(trans('exceptions.frontend.auth.password.reset_problem'));
}
/**
......@@ -80,4 +91,16 @@ class ResetPasswordController extends Controller
'password.regex' => 'Password must contain at least 1 uppercase letter and 1 number.',
];
}
/**
* Get the response for a successful password reset.
*
* @param string $response
*
* @return \Illuminate\Http\RedirectResponse
*/
protected function sendResetResponse($response)
{
return redirect()->route(homeRoute())->withFlashSuccess(trans($response));
}
}
......@@ -26,9 +26,22 @@ class StoreRoleRequest extends Request
*/
public function rules()
{
$permissions = '';
if ($this->associated_permissions != 'all') {
$permissions = 'required';
}
return [
'name' => 'required|max:191',
'permissions' => 'required',
'permissions' => $permissions,
];
}
public function messages()
{
return [
'permissions.required' => 'You must select at least one permission for this role.',
];
}
}
......@@ -26,9 +26,22 @@ class UpdateRoleRequest extends Request
*/
public function rules()
{
$permissions = '';
if ($this->associated_permissions != 'all') {
$permissions = 'required';
}
return [
'name' => 'required|max:191',
'permissions' => 'required',
'permissions' => $permissions,
];
}
public function messages()
{
return [
'permissions.required' => 'You must select at least one permission for this role.',
];
}
}
......@@ -30,6 +30,14 @@ class UserEventListener
* @param $event
*/
public function onRegistered($event)
{
\Log::info('User Registered: '.$event->user->full_name);
}
/**
* @param $event
*/
/*public function onRegistered($event)
{
\Log::info('User Registered: '.$event->user->first_name);
......@@ -39,7 +47,7 @@ class UserEventListener
'email_template_type' => 1,
];
createNotification('', 1, 2, $options);
}
}*/
/**
* @param $event
......
......@@ -213,9 +213,9 @@ trait UserAttribute
/**
* @return string
*/
public function getDeletePermanentlyButtonAttribute()
public function getDeletePermanentlyButtonAttribute($class)
{
return '<a href="'.route('admin.access.user.delete-permanently', $this).'" name="delete_user_perm"><i class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.delete_permanently').'"></i></a> ';
return '<a class="'.$class.'" href="'.route('admin.access.user.delete-permanently', $this).'" name="delete_user_perm"><i class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.delete_permanently').'"></i></a> ';
}
/**
......@@ -383,7 +383,10 @@ trait UserAttribute
public function getActionButtonsAttribute()
{
if ($this->trashed()) {
return '<div class="btn-group action-btn">'.$this->getRestoreButtonAttribute('btn btn-default btn-flat').'</div>';
return '<div class="btn-group action-btn">
'.$this->getRestoreButtonAttribute('btn btn-default btn-flat').'
'.$this->getDeletePermanentlyButtonAttribute('btn btn-default btn-flat').'
</div>';
}
// Check if role have all permission
......
......@@ -13,8 +13,8 @@ trait BlogCategoryAttribute
public function getActionButtonsAttribute()
{
return '<div class="btn-group action-btn">
'.$this->getEditButtonAttribute('edit-blog-category', 'admin.blogcategories.edit').'
'.$this->getDeleteButtonAttribute('delete-blog-category', 'admin.blogcategories.destroy').'
'.$this->getEditButtonAttribute('edit-blog-category', 'admin.blogCategories.edit').'
'.$this->getDeleteButtonAttribute('delete-blog-category', 'admin.blogCategories.destroy').'
</div>';
}
......
......@@ -12,8 +12,8 @@ trait BlogCategoryRelationship
/**
* BlogCategories belongs to relationship with state.
*/
public function createdBy()
public function creator()
{
return $this->belongsTo(User::class, 'created_by', 'id');
return $this->belongsTo(User::class, 'created_by');
}
}
......@@ -13,8 +13,8 @@ trait BlogTagAttribute
public function getActionButtonsAttribute()
{
return '<div class="btn-group action-btn">
'.$this->getEditButtonAttribute('edit-blog-tag', 'admin.blogtags.edit').'
'.$this->getDeleteButtonAttribute('delete-blog-tag', 'admin.blogtags.destroy').'
'.$this->getEditButtonAttribute('edit-blog-tag', 'admin.blogTags.edit').'
'.$this->getDeleteButtonAttribute('delete-blog-tag', 'admin.blogTags.destroy').'
</div>';
}
......
......@@ -12,8 +12,8 @@ trait BlogTagRelationship
/**
* BlogTags belongs to relationship with state.
*/
public function createdBy()
public function creator()
{
return $this->belongsTo(User::class, 'created_by', 'id');
return $this->belongsTo(User::class, 'created_by');
}
}
......@@ -30,8 +30,8 @@ trait BlogRelationship
/**
* Blogs belongsTo with User.
*/
public function createdBy()
public function owner()
{
return $this->belongsTo(User::class, 'created_by', 'id');
return $this->belongsTo(User::class, 'created_by');
}
}
......@@ -5,12 +5,14 @@ namespace App\Models\Page;
use App\Models\BaseModel;
use App\Models\ModelTrait;
use App\Models\Page\Traits\Attribute\PageAttribute;
use App\Models\Page\Traits\PageRelationship;
use Illuminate\Database\Eloquent\SoftDeletes;
class Page extends BaseModel
{
use ModelTrait,
SoftDeletes,
PageRelationship,
PageAttribute {
// PageAttribute::getEditButtonAttribute insteadof ModelTrait;
}
......@@ -29,6 +31,17 @@ class Page extends BaseModel
*/
protected $guarded = ['id'];
/**
* The default values for attributes.
*
* @var array
*/
protected $attributes = [
'created_by' => 1,
];
protected $with = ['owner'];
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
......
......@@ -13,8 +13,8 @@ trait PageAttribute
public function getActionButtonsAttribute()
{
return '<div class="btn-group action-btn">
'.$this->getEditButtonAttribute('edit-cms-pages', 'admin.pages.edit').'
'.$this->getDeleteButtonAttribute('delete-cms-pages', 'admin.pages.destroy').'
'.$this->getEditButtonAttribute('edit-page', 'admin.pages.edit').'
'.$this->getDeleteButtonAttribute('delete-page', 'admin.pages.destroy').'
</div>';
}
......
<?php
namespace App\Models\Page\Traits;
use App\Models\Access\User\User;
trait PageRelationship
{
public function owner()
{
return $this->belongsTo(User::class, 'created_by');
}
}
......@@ -69,7 +69,7 @@ class RoleRepository extends BaseRepository
}
//See if the role has all access
$all = $input['associated-permissions'] == 'all' ? true : false;
$all = $input['associated_permissions'] == 'all' ? true : false;
if (!isset($input['permissions'])) {
$input['permissions'] = [];
......@@ -133,7 +133,7 @@ class RoleRepository extends BaseRepository
if ($role->id == 1) {
$all = true;
} else {
$all = $input['associated-permissions'] == 'all' ? true : false;
$all = $input['associated_permissions'] == 'all' ? true : false;
}
if (!isset($input['permissions'])) {
......@@ -190,13 +190,13 @@ class RoleRepository extends BaseRepository
}
/**
* @param Model $role
* @param Role $role
*
* @throws GeneralException
*
* @return bool
*/
public function delete(Model $role)
public function delete(Role $role)
{
//Would be stupid to delete the administrator role
if ($role->id == 1) { //id is 1 because of the seeder
......
......@@ -97,9 +97,6 @@ class UserRepository extends BaseRepository
$user = $this->createUserStub($data);
DB::transaction(function () use ($user, $data, $roles, $permissions) {
// Set email type 2
$email_type = 2;
if ($user->save()) {
//User Created, Validate Roles
......@@ -120,18 +117,6 @@ class UserRepository extends BaseRepository
event(new UserCreated($user));
/*if (isset($data['confirmation_email']) && $user->confirmed == 0) {
$email_type = 1;
}*/
// Send email to the user
/* $options = [
'data' => $user->toArray(),
'email_template_type' => $email_type,
];*/
//createNotification('', 1, 2, $options);
return true;
}
......@@ -175,28 +160,23 @@ class UserRepository extends BaseRepository
}
/**
* @param Model $user
* Change Password.
*
* @param $user
* @param $input
*
* @throws GeneralException
*
* @return bool
*/
public function updatePassword(Model $user, $input)
public function updatePassword($user, $input)
{
$user = $this->find(access()->id());
if (Hash::check($input['old_password'], $user->password)) {
$user->password = bcrypt($input['password']);
if ($user->save()) {
$input['email'] = $user->email;
// Send email to the user
$options = [
'data' => $input,
'email_template_type' => 4,
];
createNotification('', $user->id, 2, $options);
if ($user->save()) {
event(new UserPasswordChanged($user));
return true;
......@@ -215,7 +195,7 @@ class UserRepository extends BaseRepository
*
* @return bool
*/
public function delete(Model $user)
public function delete($user)
{
if (access()->id() == $user->id) {
throw new GeneralException(trans('exceptions.backend.access.users.cant_delete_self'));
......@@ -231,11 +211,11 @@ class UserRepository extends BaseRepository
}
/**
* @param Model $user
* @param $user
*
* @throws GeneralException
*/
public function forceDelete(Model $user)
public function forceDelete($user)
{
if (is_null($user->deleted_at)) {
throw new GeneralException(trans('exceptions.backend.access.users.delete_first'));
......@@ -253,13 +233,13 @@ class UserRepository extends BaseRepository
}
/**
* @param Model $user
* @param $user
*
* @throws GeneralException
*
* @return bool
*/
public function restore(Model $user)
public function restore($user)
{
if (is_null($user->deleted_at)) {
throw new GeneralException(trans('exceptions.backend.access.users.cant_restore'));
......@@ -275,14 +255,14 @@ class UserRepository extends BaseRepository
}
/**
* @param Model $user
* @param $user
* @param $status
*
* @throws GeneralException
*
* @return bool
*/
public function mark(Model $user, $status)
public function mark($user, $status)
{
if (access()->id() == $user->id && $status == 0) {
throw new GeneralException(trans('exceptions.backend.access.users.cant_deactivate_self'));
......@@ -301,13 +281,6 @@ class UserRepository extends BaseRepository
}
if ($user->save()) {
// Send email to the user
$options = [
'data' => $user,
'email_template_type' => 3,
];
createNotification('', $user->id, 2, $options);
return true;
}
......
......@@ -6,7 +6,6 @@ use App\Events\Backend\Blogs\BlogCreated;
use App\Events\Backend\Blogs\BlogDeleted;
use App\Events\Backend\Blogs\BlogUpdated;
use App\Exceptions\GeneralException;
use App\Http\Utilities\FileUploads;
use App\Models\BlogCategories\BlogCategory;
use App\Models\BlogMapCategories\BlogMapCategory;
use App\Models\BlogMapTags\BlogMapTag;
......@@ -15,6 +14,7 @@ use App\Models\BlogTags\BlogTag;
use App\Repositories\BaseRepository;
use Carbon\Carbon;
use DB;
use Illuminate\Support\Facades\Storage;
/**
* Class BlogsRepository.
......@@ -26,6 +26,21 @@ class BlogsRepository extends BaseRepository
*/
const MODEL = Blog::class;
protected $upload_path;
/**
* Storage Class Object.
*
* @var \Illuminate\Support\Facades\Storage
*/
protected $storage;
public function __construct()
{
$this->upload_path = 'img'.DIRECTORY_SEPARATOR.'blog'.DIRECTORY_SEPARATOR;
$this->storage = Storage::disk('public');
}
/**
* @return mixed
*/
......@@ -132,7 +147,7 @@ class BlogsRepository extends BaseRepository
/**
* Creating Tags.
*
* @param Array($tags)
* @param array $tags
*
* @return array
*/
......@@ -210,13 +225,12 @@ class BlogsRepository extends BaseRepository
*/
public function uploadImage($input)
{
$uploadManager = new FileUploads();
$avatar = $input['featured_image'];
if (isset($input['featured_image']) && !empty($input['featured_image'])) {
$fileName = $uploadManager->setBasePath('backend/blog_images')
->setThumbnailFlag(false)
->upload($input['featured_image']);
$fileName = time().$avatar->getClientOriginalName();
$this->storage->put($this->upload_path.$fileName, file_get_contents($avatar->getRealPath()));
$input = array_merge($input, ['featured_image' => $fileName]);
......@@ -231,11 +245,8 @@ class BlogsRepository extends BaseRepository
*/
public function deleteOldFile($model)
{
$uploadManager = new FileUploads();
$fileName = $model->featured_image;
$filePath = $uploadManager->setBasePath('backend/blog_images');
$file = $filePath->filePath.DIRECTORY_SEPARATOR.$fileName;
return $uploadManager->deleteFile($file);
return $this->storage->delete($this->upload_path.$fileName);
}
}
......@@ -25,12 +25,14 @@ class PagesRepository extends BaseRepository
public function getForDataTable()
{
return $this->query()
->leftjoin(config('access.users_table'), config('access.users_table').'.id', '=', config('module.pages.table').'.created_by')
->select([
config('module.pages.table').'.id',
config('module.pages.table').'.title',
config('module.pages.table').'.status',
config('module.pages.table').'.created_at',
config('module.pages.table').'.updated_at',
config('access.users_table').'.first_name as created_by',
]);
}
......@@ -47,10 +49,10 @@ class PagesRepository extends BaseRepository
throw new GeneralException(trans('exceptions.backend.pages.already_exists'));
}
//Making extra fields
// Making extra fields
$input['page_slug'] = str_slug($input['title']);
$input['status'] = isset($input['status']) ? 1 : 0;
$input['created_by'] = access()->user()->id;
$input['created_by'] = auth()->id();
if ($page = Page::create($input)) {
event(new PageCreated($page));
......@@ -75,7 +77,7 @@ class PagesRepository extends BaseRepository
throw new GeneralException(trans('exceptions.backend.pages.already_exists'));
}
//Making extra fields
// Making extra fields
$input['page_slug'] = str_slug($input['title']);
$input['status'] = isset($input['status']) ? 1 : 0;
$input['updated_by'] = access()->user()->id;
......
......@@ -5,6 +5,7 @@ namespace App\Repositories\Backend\Settings;
use App\Exceptions\GeneralException;
use App\Models\Settings\Setting;
use App\Repositories\BaseRepository;
use Illuminate\Support\Facades\Storage;
/**
* Class SettingsRepository.
......@@ -16,24 +17,57 @@ class SettingsRepository extends BaseRepository
*/
const MODEL = Setting::class;
/**
* Site Logo Path.
*
* @var string
*/
protected $site_logo_path;
/**
* Favicon path.
*
* @var string
*/
protected $favicon_path;
/**
* Storage Class Object.
*
* @var \Illuminate\Support\Facades\Storage
*/
protected $storage;
/**
* Constructor.
*/
public function __construct()
{
$this->site_logo_path = 'img'.DIRECTORY_SEPARATOR.'logo'.DIRECTORY_SEPARATOR;
$this->favicon_path = 'img'.DIRECTORY_SEPARATOR.'favicon'.DIRECTORY_SEPARATOR;
$this->storage = Storage::disk('public');
}
/**
* @param \App\Models\Settings\Setting $setting
* @param $input
* @param array $input
*
* @throws \App\Exceptions\GeneralException
*
* return bool
* @return bool
*/
public function update(Setting $setting, array $input)
{
if (isset($input['logo'])) {
$image_upload = $this->uploadlogoimage($setting, $input['logo']);
$input['logo'] = $image_upload;
if (!empty($input['logo'])) {
$this->removeLogo($setting, 'logo');
$input['logo'] = $this->uploadLogo($setting, $input['logo'], 'logo');
}
if (isset($input['favicon'])) {
$image_upload = $this->uploadfaviconimage($setting, $input['favicon']);
$input['favicon'] = $image_upload;
if (!empty($input['favicon'])) {
$this->removeLogo($setting, 'favicon');
$input['favicon'] = $this->uploadLogo($setting, $input['favicon'], 'favicon');
}
if ($setting->update($input)) {
......@@ -46,63 +80,34 @@ class SettingsRepository extends BaseRepository
/*
* Upload logo image
*/
public function uploadlogoimage($setting, $logo)
public function uploadLogo($setting, $logo, $type)
{
$image_name_ex = $logo->getClientOriginalExtension();
if ($setting->logo) {
if (file_exists(public_path().'/img/site_logo/'.$setting->logo)) {
unlink('img/site_logo/'.$setting->logo);
}
}
$path = $type == 'logo' ? $this->site_logo_path : $this->favicon_path;
$image_name = time().$logo->getClientOriginalName();
$destinationPath = public_path('img/site_logo');
$logo->move($destinationPath, $image_name);
$this->storage->put($path.$image_name, file_get_contents($logo->getRealPath()));
return $image_name;
}
/*
* Upload favicon icon image
* remove logo or favicon icon
*/
public function uploadfaviconimage($setting, $logo)
public function removeLogo(Setting $setting, $type)
{
$image_name_ex = $logo->getClientOriginalExtension();
$path = $type == 'logo' ? $this->site_logo_path : $this->favicon_path;
if ($setting->favicon) {
if (file_exists(public_path().'/img/favicon_icon/'.$setting->favicon)) {
unlink('img/favicon_icon/'.$setting->favicon);
}
if ($setting->$type && $this->storage->exists($path.$setting->$type)) {
$this->storage->delete($path.$setting->$type);
}
$image_name = time().$logo->getClientOriginalName();
$destinationPath = public_path('/img/favicon_icon');
$logo->move($destinationPath, $image_name);
$result = $setting->update([$type => null]);
return $image_name;
}
/*
* remove logo or favicon icon
*/
public function removeicon($input)
{
$setting = $this->query()->get();
if ($input == 'logo') {
if ($setting[0]->logo) {
if (file_exists(public_path().'/img/site_logo/'.$setting[0]->logo)) {
unlink('img/site_logo/'.$setting[0]->logo);
}
$this->query()->update(['logo' => null]);
}
} else {
if ($setting[0]->favicon) {
if (file_exists(public_path().'/img/favicon_icon/'.$setting[0]->favicon)) {
unlink('img/favicon_icon/'.$setting[0]->favicon);
}
}
$this->query()->update(['favicon' => null]);
if ($result) {
return true;
}
throw new GeneralException(trans('exceptions.backend.settings.update_error'));
}
}
......@@ -79,6 +79,8 @@ class UserRepository extends BaseRepository
}
/**
* Create User.
*
* @param array $data
* @param bool $provider
*
......@@ -94,11 +96,28 @@ class UserRepository extends BaseRepository
$user->confirmation_code = md5(uniqid(mt_rand(), true));
$user->status = 1;
$user->password = $provider ? null : bcrypt($data['password']);
$user->confirmed = $provider ? 1 : (config('access.users.confirm_email') ? 0 : 1);
$user->is_term_accept = $data['is_term_accept'];
// If users require approval, confirmed is false regardless of account type
if (config('access.users.requires_approval')) {
$user->confirmed = 0; // No confirm e-mail sent, that defeats the purpose of manual approval
} elseif (config('access.users.confirm_email')) { // If user must confirm email
// If user is from social, already confirmed
if ($provider) {
$user->confirmed = 1; // E-mails are validated through the social platform
} else {
// Otherwise needs confirmation
$user->confirmed = 0;
$confirm = true;
}
} else {
// Otherwise both are off and confirmed is default
$user->confirmed = 1;
}
DB::transaction(function () use ($user) {
if ($user->save()) {
/*
* Add the default site role to the new user
*/
......@@ -304,4 +323,20 @@ class UserRepository extends BaseRepository
return $token;
}
/**
* @param $token
*
* @return mixed
*/
public function findByPasswordResetToken($token)
{
foreach (DB::table(config('auth.passwords.users.table'))->get() as $row) {
if (password_verify($token, $row->token)) {
return $this->findByEmail($row->email);
}
}
return false;
}
}
......@@ -4,7 +4,9 @@
"keywords": [
"framework",
"laravel",
"boilerplate"
"boilerplate",
"adminpanel",
"rest-api"
],
"license": "MIT",
"type": "project",
......@@ -12,6 +14,7 @@
"php": ">=7.0.0",
"arcanedev/log-viewer": "^4.4",
"arcanedev/no-captcha": "^5.0",
"codedungeon/phpunit-result-printer": "0.4.4",
"creativeorange/gravatar": "~1.0",
"davejamesmiller/laravel-breadcrumbs": "^4.1",
"doctrine/dbal": "^2.6",
......@@ -54,6 +57,9 @@
},
"classmap": [
"tests/TestCase.php"
],
"files": [
"tests/Utilities/helpers.php"
]
},
"scripts": {
......
This diff is collapsed.
......@@ -88,7 +88,7 @@ return [
/*
* Whether or not public registration is on
*/
'registration' => env('ENABLE_REGISTRATION', 'true'),
'registration' => env('ENABLE_REGISTRATION', true),
/*
* The role the user is assigned to when they sign up from the frontend, not namespaced
......@@ -105,6 +105,12 @@ return [
* Whether or not the users email can be changed on the edit profile screen
*/
'change_email' => false,
/*
* Whether or not new users need to be approved by an administrator before logging in
* If this is set to true, then confirm_email is not in effect
*/
'requires_approval' => env('REQUIRES_APPROVAL', false),
],
/*
......
<?php
use App\Models\Access\User\User;
use App\Models\BlogCategories\BlogCategory;
use Faker\Generator as Faker;
$factory->define(BlogCategory::class, function (Faker $faker) {
return [
'name' => $faker->word,
'status' => $faker->numberBetween(0, 1),
'created_by' => function () {
return factory(User::class)->create()->id;
},
];
});
<?php
use App\Models\Access\User\User;
use App\Models\Blogs\Blog;
use Faker\Generator as Faker;
$factory->define(Blog::class, function (Faker $faker) {
$status = [
'Published',
'Draft',
'InActive',
'Scheduled',
];
return [
'name' => $faker->sentence,
'publish_datetime' => $faker->dateTime(),
'featured_image' => 'logo.png',
'content' => $faker->paragraph(3),
'status' => $status[$faker->numberBetween(0, 3)],
'created_by' => function () {
return factory(User::class)->create()->id;
},
];
});
<?php
use App\Models\Access\User\User;
use App\Models\BlogTags\BlogTag;
use Faker\Generator as Faker;
$factory->define(BlogTag::class, function (Faker $faker) {
return [
'name' => $faker->word,
'status' => $faker->numberBetween(0, 1),
'created_by' => function () {
return factory(User::class)->create()->id;
},
];
});
<?php
use App\Models\Faqs\Faq;
use Faker\Generator as Faker;
$factory->define(Faq::class, function (Faker $faker) {
return [
'question' => rtrim($faker->sentence, '.').'?',
'answer' => $faker->paragraph,
'status' => $faker->numberBetween(0, 1),
];
});
<?php
use App\Models\Access\User\User;
use App\Models\Page\Page;
use Faker\Generator as Faker;
$factory->define(Page::class, function (Faker $faker) {
$title = $faker->sentence;
return [
'title' => $title,
'page_slug' => str_slug($title),
'description' => $faker->paragraph,
'created_by' => function () {
return factory(User::class)->create()->id;
},
];
});
<?php
use App\Models\Access\Permission\Permission;
use Faker\Generator;
/*
* Permissions
*/
$factory->define(Permission::class, function (Generator $faker) {
$name = $faker->word;
return [
'name' => $name,
'display_name' => $name,
'sort' => $faker->numberBetween(1, 100),
];
});
$factory->state(Permission::class, 'active', function () {
return [
'status' => 1,
];
});
$factory->state(Permission::class, 'inactive', function () {
return [
'status' => 0,
];
});
<?php
use App\Models\Access\Role\Role;
use Faker\Generator;
/*
* Roles
*/
$factory->define(Role::class, function (Generator $faker) {
return [
'name' => $faker->name,
'all' => 0,
'sort' => $faker->numberBetween(1, 100),
];
});
$factory->state(Role::class, 'admin', function () {
return [
'all' => 1,
];
});
$factory->state(Role::class, 'active', function () {
return [
'status' => 1,
];
});
$factory->state(Role::class, 'inactive', function () {
return [
'status' => 0,
];
});
<?php
use App\Models\Access\Role\Role;
use App\Models\Access\User\User;
use Faker\Generator;
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(User::class, function (Generator $faker) {
static $password;
return [
'name' => $faker->name,
'first_name' => $faker->name,
'last_name' => $faker->name,
'email' => $faker->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
'remember_token' => str_random(10),
];
});
......@@ -50,20 +39,3 @@ $factory->state(User::class, 'unconfirmed', function () {
'confirmed' => 0,
];
});
/*
* Roles
*/
$factory->define(Role::class, function (Generator $faker) {
return [
'name' => $faker->name,
'all' => 0,
'sort' => $faker->numberBetween(1, 100),
];
});
$factory->state(Role::class, 'admin', function () {
return [
'all' => 1,
];
});
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddNullConstraintOnCreatedByOnUserTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->integer('created_by')->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddNullConstraintOnCreatedByOnRoleTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('roles', function (Blueprint $table) {
$table->integer('created_by')->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddNullConstraintOnCreatedByOnPermissionTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('permissions', function (Blueprint $table) {
$table->integer('created_by')->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
......@@ -26,8 +26,8 @@ class UserTableSeeder extends Seeder
//Add the master administrator, user id of 1
$users = [
[
'first_name' => 'Admin Istrator',
'last_name' => 'Admin Istrator',
'first_name' => 'Viral',
'last_name' => 'Solani',
'email' => 'admin@admin.com',
'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
......@@ -39,8 +39,8 @@ class UserTableSeeder extends Seeder
'deleted_at' => null,
],
[
'first_name' => 'Backend User',
'last_name' => 'Admin Istrator',
'first_name' => 'Vipul',
'last_name' => 'Basapati',
'email' => 'executive@executive.com',
'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
......@@ -52,8 +52,8 @@ class UserTableSeeder extends Seeder
'deleted_at' => null,
],
[
'first_name' => 'Default User',
'last_name' => 'Admin Istrator',
'first_name' => 'User',
'last_name' => 'Test',
'email' => 'user@user.com',
'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
......
......@@ -18,7 +18,7 @@ class MenuTableSeeder extends Seeder
'id' => 1,
'type' => 'backend',
'name' => 'Backend Sidebar Menu',
'items' => '[{"view_permission_id":"view-access-management","icon":"fa-users","open_in_new_tab":0,"url_type":"route","url":"","name":"Access Management","id":11,"content":"Access Management","children":[{"view_permission_id":"view-user-management","open_in_new_tab":0,"url_type":"route","url":"admin.access.user.index","name":"User Management","id":12,"content":"User Management"},{"view_permission_id":"view-role-management","open_in_new_tab":0,"url_type":"route","url":"admin.access.role.index","name":"Role Management","id":13,"content":"Role Management"},{"view_permission_id":"view-permission-management","open_in_new_tab":0,"url_type":"route","url":"admin.access.permission.index","name":"Permission Management","id":14,"content":"Permission Management"}]},{"view_permission_id":"view-module","icon":"fa-wrench","open_in_new_tab":0,"url_type":"route","url":"admin.modules.index","name":"Module","id":1,"content":"Module"},{"view_permission_id":"view-menu","icon":"fa-bars","open_in_new_tab":0,"url_type":"route","url":"admin.menus.index","name":"Menus","id":3,"content":"Menus"},{"view_permission_id":"view-page","icon":"fa-file-text","open_in_new_tab":0,"url_type":"route","url":"admin.pages.index","name":"Pages","id":2,"content":"Pages"},{"view_permission_id":"view-email-template","icon":"fa-envelope","open_in_new_tab":0,"url_type":"route","url":"admin.emailtemplates.index","name":"Email Templates","id":8,"content":"Email Templates"},{"view_permission_id":"edit-settings","icon":"fa-gear","open_in_new_tab":0,"url_type":"route","url":"admin.settings.edit?id=1","name":"Settings","id":9,"content":"Settings"},{"view_permission_id":"view-blog","icon":"fa-commenting","open_in_new_tab":0,"url_type":"route","url":"","name":"Blog Management","id":15,"content":"Blog Management","children":[{"view_permission_id":"view-blog-category","open_in_new_tab":0,"url_type":"route","url":"admin.blogcategories.index","name":"Blog Category Management","id":16,"content":"Blog Category Management"},{"view_permission_id":"view-blog-tag","open_in_new_tab":0,"url_type":"route","url":"admin.blogtags.index","name":"Blog Tag Management","id":17,"content":"Blog Tag Management"},{"view_permission_id":"view-blog","open_in_new_tab":0,"url_type":"route","url":"admin.blogs.index","name":"Blog Management","id":18,"content":"Blog Management"}]},{"view_permission_id":"view-faq","icon":"fa-question-circle","open_in_new_tab":0,"url_type":"route","url":"admin.faqs.index","name":"Faq Management","id":19,"content":"Faq Management"}]',
'items' => '[{"view_permission_id":"view-access-management","icon":"fa-users","open_in_new_tab":0,"url_type":"route","url":"","name":"Access Management","id":11,"content":"Access Management","children":[{"view_permission_id":"view-user-management","open_in_new_tab":0,"url_type":"route","url":"admin.access.user.index","name":"User Management","id":12,"content":"User Management"},{"view_permission_id":"view-role-management","open_in_new_tab":0,"url_type":"route","url":"admin.access.role.index","name":"Role Management","id":13,"content":"Role Management"},{"view_permission_id":"view-permission-management","open_in_new_tab":0,"url_type":"route","url":"admin.access.permission.index","name":"Permission Management","id":14,"content":"Permission Management"}]},{"view_permission_id":"view-module","icon":"fa-wrench","open_in_new_tab":0,"url_type":"route","url":"admin.modules.index","name":"Module","id":1,"content":"Module"},{"view_permission_id":"view-menu","icon":"fa-bars","open_in_new_tab":0,"url_type":"route","url":"admin.menus.index","name":"Menus","id":3,"content":"Menus"},{"view_permission_id":"view-page","icon":"fa-file-text","open_in_new_tab":0,"url_type":"route","url":"admin.pages.index","name":"Pages","id":2,"content":"Pages"},{"view_permission_id":"view-email-template","icon":"fa-envelope","open_in_new_tab":0,"url_type":"route","url":"admin.emailtemplates.index","name":"Email Templates","id":8,"content":"Email Templates"},{"view_permission_id":"edit-settings","icon":"fa-gear","open_in_new_tab":0,"url_type":"route","url":"admin.settings.edit?id=1","name":"Settings","id":9,"content":"Settings"},{"view_permission_id":"view-blog","icon":"fa-commenting","open_in_new_tab":0,"url_type":"route","url":"","name":"Blog Management","id":15,"content":"Blog Management","children":[{"view_permission_id":"view-blog-category","open_in_new_tab":0,"url_type":"route","url":"admin.blogCategories.index","name":"Blog Category Management","id":16,"content":"Blog Category Management"},{"view_permission_id":"view-blog-tag","open_in_new_tab":0,"url_type":"route","url":"admin.blogTags.index","name":"Blog Tag Management","id":17,"content":"Blog Tag Management"},{"view_permission_id":"view-blog","open_in_new_tab":0,"url_type":"route","url":"admin.blogs.index","name":"Blog Management","id":18,"content":"Blog Management"}]},{"view_permission_id":"view-faq","icon":"fa-question-circle","open_in_new_tab":0,"url_type":"route","url":"admin.faqs.index","name":"Faq Management","id":19,"content":"Faq Management"}]',
'created_by' => 1,
'created_at' => Carbon::now(),
];
......
......@@ -7,7 +7,8 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
stopOnFailure="false"
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer">
<testsuites>
<testsuite name="Feature Tests">
<directory suffix="Test.php">./tests/Feature</directory>
......
var associated = $("select[name='associated-permissions']");
var associated = $("select[name='associated_permissions']");
var associated_container = $("#available-permissions");
if (associated.val() == "custom")
......
{
"/js/frontend.js": "/js/frontend.945469bbbc12df3ad9e1.js",
"/js/backend.js": "/js/backend.79d9e4698dadbc0d93c7.js",
"/mix.js": "/mix.247ab120fe7680658924.js",
"/css/frontend.css": "/css/frontend.3af0a6cbd7d1d8d042f2a37e97008b7c.css",
"/css/backend.css": "/css/backend.f8550f50504e5b8ef6055285205f223a.css",
"/css/backend-custom.css": "/css/backend-custom.18e74fbe4c755b817a022d6d3d4e76b1.css",
"/js/backend-custom.js": "/js/backend-custom.e6ea05e1824d0dd8e7c62027c135b7f2.js",
"/js/dataTable.js": "/js/dataTable.f968d300a6a0b871f138f114361259c8.js"
}
\ No newline at end of file
......@@ -115,6 +115,7 @@ return [
'already_confirmed' => 'Your account is already confirmed.',
'confirm' => 'Confirm your account!',
'created_confirm' => 'Your account was successfully created. We have sent you an e-mail to confirm your account.',
'created_pending' => 'Your account was successfully created and is pending approval. An e-mail will be sent when your account is approved.',
'mismatch' => 'Your confirmation code does not match.',
'not_found' => 'That confirmation code does not exist.',
'resend' => 'Your account is not confirmed. Please click the confirmation link in your e-mail, or <a href='.route('frontend.auth.account.confirm.resend', ':user_id').'>click here</a> to resend the confirmation e-mail.',
......
......@@ -66,7 +66,7 @@ return [
'active' => 'Active Users',
'all_permissions' => 'All Permissions',
'change_password' => 'Change Password',
'change_password_for' => 'Change Password :user',
'change_password_for' => 'Change Password for :user',
'create' => 'Create User',
'deactivated' => 'Deactivated Users',
'deleted' => 'Deleted Users',
......@@ -126,6 +126,7 @@ return [
'status' => 'Status',
'createdat' => 'Created At',
'updatedat' => 'Updated At',
'createdby' => 'Created By',
'all' => 'All',
],
],
......@@ -200,7 +201,7 @@ return [
'companydetails' => 'Company Contact Details',
'mail' => 'Mail Settings',
'footer' => 'Footer Settings',
'terms' => 'Terms & Condition Settings',
'terms' => 'Terms and Condition Settings',
'google' => 'Google Analytics Track Code',
],
......
<!--Action Button-->
@if(Active::checkUriPattern('admin/access/user') || Active::checkUriPattern('admin/access/user/deleted') || Active::checkUriPattern('admin/access/user/deactivated'))
<div class="btn-group">
<button type="button" class="btn btn-warning btn-flat dropdown-toggle" data-toggle="dropdown">Export
<button type="button" class="btn btn-warning btn-flat dropdown-toggle" data-toggle="dropdown">Export
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li id="copyButton"><a href="#"><i class="fa fa-clone"></i> Copy</a></li>
<li id="copyButton"><a href="#"><i class="fa fa-clone"></i>Copy</a></li>
<li id="csvButton"><a href="#"><i class="fa fa-file-text-o"></i> CSV</a></li>
<li id="excelButton"><a href="#"><i class="fa fa-file-excel-o"></i> Excel</a></li>
<li id="pdfButton"><a href="#"><i class="fa fa-file-pdf-o"></i> PDF</a></li>
......@@ -16,7 +16,7 @@
@endif
<!--Action Button-->
<div class="btn-group">
<button type="button" class="btn btn-primary btn-flat dropdown-toggle" data-toggle="dropdown">Action
<button type="button" class="btn btn-primary btn-flat dropdown-toggle" data-toggle="dropdown">Action
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
......
......@@ -31,10 +31,10 @@
</div><!--form control-->
<div class="form-group">
{{ Form::label('associated-permissions', trans('validation.attributes.backend.access.roles.associated_permissions'), ['class' => 'col-lg-2 control-label']) }}
{{ Form::label('associated_permissions', trans('validation.attributes.backend.access.roles.associated_permissions'), ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::select('associated-permissions', array('all' => trans('labels.general.all'), 'custom' => trans('labels.general.custom')), 'all', ['class' => 'form-control select2 box-size']) }}
{{ Form::select('associated_permissions', array('all' => trans('labels.general.all'), 'custom' => trans('labels.general.custom')), 'all', ['class' => 'form-control select2 box-size']) }}
<div id="available-permissions" class="hidden mt-20" style="width: 700px; height: 200px; overflow-x: hidden; overflow-y: scroll;">
<div class="row">
......
......@@ -31,15 +31,10 @@
</div><!--form control-->
<div class="form-group">
{{ Form::label('associated-permissions', trans('validation.attributes.backend.access.roles.associated_permissions'), ['class' => 'col-lg-2 control-label']) }}
{{ Form::label('associated_permissions', trans('validation.attributes.backend.access.roles.associated_permissions'), ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
@if ($role->id != 1)
{{-- Administrator has to be set to all --}}
{{ Form::select('associated-permissions', ['all' => 'All', 'custom' => 'Custom'], $role->all ? 'all' : 'custom', ['class' => 'form-control select2 box-size']) }}
@else
<span class="label label-success">{{ trans('labels.general.all') }}</span>
@endif
{{ Form::select('associated_permissions', ['all' => 'All', 'custom' => 'Custom'], $role->all ? 'all' : 'custom', ['class' => 'form-control select2 box-size']) }}
<div id="available-permissions" class="hidden mt-20" style="width: 700px; height: 200px; overflow-x: hidden; overflow-y: scroll;">
<div class="row">
......
......@@ -120,7 +120,7 @@
@foreach($roles as $role)
<div>
<label for="role-{{$role->id}}" class="control control--radio">
<input type="radio" value="{{$role->id}}" name="assignees_roles[]" id="role-{{$role->id}}" class="get-role-for-permissions" /> &nbsp;&nbsp;{!! $role->name !!}
<input type="radio" value="{{$role->id}}" name="assignees_roles[]" id="role-{{$role->id}}" class="get-role-for-permissions" {{ $role->id == 3 ? 'checked' : '' }} /> &nbsp;&nbsp;{!! $role->name !!}
<div class="control__indicator"></div>
<a href="#" data-role="role_{{ $role->id }}" class="show-permissions small">
(
......@@ -184,7 +184,7 @@
$(document).ready(function() {
Backend.Access.init();
/**
* This function is used to get clicked element role id and return required result
*/
......@@ -220,6 +220,7 @@
});
});
$("#role-3").click();
});
</script>
@endsection
......@@ -10,7 +10,7 @@
@endsection
@section('content')
{{ Form::open(['route' => 'admin.blogcategories.store', 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'post', 'id' => 'create-permission']) }}
{{ Form::open(['route' => 'admin.blogCategories.store', 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'post', 'id' => 'create-permission']) }}
<div class="box box-info">
<div class="box-header with-border">
......@@ -26,7 +26,7 @@
<div class="form-group">
@include("backend.blogcategories.form")
<div class="edit-form-btn">
{{ link_to_route('admin.blogcategories.index', trans('buttons.general.cancel'), [], ['class' => 'btn btn-danger btn-md']) }}
{{ link_to_route('admin.blogCategories.index', trans('buttons.general.cancel'), [], ['class' => 'btn btn-danger btn-md']) }}
{{ Form::submit(trans('buttons.general.crud.create'), ['class' => 'btn btn-primary btn-md']) }}
<div class="clearfix"></div>
</div>
......
......@@ -10,7 +10,7 @@
@endsection
@section('content')
{{ Form::model($blogcategory, ['route' => ['admin.blogcategories.update', $blogcategory], 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'PATCH', 'id' => 'edit-role']) }}
{{ Form::model($blogcategory, ['route' => ['admin.blogCategories.update', $blogcategory], 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'PATCH', 'id' => 'edit-role']) }}
<div class="box box-info">
<div class="box-header with-border">
......@@ -26,7 +26,7 @@
<div class="form-group">
@include("backend.blogcategories.form")
<div class="edit-form-btn">
{{ link_to_route('admin.blogcategories.index', trans('buttons.general.cancel'), [], ['class' => 'btn btn-danger btn-md']) }}
{{ link_to_route('admin.blogCategories.index', trans('buttons.general.cancel'), [], ['class' => 'btn btn-danger btn-md']) }}
{{ Form::submit(trans('buttons.general.crud.update'), ['class' => 'btn btn-primary btn-md']) }}
<div class="clearfix"></div>
</div>
......
......@@ -70,7 +70,7 @@
processing: true,
serverSide: true,
ajax: {
url: '{{ route("admin.blogcategories.get") }}',
url: '{{ route("admin.blogCategories.get") }}',
type: 'post'
},
columns: [
......
<!--Action Button-->
@if(Active::checkUriPattern('admin/blogcategories'))
@if(Active::checkUriPattern('admin/blogCategories'))
<div class="btn-group">
<button type="button" class="btn btn-warning btn-flat dropdown-toggle" data-toggle="dropdown">Export
<span class="caret"></span>
......@@ -21,9 +21,9 @@
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="{{route('admin.blogcategories.index')}}"><i class="fa fa-list-ul"></i> {{trans('menus.backend.blogcategories.all')}}</a></li>
<li><a href="{{route('admin.blogCategories.index')}}"><i class="fa fa-list-ul"></i> {{trans('menus.backend.blogcategories.all')}}</a></li>
@permission('create-blog-category')
<li><a href="{{route('admin.blogcategories.create')}}"><i class="fa fa-plus"></i> {{trans('menus.backend.blogcategories.create')}}</a></li>
<li><a href="{{route('admin.blogCategories.create')}}"><i class="fa fa-plus"></i> {{trans('menus.backend.blogcategories.create')}}</a></li>
@endauth
</ul>
</div>
\ No newline at end of file
......@@ -35,7 +35,7 @@
{{ Form::label('featured_image', trans('validation.attributes.backend.blogs.image'), ['class' => 'col-lg-2 control-label required']) }}
@if(!empty($blog->featured_image))
<div class="col-lg-1">
<img src="/img/backend/blog_images/{{$blog->featured_image}}" height="80" width="80">
<img src="{{ Storage::disk('public')->url('img/blog/' . $blog->featured_image) }}" height="80" width="80">
</div>
<div class="col-lg-5">
<div class="custom-file-input">
......
......@@ -10,7 +10,7 @@
@endsection
@section('content')
{{ Form::open(['route' => 'admin.blogtags.store', 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'post', 'id' => 'create-permission']) }}
{{ Form::open(['route' => 'admin.blogTags.store', 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'post', 'id' => 'create-blogtags']) }}
<div class="box box-info">
<div class="box-header with-border">
......@@ -26,7 +26,7 @@
<div class="form-group">
@include("backend.blogtags.form")
<div class="edit-form-btn">
{{ link_to_route('admin.blogtags.index', trans('buttons.general.cancel'), [], ['class' => 'btn btn-danger btn-md']) }}
{{ link_to_route('admin.blogTags.index', trans('buttons.general.cancel'), [], ['class' => 'btn btn-danger btn-md']) }}
{{ Form::submit(trans('buttons.general.crud.create'), ['class' => 'btn btn-primary btn-md']) }}
<div class="clearfix"></div>
</div>
......
......@@ -10,7 +10,7 @@
@endsection
@section('content')
{{ Form::model($blogtag, ['route' => ['admin.blogtags.update', $blogtag], 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'PATCH', 'id' => 'edit-role']) }}
{{ Form::model($blogtag, ['route' => ['admin.blogTags.update', $blogtag], 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'PATCH', 'id' => 'edit-blogtags']) }}
<div class="box box-info">
<div class="box-header with-border">
......@@ -26,7 +26,7 @@
<div class="form-group">
@include("backend.blogtags.form")
<div class="edit-form-btn">
{{ link_to_route('admin.blogtags.index', trans('buttons.general.cancel'), [], ['class' => 'btn btn-danger btn-md']) }}
{{ link_to_route('admin.blogTags.index', trans('buttons.general.cancel'), [], ['class' => 'btn btn-danger btn-md']) }}
{{ Form::submit(trans('buttons.general.crud.update'), ['class' => 'btn btn-primary btn-md']) }}
<div class="clearfix"></div>
</div>
......
......@@ -70,7 +70,7 @@
processing: true,
serverSide: true,
ajax: {
url: '{{ route("admin.blogtags.get") }}',
url: '{{ route("admin.blogTags.get") }}',
type: 'post'
},
columns: [
......
<!--Action Button-->
@if(Active::checkUriPattern('admin/blogtags'))
@if(Active::checkUriPattern('admin/blogTags'))
<div class="btn-group">
<button type="button" class="btn btn-warning btn-flat dropdown-toggle" data-toggle="dropdown">Export
<span class="caret"></span>
......@@ -21,9 +21,9 @@
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="{{route('admin.blogtags.index')}}"><i class="fa fa-list-ul"></i> {{trans('menus.backend.blogtags.all')}}</a></li>
<li><a href="{{route('admin.blogTags.index')}}"><i class="fa fa-list-ul"></i> {{trans('menus.backend.blogtags.all')}}</a></li>
@permission('create-blog-tag')
<li><a href="{{route('admin.blogtags.create')}}"><i class="fa fa-plus"></i> {{trans('menus.backend.blogtags.create')}}</a></li>
<li><a href="{{route('admin.blogTags.create')}}"><i class="fa fa-plus"></i> {{trans('menus.backend.blogtags.create')}}</a></li>
@endauth
</ul>
</div>
......
<?php //dd(getMenuItems());
<?php //dd(getMenuItems());
?>
<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar">
......@@ -90,15 +90,15 @@
<ul class="treeview-menu {{ active_class(Active::checkUriPattern('admin/blog*'), 'menu-open') }}" style="display: none; {{ active_class(Active::checkUriPattern('admin/blog*'), 'display: block;') }}">
@permission('view-blog-category')
<li class="{{ active_class(Active::checkUriPattern('admin/blogcategories*')) }}">
<a href="{{ route('admin.blogcategories.index') }}">
<li class="{{ active_class(Active::checkUriPattern('admin/blogCategories*')) }}">
<a href="{{ route('admin.blogCategories.index') }}">
<span>{{ trans('menus.backend.blogcategories.management') }}</span>
</a>
</li>
@endauth
@permission('view-blog-tag')
<li class="{{ active_class(Active::checkUriPattern('admin/blogtags*')) }}">
<a href="{{ route('admin.blogtags.index') }}">
<li class="{{ active_class(Active::checkUriPattern('admin/blogTags*')) }}">
<a href="{{ route('admin.blogTags.index') }}">
<span>{{ trans('menus.backend.blogtags.management') }}</span>
</a>
</li>
......@@ -111,15 +111,16 @@
</li>
@endauth
</ul>
@permission('view-faq')
</li>
@endauth
@permission('view-faq')
<li class="{{ active_class(Active::checkUriPattern('admin/faqs*')) }}">
<a href="{{ route('admin.faqs.index')}}">
<i class="fa fa-question-circle"></i>
<span>{{ trans('labels.backend.faqs.title') }}</span>
</a>
</li>
@endauth
</li>
@endauth
<li class="{{ active_class(Active::checkUriPattern('admin/log-viewer*')) }} treeview">
......
......@@ -24,7 +24,7 @@
<th>{{ trans('labels.backend.pages.table.title') }}</th>
<th>{{ trans('labels.backend.pages.table.status') }}</th>
<th>{{ trans('labels.backend.pages.table.createdat') }}</th>
<th>{{ trans('labels.backend.pages.table.updatedat') }}</th>
<th>{{ trans('labels.backend.pages.table.createdby') }}</th>
<th>{{ trans('labels.general.actions') }}</th>
</tr>
</thead>
......@@ -77,10 +77,10 @@
{data: 'title', name: '{{config('module.pages.table')}}.title'},
{data: 'status', name: '{{config('module.pages.table')}}.status'},
{data: 'created_at', name: '{{config('module.pages.table')}}.created_at'},
{data: 'updated_at', name: '{{config('module.pages.table')}}.updated_at'},
{data: 'created_by', name: '{{config('access.users_table')}}.first_name'},
{data: 'actions', name: 'actions', searchable: false, sortable: false}
],
order: [[3, "asc"]],
order: [[1, "asc"]],
searchDelay: 500,
dom: 'lBfrtip',
buttons: {
......
......@@ -4,9 +4,9 @@
* Blogs Categories Management
*/
Route::group(['namespace' => 'BlogCategories'], function () {
Route::resource('blogcategories', 'BlogCategoriesController', ['except' => ['show']]);
Route::resource('blogCategories', 'BlogCategoriesController', ['except' => ['show']]);
//For DataTables
Route::post('blogcategories/get', 'BlogCategoriesTableController')
->name('blogcategories.get');
Route::post('blogCategories/get', 'BlogCategoriesTableController')
->name('blogCategories.get');
});
......@@ -4,9 +4,9 @@
* Blogs Tags Management
*/
Route::group(['namespace' => 'BlogTags'], function () {
Route::resource('blogtags', 'BlogTagsController', ['except' => ['show']]);
Route::resource('blogTags', 'BlogTagsController', ['except' => ['show']]);
//For DataTables
Route::post('blogtags/get', 'BlogTagsTableController')
->name('blogtags.get');
Route::post('blogTags/get', 'BlogTagsTableController')
->name('blogTags.get');
});
......@@ -6,5 +6,5 @@
Route::group(['namespace' => 'Settings'], function () {
Route::resource('settings', 'SettingsController', ['except' => ['show', 'create', 'save', 'index', 'destroy']]);
Route::post('removeicon', 'SettingsController@removeIcon')->name('removeicon');
Route::post('removeicon/{setting}', 'SettingsLogoController@destroy')->name('removeIcon');
});
......@@ -2,11 +2,101 @@
namespace Tests;
use App\Models\Access\Role\Role;
use App\Models\Access\User\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
abstract class BrowserKitTestCase extends BaseTestCase
{
use CreatesApplication;
use CreatesApplication,
RefreshDatabase;
public $baseUrl = 'http://localhost:8000';
/**
* @var
*/
public $baseUrl;
/**
* @var
*/
protected $admin;
/**
* @var
*/
protected $executive;
/**
* @var
*/
protected $user;
/**
* @var
*/
protected $adminRole;
/**
* @var
*/
protected $executiveRole;
/**
* @var
*/
protected $userRole;
public function setUp()
{
parent::setUp();
$this->baseUrl = config('app.url', 'http://localhost:8000');
// Set up the database
Artisan::call('migrate:refresh');
Artisan::call('db:seed');
/*
* Create class properties to be used in tests
*/
$this->admin = User::find(1);
$this->executive = User::find(2);
$this->user = User::find(3);
$this->adminRole = Role::find(1);
$this->executiveRole = Role::find(2);
$this->userRole = Role::find(3);
}
public function tearDown()
{
$this->beforeApplicationDestroyed(function () {
DB::disconnect();
});
parent::tearDown();
}
/**
* Check if User is logged in or not.
*
* @return bool true or false
*/
protected function assertLoggedIn()
{
$this->assertTrue(Auth::check());
}
/**
* Check if User is logged out or not.
*
* @return bool true or false
*/
protected function assertLoggedOut()
{
$this->assertFalse(Auth::check());
}
}
<?php
namespace Tests\Feature\Api\V1;
use Illuminate\Support\Facades\Auth;
use Tests\TestCase;
class LoginTest extends TestCase
{
/** @test */
public function users_can_login_through_api()
{
$res = $this->json('POST', '/api/v1/auth/login', [
'email' => $this->user->email,
'password' => '1234',
])
->assertStatus(200)
->assertJsonStructure([
'message',
'token',
]);
}
}
<?php
namespace Tests\Feature\Auth;
use App\Events\Frontend\Auth\UserLoggedIn;
use App\Models\Access\User\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use Tests\BrowserKitTestCase;
class LoginTest extends BrowserKitTestCase
{
/** @test */
public function login_page_loads_properly()
{
$this->visit('/login')
->see('Email')
->see('Password')
->see('Login')
->dontSee('You are logged in!');
}
/** @test */
public function login_fails_when_a_required_field_is_not_filled_in()
{
$this->visit('/login')
->type('', 'email')
->type('', 'password')
->press('Login')
->seePageIs('/login')
->see('The email field is required.')
->see('The password field is required.');
}
/** @test */
public function login_fails_when_password_is_incorrect()
{
$this->visit('/login')
->type('admin@admin.com', 'email')
->type('invalidpass', 'password')
->press('Login')
->seePageIs('/login')
->see('These credentials do not match our records.');
}
/** @test */
public function login_failure_with_wrong_inputs()
{
$this->visit('/login')
->type('wrongusername@wrongpassword.com', 'email')
->type('wrongpassword', 'password')
->press('Login')
->seePageIs('/login')
->see('These credentials do not match our records.');
}
/** @test */
public function unconfirmed_users_can_not_logIn()
{
Auth::logout();
config(['access.users.requires_approval' => false]);
// Create default user to test with
$unconfirmed = factory(User::class)->states('unconfirmed')->create();
$unconfirmed->attachRole(3); //User
$this->visit('/login')
->type($unconfirmed->email, 'email')
->type('secret', 'password')
->press('Login')
->seePageIs('/login')
->see('Your account is not confirmed.');
}
/** @test **/
public function inactive_users_can_not_login()
{
Auth::logout();
// Create default user to test with
$inactive = factory(User::class)->states('confirmed', 'inactive')->create();
$inactive->attachRole(3); //User
$this->visit('/login')
->type($inactive->email, 'email')
->type('secret', 'password')
->press('Login')
->seePageIs('/login')
->see('Your account has been deactivated.');
}
/** @test */
public function users_can_login()
{
// Make sure our events are fired
Event::fake();
Auth::logout();
//User Test
$this->visit('/login')
->type($this->user->email, 'email')
->type('1234', 'password')
->press('Login')
->see($this->user->name)
->seePageIs('/dashboard');
$this->assertLoggedIn();
Auth::logout();
//Admin Test
$this->visit('/login')
->type($this->admin->email, 'email')
->type('1234', 'password')
->press('Login')
->seePageIs('/admin/dashboard')
->see($this->admin->first_name)
->see('Access Management');
$this->assertLoggedIn();
Event::assertDispatched(UserLoggedIn::class);
}
}
<?php
namespace Tests\Feature\Auth;
use App\Events\Frontend\Auth\UserRegistered;
use App\Models\Access\User\User;
use App\Notifications\Frontend\Auth\UserNeedsConfirmation;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification;
use Tests\BrowserKitTestCase;
class RegistrationTest extends BrowserKitTestCase
{
/** @test */
public function registration_page_loads_properly()
{
$this->visit('/register')
->see('first_name')
->see('last_name')
->see('email')
->see('password')
->see('is_term_accept')
->see('Register');
}
/** @test */
public function registration_fails_when_a_required_field_is_not_filled_in()
{
$this->visit('/register')
->type('', 'first_name')
->type('', 'last_name')
->type('', 'email')
->type('', 'password')
->press('Register')
->seePageIs('/register')
->see('The first name field is required.')
->see('The last name field is required.')
->see('The email field is required.')
->see('The password field is required.')
->see('The is term accept field is required.');
}
/**
* Test the registration form
* Test it works with confirming email on or off, and that the confirm email notification is sent
* Note: Captcha is disabled by default in phpunit.xml.
*/
/** @test */
public function user_can_register()
{
// Make sure our events are fired
Event::fake();
config(['access.users.confirm_email' => false]);
config(['access.users.requires_approval' => false]);
$this->visit('/register')
->type('John', 'first_name')
->type('Doe', 'last_name')
->type('john.doe@example.com', 'email')
->type('Viral@1234', 'password')
->type('Viral@1234', 'password_confirmation')
->check('is_term_accept')
->press('Register')
->seePageIs('/')
->seeInDatabase(config('access.users_table'),
[
'email' => 'john.doe@example.com',
'first_name' => 'John',
'last_name' => 'Doe',
'confirmed' => 1,
]);
Event::assertDispatched(UserRegistered::class);
}
/**
* Test the registration form when account are set to be pending an approval
* ensure they are registered but not confirmed.
*/
/** @test */
public function registration_for_pending_approval()
{
Event::fake();
Notification::fake();
// Set registration to pending approval
config(['access.users.confirm_email' => false]);
config(['access.users.requires_approval' => true]);
$this->visit('/register')
->type('first name', 'first_name')
->type('last name', 'last_name')
->type('test@example.com', 'email')
->type('Viral@1234', 'password')
->type('Viral@1234', 'password_confirmation')
->check('is_term_accept')
->press('Register')
->see('Your account was successfully created and is pending approval. An e-mail will be sent when your account is approved.')
->see('Login')
->seePageIs('/')
->seeInDatabase(config('access.users_table'),
[
'email' => 'test@example.com',
'first_name' => 'first name',
'last_name' => 'last name',
'confirmed' => 0,
]);
// Get the user that was inserted into the database
$user = User::where('email', 'test@example.com')->first();
Notification::assertNotSentTo([$user], UserNeedsConfirmation::class);
Event::assertDispatched(UserRegistered::class);
}
}
<?php
namespace Tests\Feature\Auth;
use App\Notifications\Frontend\Auth\UserNeedsPasswordReset;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Notification;
use Tests\BrowserKitTestCase;
class ResetPasswordTest extends BrowserKitTestCase
{
/** @test */
public function forgot_password_page_loads_properly()
{
$this->visit('/password/reset')
->see('Email')
->see('Reset Password');
}
/** @test **/
public function forgot_password_fails_when_a_required_field_is_not_filled_in()
{
$this->visit('/password/reset')
->type('', 'email')
->press('Send Password Reset Link')
->seePageIs('/password/reset')
->see('The email field is required.');
}
/** @test **/
public function users_can_request_a_password_reset_link()
{
Notification::fake();
$this->visit('password/reset')
->type($this->user->email, 'email')
->press('Send Password Reset Link')
->seePageIs('password/reset')
->see('We have e-mailed your password reset link!')
->seeInDatabase('password_resets', ['email' => $this->user->email]);
Notification::assertSentTo(
[$this->user],
UserNeedsPasswordReset::class
);
}
/** @test **/
public function reset_password_fails_when_a_required_field_is_not_filled_in()
{
$token = $this->app->make('auth.password.broker')->createToken($this->user);
$this->visit('password/reset/'.$token)
->see($this->user->email)
->type('', 'password')
->type('', 'password_confirmation')
->press('Reset Password')
->see('The password field is required.');
}
/** @test **/
public function users_can_reset_password()
{
$token = $this->app->make('auth.password.broker')->createToken($this->user);
$this->visit('password/reset/'.$token)
->see($this->user->email)
->type('12345678', 'password')
->type('12345678', 'password_confirmation')
->press('Reset Password')
->see($this->user->first_name);
}
}
<?php
namespace Tests\Feature;
use Tests\BrowserKitTestCase;
class AuthTest extends BrowserKitTestCase
{
/** @test */
public function login_page_loads_properly()
{
$this->visit('/login')
->see('Email')
->see('Password')
->see('Login')
->dontSee('You are logged in!');
}
/** @test */
public function login_failure_without_inputs()
{
$this->visit('/login')
->press('Login')
->seePageIs('/login')
->see('The email field is required.')
->see('The password field is required.');
}
/** @test */
/*public function test_login_failure_with_wrong_inputs()
{
$this->visit("/login")
->type('wrongusername@wrongpassword.com', 'email')
->type('wrongpassword', 'password')
->press('Login')
->seePageIs('/login')
->see('These credentials do not match our records.');
}*/
/** @test */
public function users_can_login()
{
//$this->createUser();
$this->visit('/login')
->type('user@user.com', 'email')
->type('1234', 'password')
//->press('Login')
->seePageIs('/login');
}
}
<?php
namespace Tests\Feature\Backend;
use App\Events\Backend\Access\User\UserPasswordChanged;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
class ChangePasswordTest extends TestCase
{
/** @test */
public function a_user_require_old_password_to_change_password()
{
$data = [];
$data['old_password'] = '12345';
$data['password'] = 'Viral@1234';
$data['password_confirmation'] = 'Viral@1234';
$this->withExceptionHandling()
->actingAs($this->admin)
->patch(route('admin.access.user.change-password', $this->admin), $data)
->assertSessionHas(['flash_danger' => trans('exceptions.backend.access.users.change_mismatch')]);
}
/** @test */
/*public function a_user_require_strong_password_to_change_password()
{
$data = [];
$data['old_password'] = '1234';
$data['password'] = '12345678';
$data['password_confirmation'] = '12345678';
$this->withExceptionHandling()
->actingAs($this->executive)
->patch(route('admin.access.user.change-password', $this->executive), $data)
->assertSessionHas('The given data was invalid.');
}*/
/** @test */
public function a_user_can_change_password()
{
Event::fake();
$data = [];
$data['old_password'] = '1234';
$data['password'] = 'Viral@1234';
$data['password_confirmation'] = 'Viral@1234';
$this->actingAs($this->admin)
->patch(route('admin.access.user.change-password', $this->admin), $data)
->assertSessionHas(['flash_success' => trans('alerts.backend.users.updated_password')]);
Event::assertDispatched(UserPasswordChanged::class);
}
}
<?php
namespace Tests\Feature\Backend\History;
use Tests\BrowserKitTestCase;
/**
* Class HistoryLogTest.
*/
class HistoryLogTest extends BrowserKitTestCase
{
/** @test **/
public function history_log_by_type_name_function()
{
$this->actingAs($this->admin);
history()
->withType('User')
->withText(trans('history.backend.users.created').$this->user->name)
->withEntity($this->user->id)
->withIcon('plus')
->withClass('bg-green')
->log();
$this->seeInDatabase('history',
[
'type_id' => 1,
'user_id' => $this->admin->id,
'entity_id' => $this->user->id,
'icon' => 'plus',
'class' => 'bg-green',
'text' => trans('history.backend.users.created').$this->user->name,
])
->visit('/admin/dashboard')
->see('<strong>'.$this->admin->name.'</strong> '.trans('history.backend.users.created').$this->user->name);
}
/** @test **/
public function history_log_By_TypeId_Function()
{
$this->actingAs($this->admin);
history()
->withType(1)
->withText(trans('history.backend.users.created').$this->user->name)
->withEntity($this->user->id)
->withIcon('plus')
->withClass('bg-green')
->log();
$this->seeInDatabase('history',
[
'type_id' => 1,
'user_id' => $this->admin->id,
'entity_id' => $this->user->id,
'icon' => 'plus',
'class' => 'bg-green',
'text' => trans('history.backend.users.created').$this->user->name,
])
->visit('/admin/dashboard')
->see('<strong>'.$this->admin->name.'</strong> '.trans('history.backend.users.created').$this->user->name);
}
}
<?php
namespace Tests\Feature\Backend\History;
use App\Models\Access\User\User;
use Tests\BrowserKitTestCase;
/**
* Class HistoryRenderEntityTest.
*/
class HistoryRenderEntityTest extends BrowserKitTestCase
{
/** @test **/
public function users_can_see_history_of_entity()
{
$this->actingAs($this->admin);
$test_user = factory(User::class)->create();
history()
->withType('User')
->withText('trans("history.backend.users.created") '.$this->user->name)
->withEntity($this->user->id)
->withIcon('plus')
->withClass('bg-green')
->log();
history()
->withType('User')
->withText('trans("history.backend.users.updated") '.$this->user->name)
->withEntity($this->user->id)
->withIcon('pencil')
->withClass('bg-blue')
->log();
history()
->withType('User')
->withText('trans("history.backend.users.deleted") '.$this->user->name)
->withEntity($this->user->id)
->withIcon('trash')
->withClass('bg-red')
->log();
history()
->withType('User')
->withText('trans("history.backend.roles.created") '.$test_user->name)
->withEntity($test_user->id)
->withIcon('plus')
->withClass('bg-red')
->log();
history()
->withType('User')
->withText('trans("history.backend.roles.updated") '.$test_user->name)
->withEntity($test_user->id)
->withIcon('pencil')
->withClass('bg-red')
->log();
history()
->withType('User')
->withText('trans("history.backend.roles.deleted") '.$test_user->name)
->withEntity($test_user->id)
->withIcon('trash')
->withClass('bg-red')
->log();
$this->visit('/admin/access/user/'.$this->user->id)
->see('<strong>'.$this->admin->name.'</strong> created user '.$this->user->name)
->see('<strong>'.$this->admin->name.'</strong> updated user '.$this->user->name)
->see('<strong>'.$this->admin->name.'</strong> deleted user '.$this->user->name)
->dontSee('<strong>'.$this->admin->name.'</strong> created user '.$test_user->name)
->dontSee('<strong>'.$this->admin->name.'</strong> updated user '.$test_user->name)
->dontSee('<strong>'.$this->admin->name.'</strong> deleted user '.$test_user->name);
}
}
<?php
namespace Tests\Feature\Backend\History;
use Tests\BrowserKitTestCase;
/**
* Class HistoryRenderTest.
*/
class HistoryRenderTest extends BrowserKitTestCase
{
/** @test **/
public function admin_users_can_see_history_on_dashboard()
{
$this->actingAs($this->admin);
history()
->withType('User')
->withText(trans('history.backend.users.created').$this->user->name)
->withEntity($this->user->id)
->withIcon('plus')
->withClass('bg-green')
->log();
$this->visit('/admin/dashboard')
->see('<strong>'.$this->admin->name.'</strong> '.trans('history.backend.users.created').$this->user->name);
}
/** @test **/
public function admin_users_can_see_history_on_user_show_page()
{
$this->actingAs($this->admin);
history()
->withType('User')
->withText(trans('history.backend.users.created').$this->user->name)
->withEntity($this->user->id)
->withIcon('plus')
->withClass('bg-green')
->log();
$this->visit('/admin/access/user/3')
->see('<strong>'.$this->admin->name.'</strong> '.trans('history.backend.users.created').$this->user->name);
}
}
<?php
namespace Tests\Feature\Backend;
use Tests\BrowserKitTestCase;
/**
* Class LogViewerRouteTest.
*/
class LogViewerRouteTest extends BrowserKitTestCase
{
/** @test **/
public function admin_users_can_see_logviewer_dashboard()
{
$this->actingAs($this->admin)
->visit('/admin/log-viewer')
->see('Log Viewer');
}
/** @test **/
public function admin_users_can_see_logviewer_list()
{
$this->actingAs($this->admin)
->visit('/admin/log-viewer/logs')
->see('Logs');
}
/** @test **/
public function admin_users_can_see_logviewer_single_date()
{
$this->actingAs($this->admin)
->visit('/admin/log-viewer/logs/'.date('Y-m-d'))
->see('Log ['.date('Y-m-d').']');
}
/** @test **/
public function admin_users_can_see_logviewer_single_date_type()
{
$this->actingAs($this->admin)
->visit('/admin/log-viewer/logs/'.date('Y-m-d').'/error')
->see('Log ['.date('Y-m-d').']');
}
}
<?php
namespace Tests\Feature\Backend;
use App\Models\BlogCategories\BlogCategory;
use Tests\TestCase;
class ManageBlogCategoriesTest extends TestCase
{
/** @test */
public function a_user_can_view_blog_categories_index_page()
{
$this->actingAs($this->admin)
->get(route('admin.blogCategories.index'))
->assertViewIs('backend.blogcategories.index')
->assertSee(trans('labels.backend.blogcategories.management'))
->assertSee(trans('labels.backend.blogcategories.table.title'))
->assertSee(trans('labels.backend.blogcategories.table.status'))
->assertSee('Export')
->assertSee('Action');
}
/** @test */
public function a_user_can_create_a_blog_category()
{
$this->actingAs($this->admin);
$category = make(BlogCategory::class);
$this->post(route('admin.blogCategories.store'), $category->toArray());
$this->assertDatabaseHas(config('module.blog_categories.table'), ['name' => $category->name]);
}
/** @test */
public function a_blog_category_requires_a_name_while_creating()
{
$this->actingAs($this->admin)->withExceptionHandling();
$category = make(BlogCategory::class, ['name' => '']);
$this->post(route('admin.blogCategories.store'), $category->toArray())
->assertSessionHasErrors('name');
}
/** @test */
public function a_blog_category_requires_a_name_while_updating()
{
$this->actingAs($this->admin)->withExceptionHandling();
$category = create(BlogCategory::class);
$this->patch(route('admin.blogCategories.update', $category), ['name' => ''])
->assertSessionHasErrors('name');
}
/** @test */
public function a_user_can_update_a_blog_category()
{
$this->actingAs($this->admin);
$category = create(BlogCategory::class);
$this->patch(route('admin.blogCategories.update', $category), ['name' => 'New Category']);
$this->assertDatabaseHas(config('module.blog_categories.table'), ['name' => 'New Category', 'id' => $category->id]);
}
/** @test */
public function a_user_can_delete_a_blog_category()
{
$this->actingAs($this->admin);
$category = create(BlogCategory::class);
$this->delete(route('admin.blogCategories.destroy', $category));
$this->assertDatabaseMissing(config('module.blog_categories.table'), ['name' => $category->name, 'id' => $category->id, 'deleted_at' => null]);
}
}
<?php
namespace Tests\Feature\Backend;
use App\Models\BlogTags\BlogTag;
use Tests\TestCase;
class ManageBlogTagsTest extends TestCase
{
/** @test */
public function a_user_can_view_blog_tags_index_page()
{
$this->actingAs($this->admin)
->get(route('admin.blogTags.index'))
->assertViewIs('backend.blogtags.index')
->assertSee(trans('labels.backend.blogtags.management'))
->assertSee(trans('labels.backend.blogtags.table.title'))
->assertSee(trans('labels.backend.blogtags.table.status'))
->assertSee('Export')
->assertSee('Action');
}
/** @test */
public function a_user_can_create_a_blog_tag()
{
$this->actingAs($this->admin);
$tag = make(BlogTag::class);
$this->post(route('admin.blogTags.store'), $tag->toArray());
$this->assertDatabaseHas(config('module.blog_tags.table'), ['name' => $tag->name]);
}
/** @test */
public function a_blog_tag_requires_a_name_while_creating()
{
$this->actingAs($this->admin)->withExceptionHandling();
$tag = make(BlogTag::class, ['name' => '']);
$this->post(route('admin.blogTags.store'), $tag->toArray())
->assertSessionHasErrors('name');
}
/** @test */
public function a_blog_tag_requires_a_name_while_updating()
{
$this->actingAs($this->admin)->withExceptionHandling();
$tag = create(BlogTag::class);
$this->patch(route('admin.blogTags.update', $tag), ['name' => ''])
->assertSessionHasErrors('name');
}
/** @test */
public function a_user_can_update_a_blog_tag()
{
$this->actingAs($this->admin);
$tag = create(BlogTag::class);
$this->patch(route('admin.blogTags.update', $tag), ['name' => 'New Tag']);
$this->assertDatabaseHas(config('module.blog_tags.table'), ['name' => 'New Tag', 'id' => $tag->id]);
}
/** @test */
public function a_user_can_delete_a_blog_tag()
{
$this->actingAs($this->admin);
$tag = create(BlogTag::class);
$this->delete(route('admin.blogTags.destroy', $tag));
$this->assertDatabaseMissing(config('module.blog_tags.table'), ['name' => $tag->name, 'id' => $tag->id, 'deleted_at' => null]);
}
}
<?php
namespace Tests\Feature\Backend;
use App\Models\Blogs\Blog;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class ManageBlogsTest extends TestCase
{
use WithFaker;
protected $blog;
protected $categories;
protected $tags;
public function setUp()
{
parent::setUp();
$this->actingAs($this->admin);
$this->blog = create(Blog::class);
$this->categories = [$this->faker->word, $this->faker->word];
$this->tags = [$this->faker->word, $this->faker->word];
}
/** @test */
public function a_user_can_view_blogs_index_page()
{
$this->actingAs($this->admin)
->get(route('admin.blogs.index'))
->assertViewIs('backend.blogs.index')
->assertSee(trans('labels.backend.blogs.management'))
->assertSee(trans('labels.backend.blogs.table.title'))
->assertSee(trans('labels.backend.blogs.table.publish'))
->assertSee(trans('labels.backend.blogs.table.createdby'))
->assertSee(trans('labels.backend.blogs.table.createdat'))
->assertSee(trans('labels.backend.blogs.table.status'))
->assertSee('Export')
->assertSee('Action');
}
/** @test */
public function a_user_can_create_a_blog()
{
$blog = make(Blog::class, [
'featured_image' => UploadedFile::fake()->image('logo.jpg'),
'categories' => $this->categories,
'tags' => $this->tags,
]);
$this->post(route('admin.blogs.store'), $blog->toArray());
$this->assertDatabaseHas(config('module.blogs.table'), ['name' => $blog->name, 'status' => $blog->status]);
//Assert Tags have been saved
$this->assertDatabaseHas(config('module.blog_tags.table'), ['name' => $this->tags[0]]);
$this->assertDatabaseHas(config('module.blog_tags.table'), ['name' => $this->tags[1]]);
//Assert Categories have been saved
$this->assertDatabaseHas(config('module.blog_categories.table'), ['name' => $this->categories[0]]);
$this->assertDatabaseHas(config('module.blog_categories.table'), ['name' => $this->categories[1]]);
}
public function makeBlog($overrides = [])
{
$this->withExceptionHandling();
$blog = make(Blog::class, $overrides);
return $blog;
}
/** @test */
public function it_requires_name_while_creating()
{
$blog = $this->makeBlog(['name' => '']);
$this->post(route('admin.blogs.store'), $blog->toArray())
->assertSessionHasErrors('name');
}
/** @test */
public function it_requires_content_while_creating()
{
$blog = $this->makeBlog(['content' => '']);
$this->post(route('admin.blogs.store'), $blog->toArray())
->assertSessionHasErrors('content');
}
/** @test */
public function it_requires_featured_image_while_creating()
{
$blog = $this->makeBlog(['featured_image' => '']);
$this->post(route('admin.blogs.store'), $blog->toArray())
->assertSessionHasErrors('featured_image');
}
/** @test */
public function it_requires_categories_while_creating()
{
$blog = $this->makeBlog(['categories' => '']);
$this->post(route('admin.blogs.store'), $blog->toArray())
->assertSessionHasErrors('categories');
}
/** @test */
public function it_requires_tags_while_creating()
{
$blog = $this->makeBlog(['tags' => '']);
$this->post(route('admin.blogs.store'), $blog->toArray())
->assertSessionHasErrors('tags');
}
/** @test */
public function it_can_store_featured_image()
{
$blog = make(Blog::class, [
'featured_image' => UploadedFile::fake()->image('logo.jpg'),
'categories' => $this->categories,
'tags' => $this->tags,
]);
$this->post(route('admin.blogs.store'), $blog->toArray());
$stored_blog = Blog::find(2);
Storage::disk('public')->assertExists('img/blog/'.$stored_blog->featured_image);
}
/** @test */
public function it_requires_name_while_updating()
{
$this->withExceptionHandling();
$this->blog->name = '';
$this->patch(route('admin.blogs.update', $this->blog), $this->blog->toArray())
->assertSessionHasErrors('name');
}
/** @test */
public function it_requires_content_while_updating()
{
$this->withExceptionHandling();
$this->blog->content = '';
$this->patch(route('admin.blogs.update', $this->blog), $this->blog->toArray())
->assertSessionHasErrors('content');
}
/** @test */
public function it_requires_categories_while_updating()
{
$this->withExceptionHandling();
$this->patch(route('admin.blogs.update', $this->blog), $this->blog->toArray())
->assertSessionHasErrors('categories');
}
/** @test */
public function it_requires_tags_while_updating()
{
$this->withExceptionHandling();
$this->patch(route('admin.blogs.update', $this->blog), $this->blog->toArray())
->assertSessionHasErrors('tags');
}
/** @test */
public function a_user_can_update_blog()
{
$blog = make(Blog::class, [
'featured_image' => UploadedFile::fake()->image('logo.jpg'),
'name' => 'Changed Name',
'categories' => $this->categories,
'tags' => $this->tags,
]);
$this->patch(route('admin.blogs.update', $this->blog), $blog->toArray());
$this->assertDatabaseHas(config('module.blogs.table'), ['id' => $this->blog->id, 'name' => 'Changed Name']);
}
/** @test */
public function a_user_can_delete_a_blog()
{
$this->delete(route('admin.blogs.destroy', $this->blog));
$this->assertDatabaseMissing(config('module.blogs.table'), ['id' => $this->blog->id, 'deleted_at' => null]);
}
}
<?php
namespace Tests\Feature\Backend;
use App\Models\Faqs\Faq;
use Tests\TestCase;
class ManageFaqsTest extends TestCase
{
/** @test */
public function a_user_can_view_faqs_index_page()
{
$this->actingAs($this->admin)
->get(route('admin.faqs.index'))
->assertViewIs('backend.faqs.index')
->assertSee(trans('labels.backend.faqs.management'))
->assertSee(trans('labels.backend.faqs.table.question'))
->assertSee(trans('labels.backend.faqs.table.answer'))
->assertSee(trans('labels.backend.faqs.table.status'))
->assertSee('Export')
->assertSee('Action');
}
/** @test */
public function a_user_can_create_faq()
{
$faq = make(Faq::class);
$this->actingAs($this->admin)
->post(route('admin.faqs.store'), $faq->toArray());
$this->assertDatabaseHas(config('module.faqs.table'), ['question' => $faq->question, 'answer' => $faq->answer]);
}
/** @test */
public function it_requires_question_while_creating()
{
$faq = make(Faq::class, ['question' => '']);
$this->actingAs($this->admin)
->withExceptionHandling()
->post(route('admin.faqs.store'), $faq->toArray())
->assertSessionHasErrors('question');
}
/** @test */
public function it_requires_answer_while_creating()
{
$faq = make(Faq::class, ['answer' => '']);
$this->actingAs($this->admin)
->withExceptionHandling()
->post(route('admin.faqs.store'), $faq->toArray())
->assertSessionHasErrors('answer');
}
/** @test */
public function it_requires_question_while_updating()
{
$faq = create(Faq::class);
$this->actingAs($this->admin)
->withExceptionHandling()
->patch(route('admin.faqs.update', $faq), ['question' => '', 'answer' => $faq->answer])
->assertSessionHasErrors('question');
}
/** @test */
public function it_requires_answer_while_updating()
{
$faq = create(Faq::class);
$this->actingAs($this->admin)
->withExceptionHandling()
->patch(route('admin.faqs.update', $faq), ['question' => $faq->question, 'answer' => ''])
->assertSessionHasErrors('answer');
}
/** @test */
public function a_user_can_update_faq()
{
$faq = create(Faq::class);
$changed_question = 'What is Life?';
$changed_answer = $faq->answer;
$this->actingAs($this->admin)
->patch(route('admin.faqs.update', $faq), ['question' => $changed_question, 'answer' => $changed_answer]);
$this->assertDatabaseHas(config('module.faqs.table'), ['id' => $faq->id, 'question' => $changed_question, 'answer' => $changed_answer]);
}
/** @test */
public function a_user_can_delete_faq()
{
$faq = create(Faq::class);
$this->actingAs($this->admin)
->delete(route('admin.faqs.destroy', $faq));
$this->assertDatabaseMissing(config('module.faqs.table'), ['id' => $faq->id, 'deleted_at' => null]);
}
}
<?php
namespace Tests\Feature\Backend;
use App\Models\Page\Page;
use Tests\TestCase;
class ManagePagesTest extends TestCase
{
/** @test */
public function a_user_can_view_pages()
{
$this->actingAs($this->admin)
->get(route('admin.pages.index'))
->assertSee(trans('labels.backend.pages.management'))
->assertSee(trans('labels.backend.pages.table.title'))
->assertSee(trans('labels.backend.pages.table.status'))
->assertSee($this->admin->name);
}
/** @test */
public function test_create_and_edit_page_has_all_fields()
{
$this->actingAs($this->admin)
->get(route('admin.pages.create'))
->assertSee(trans('validation.attributes.backend.pages.title'))
->assertSee(trans('validation.attributes.backend.pages.description'))
->assertSee(trans('validation.attributes.backend.pages.cannonical_link'))
->assertSee(trans('validation.attributes.backend.pages.seo_title'))
->assertSee(trans('validation.attributes.backend.pages.seo_keyword'))
->assertSee(trans('validation.attributes.backend.pages.seo_description'))
->assertSee(trans('validation.attributes.backend.pages.is_active'));
$page = create(Page::class);
$this->actingAs($this->admin)
->get(route('admin.pages.edit', $page))
->assertSee(trans('validation.attributes.backend.pages.title'))
->assertSee(trans('validation.attributes.backend.pages.description'))
->assertSee(trans('validation.attributes.backend.pages.cannonical_link'))
->assertSee(trans('validation.attributes.backend.pages.seo_title'))
->assertSee(trans('validation.attributes.backend.pages.seo_keyword'))
->assertSee(trans('validation.attributes.backend.pages.seo_description'))
->assertSee(trans('validation.attributes.backend.pages.is_active'));
}
/** @test */
public function a_user_can_create_page()
{
$page = make(Page::class);
$this->actingAs($this->admin)
->post(route('admin.pages.store'), $page->toArray())
->assertRedirect(route('admin.pages.index'));
$this->assertDatabaseHas('pages', ['title' => $page->title, 'description' => $page->description]);
}
/** @test */
public function it_requires_title_on_create()
{
$page = make(Page::class, ['title' => '']);
$this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.pages.store'), $page->toArray())
->assertSessionHasErrors('title');
}
/** @test */
public function it_requires_description_while_create()
{
$page = make(Page::class, ['description' => '']);
$this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.pages.store'), $page->toArray())
->assertSessionHasErrors('description');
}
/** @test */
public function a_user_can_update_page()
{
$page = create(Page::class);
$title = 'Changed title';
$slug = str_slug($title);
$description = 'Changed Description';
$this->actingAs($this->admin)
->patch(route('admin.pages.update', $page), ['title' => $title, 'description' => $description]);
$this->assertDatabaseHas('pages', ['id' => $page->id, 'title' => $title, 'page_slug' => $slug, 'description' => $description]);
}
/** @test */
public function it_requires_title_on_update()
{
$page = create(Page::class);
$page1 = $page->toArray();
$page1['title'] = '';
$this->withExceptionHandling()
->actingAs($this->admin)
->patch(route('admin.pages.update', $page), $page1)
->assertSessionHasErrors('title');
}
/** @test */
public function it_requires_description_while_update()
{
$page = create(Page::class);
$page1 = $page->toArray();
$page1['description'] = '';
$this->withExceptionHandling()
->actingAs($this->admin)
->patch(route('admin.pages.update', $page), $page1)
->assertSessionHasErrors('description');
}
/** @test */
public function a_user_can_delete_a_page()
{
$this->actingAs($this->admin);
$page = create(Page::class);
$this->delete(route('admin.pages.destroy', $page));
$this->assertDatabaseMissing(config('module.pages.table'), ['name' => $page->name, 'id' => $page->id, 'deleted_at' => null]);
}
}
<?php
namespace Tests\Feature\Backend;
use App\Events\Backend\Access\Permission\PermissionCreated;
use App\Events\Backend\Access\Permission\PermissionDeleted;
use App\Events\Backend\Access\Permission\PermissionUpdated;
use App\Models\Access\Permission\Permission;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
class ManagePermissionsTest extends TestCase
{
/** @test */
public function a_user_can_view_permissions()
{
$this->actingAs($this->admin)
->get(route('admin.access.permission.index'))
->assertViewIs('backend.access.permissions.index')
->assertSee(trans('labels.backend.access.permissions.management'))
->assertSee('Export')
->assertSee('Action');
}
/** @test */
public function a_permission_requires_a_name()
{
$permission = make(Permission::class, ['name' => null])->toArray();
return $this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.access.permission.store'), $permission)
->assertSessionHasErrors('name');
}
/** @test */
public function a_permission_requires_a_display_name()
{
$permission = make(Permission::class, ['display_name' => null])->toArray();
return $this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.access.permission.store'), $permission)
->assertSessionHasErrors('display_name');
}
/** @test */
public function a_user_can_create_new_permission()
{
// Make sure our events are fired
Event::fake();
$permission = make(Permission::class, ['name' => 'test permission'])->toArray();
$this->actingAs($this->admin)
->post(route('admin.access.permission.store'), $permission)
->assertRedirect(route('admin.access.permission.index'))
->assertSessionHas(['flash_success' => trans('alerts.backend.permissions.created')]);
$this->assertDatabaseHas(config('access.permissions_table'), [
'name' => $permission['name'],
]);
Event::assertDispatched(PermissionCreated::class);
}
/** @test */
public function it_fails_for_validation_on_update_permission()
{
$permission = create(Permission::class);
$data = $permission->toArray();
$data['name'] = '';
$this->withExceptionHandling()
->actingAs($this->admin)
->patch(route('admin.access.permission.update', $permission), $data)
->assertSessionHasErrors(['name']);
}
/** @test */
public function a_user_can_update_permission()
{
Event::fake();
$permission = create(Permission::class);
$data = $permission->toArray();
$data['name'] = 'Updated Permission Name';
$this->withExceptionHandling()
->actingAs($this->admin)
->patch(route('admin.access.permission.update', $permission), $data)
->assertRedirect(route('admin.access.permission.index'))
->assertSessionHas(['flash_success' => trans('alerts.backend.permissions.updated')]);
$this->assertDatabaseHas(config('access.permissions_table'), [
'name' => $data['name'],
]);
Event::assertDispatched(PermissionUpdated::class);
}
/** @test */
public function a_user_can_delete_a_permission()
{
Event::fake();
$permission = create(Permission::class);
$this->actingAs($this->admin)
->delete(route('admin.access.permission.destroy', $permission))
->assertStatus(302)
->assertSessionHas(['flash_success' => trans('alerts.backend.permissions.deleted')]);
/*$this->assertDatabaseMissing('permissions', [
'name' => $permission->name, 'id' => $permission->id
]);*/
Event::assertDispatched(PermissionDeleted::class);
}
}
<?php
namespace Tests\Feature\Backend;
use App\Events\Backend\Access\Role\RoleCreated;
use App\Events\Backend\Access\Role\RoleDeleted;
use App\Events\Backend\Access\Role\RoleUpdated;
use App\Exceptions\GeneralException;
use App\Models\Access\Permission\Permission;
use App\Models\Access\Role\Role;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
class ManageRolesTest extends TestCase
{
/** @test */
public function a_user_can_view_roles()
{
$this->actingAs($this->admin)
->get(route('admin.access.role.index'))
->assertViewIs('backend.access.roles.index')
->assertSee(trans('labels.backend.access.roles.management'))
->assertSee('Export')
->assertSee('Action');
}
/** @test */
public function a_role_requires_a_name()
{
$role = make(Role::class, ['name' => null])->toArray();
return $this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.access.role.store'), $role)
->assertSessionHasErrors('name');
}
/** @test */
public function a_role_requires_a_permission_if_associated_permissions_is_not_set_to_all()
{
$role = make(Role::class)->toArray();
$role['associated_permissions'] = 'custom';
return $this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.access.role.store'), $role)
->assertSessionHasErrors('permissions');
}
/** @test */
/*public function a_role_can_not_create_if_name_is_already_exists()
{
$role = make(Role::class, ['name' => $this->adminRole->name])->toArray();
return $this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.access.role.store'), $role);
$this->assertSessionHas(['flash_danger' => trans('exceptions.backend.access.roles.already_exists')]);
$this->expectException(GeneralException::class);
}*/
/** @test */
public function a_user_can_create_new_role()
{
// Make sure our events are fired
Event::fake();
$role = make(Role::class, ['name' => 'test Role'])->toArray();
$role['associated_permissions'] = 'all';
$this->actingAs($this->admin)
->post(route('admin.access.role.store'), $role)
->assertRedirect(route('admin.access.role.index'))
->assertSessionHas(['flash_success' => trans('alerts.backend.roles.created')]);
$this->assertDatabaseHas(config('access.roles_table'), [
'name' => $role['name'],
]);
Event::assertDispatched(RoleCreated::class);
}
/** @test */
public function a_user_can_create_new_role_with_permissions()
{
// Make sure our events are fired
Event::fake();
$role = make(Role::class, ['name' => 'test Role'])->toArray();
$permission = create(Permission::class);
$role['associated_permissions'] = 'custom';
$role['permissions'] = [$permission->id];
$this->actingAs($this->admin)
->post(route('admin.access.role.store'), $role)
->assertRedirect(route('admin.access.role.index'))
->assertSessionHas(['flash_success' => trans('alerts.backend.roles.created')]);
$this->assertDatabaseHas(config('access.roles_table'), [
'name' => $role['name'],
]);
$this->assertDatabaseHas(config('access.permissions_table'), ['name' => $permission->name]);
$this->assertDatabaseHas(config('access.permission_role_table'), ['permission_id' => $permission->id]);
Event::assertDispatched(RoleCreated::class);
}
/** @test */
public function it_fails_for_validation_on_update_role()
{
$role = create(Role::class);
$data = $role->toArray();
$data['name'] = '';
$this->withExceptionHandling()
->actingAs($this->admin)
->patch(route('admin.access.role.update', $role), $data)
->assertSessionHasErrors(['name']);
}
/** @test */
public function a_user_can_update_role()
{
Event::fake();
$role = create(Role::class);
$permission = create(Permission::class);
$data = $role->toArray();
$data['associated_permissions'] = 'custom';
$data['permissions'] = [$permission->id];
$data['name'] = 'Updated Role Name';
$this->withExceptionHandling()
->actingAs($this->admin)
->patch(route('admin.access.role.update', $role), $data)
->assertRedirect(route('admin.access.role.index'))
->assertSessionHas(['flash_success' => trans('alerts.backend.roles.updated')]);
$this->assertDatabaseHas(config('access.roles_table'), [
'name' => $data['name'],
]);
$this->assertDatabaseHas(config('access.permissions_table'), ['name' => $permission->name]);
$this->assertDatabaseHas(config('access.permission_role_table'), ['permission_id' => $permission->id]);
Event::assertDispatched(RoleUpdated::class);
}
/** @test */
public function a_user_can_delete_a_role()
{
Event::fake();
$role = create(Role::class);
$this->actingAs($this->admin)
->delete(route('admin.access.role.destroy', $role))
->assertStatus(302)
->assertSessionHas(['flash_success' => trans('alerts.backend.roles.deleted')]);
/*$this->assertDatabaseMissing(config('access.roles_table'), [
'name' => $role->name,
'id' => $role->id
]);*/
Event::assertDispatched(RoleDeleted::class);
}
}
<?php
namespace Tests\Feature\Backend;
use App\Models\Settings\Setting;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class ManageSettingsTest extends TestCase
{
protected $setting;
public function setUp()
{
parent::setUp();
$this->setting = Setting::find(1);
$this->actingAs($this->admin);
}
/** @test */
public function setting_page_shows_different_tabs()
{
$this->get(route('admin.settings.edit', $this->setting))
->assertSee(__('labels.backend.settings.seo'))
->assertSee(__('labels.backend.settings.companydetails'))
->assertSee(__('labels.backend.settings.mail'))
->assertSee(__('labels.backend.settings.footer'))
->assertSee(__('labels.backend.settings.terms'))
->assertSee(__('labels.backend.settings.google'));
}
/** @test */
public function it_can_update_a_valid_site_logo()
{
$this->patch(route('admin.settings.update', $this->setting), [
'logo' => UploadedFile::fake()->image('logo.jpg', 226, 48),
]);
Storage::disk('public')->assertExists('img/logo/'.$this->setting->logo);
}
/** @test */
public function it_throws_error_for_valid_site_logo()
{
$this->withExceptionHandling();
$this->patch(route('admin.settings.update', $this->setting), [
'logo' => UploadedFile::fake()->image('logo.jpg', 200, 500),
])
->assertSessionHasErrors('logo');
}
/** @test */
public function it_can_update_site_favicon()
{
$this->patch(route('admin.settings.update', $this->setting), [
'favicon' => UploadedFile::fake()->image('favicon.jpg', 16, 16),
]);
Storage::disk('public')->assertExists('img/favicon/'.$this->setting->favicon);
}
/** @test */
public function it_throws_error_for_valid_site_favicon()
{
$this->withExceptionHandling();
$this->patch(route('admin.settings.update', $this->setting), [
'favicon' => UploadedFile::fake()->image('favicon.jpg', 200, 500),
])
->assertSessionHasErrors('favicon');
}
}
This diff is collapsed.
<?php
namespace Tests\Feature;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$response = $this->get('/');
$response->assertSee('Laravel AdminPanel');
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
namespace Tests\Unit;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
}
<?php
namespace Tests\Unit\Models;
use App\Models\Access\User\User;
use App\Models\BlogCategories\BlogCategory;
use Tests\TestCase;
class BlogCategoryTest extends TestCase
{
/** @test */
public function it_has_a_creator()
{
$this->actingAs($this->admin);
$category = create(BlogCategory::class, ['created_by' => access()->id()]);
$this->assertInstanceOf(User::class, $category->creator);
$this->assertEquals($category->creator->id, access()->id());
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
function create($class, $attributes = [], $times = null)
{
return factory($class, $times)->create($attributes);
}
function make($class, $attributes = [], $times = null)
{
return factory($class, $times)->make($attributes);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment