Commit 1c2ee785 authored by Vipul Basapati's avatar Vipul Basapati

Blog Tags Test Complete

parent c5c8c63d
...@@ -62,7 +62,7 @@ class BlogCategoriesController extends Controller ...@@ -62,7 +62,7 @@ class BlogCategoriesController extends Controller
} }
/** /**
* @param \App\Models\BlogCategories\BlogCategory $blogcategory * @param \App\Models\BlogCategories\BlogCategory $blogCategory
* @param \App\Http\Requests\Backend\BlogCategories\EditBlogCategoriesRequest $request * @param \App\Http\Requests\Backend\BlogCategories\EditBlogCategoriesRequest $request
* *
* @return mixed * @return mixed
...@@ -74,7 +74,7 @@ class BlogCategoriesController extends Controller ...@@ -74,7 +74,7 @@ class BlogCategoriesController extends Controller
} }
/** /**
* @param \App\Models\BlogCategories\BlogCategory $blogcategory * @param \App\Models\BlogCategories\BlogCategory $blogCategory
* @param \App\Http\Requests\Backend\BlogCategories\UpdateBlogCategoriesRequest $request * @param \App\Http\Requests\Backend\BlogCategories\UpdateBlogCategoriesRequest $request
* *
* @return mixed * @return mixed
...@@ -89,7 +89,7 @@ class BlogCategoriesController extends Controller ...@@ -89,7 +89,7 @@ class BlogCategoriesController extends Controller
} }
/** /**
* @param \App\Models\BlogCategories\BlogCategory $blogcategory * @param \App\Models\BlogCategories\BlogCategory $blogCategory
* @param \App\Http\Requests\Backend\BlogCategories\DeleteBlogCategoriesRequest $request * @param \App\Http\Requests\Backend\BlogCategories\DeleteBlogCategoriesRequest $request
* *
* @return mixed * @return mixed
......
...@@ -60,49 +60,49 @@ class BlogTagsController extends Controller ...@@ -60,49 +60,49 @@ class BlogTagsController extends Controller
$this->blogtag->create($request->except('token')); $this->blogtag->create($request->except('token'));
return redirect() return redirect()
->route('admin.blogtags.index') ->route('admin.blogTags.index')
->with('flash_success', trans('alerts.backend.blogtags.created')); ->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 * @param \App\Http\Requests\Backend\BlogTags\EditBlogTagsRequest $request
* *
* @return mixed * @return mixed
*/ */
public function edit(BlogTag $blogtag, EditBlogTagsRequest $request) public function edit(BlogTag $blogTag, EditBlogTagsRequest $request)
{ {
return view('backend.blogtags.edit') 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 * @param \App\Http\Requests\Backend\BlogTags\UpdateBlogTagsRequest $request
* *
* @return mixed * @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() return redirect()
->route('admin.blogtags.index') ->route('admin.blogTags.index')
->with('flash_success', trans('alerts.backend.blogtags.updated')); ->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 * @param \App\Http\Requests\Backend\BlogTags\DeleteBlogTagsRequest $request
* *
* @return mixed * @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() return redirect()
->route('admin.blogtags.index') ->route('admin.blogTags.index')
->with('flash_success', trans('alerts.backend.blogtags.deleted')); ->with('flash_success', trans('alerts.backend.blogtags.deleted'));
} }
} }
...@@ -12,8 +12,8 @@ trait BlogTagRelationship ...@@ -12,8 +12,8 @@ trait BlogTagRelationship
/** /**
* BlogTags belongs to relationship with state. * 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');
} }
} }
<?php
use Faker\Generator as Faker;
use App\Models\BlogTags\BlogTag;
use App\Models\Access\User\User;
$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;
}
];
});
...@@ -16,7 +16,7 @@ class CreateBlogCategoriesTable extends Migration ...@@ -16,7 +16,7 @@ class CreateBlogCategoriesTable extends Migration
$table->increments('id'); $table->increments('id');
$table->string('name', 191); $table->string('name', 191);
$table->boolean('status')->default(1); $table->boolean('status')->default(1);
$table->integer('created_by')->unsigned()->nullable(); $table->integer('created_by')->unsigned();
$table->integer('updated_by')->unsigned()->nullable(); $table->integer('updated_by')->unsigned()->nullable();
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();
......
...@@ -18,7 +18,7 @@ class MenuTableSeeder extends Seeder ...@@ -18,7 +18,7 @@ class MenuTableSeeder extends Seeder
'id' => 1, 'id' => 1,
'type' => 'backend', 'type' => 'backend',
'name' => 'Backend Sidebar Menu', '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_by' => 1,
'created_at' => Carbon::now(), 'created_at' => Carbon::now(),
]; ];
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
@endsection @endsection
@section('content') @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 box-info">
<div class="box-header with-border"> <div class="box-header with-border">
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<div class="form-group"> <div class="form-group">
@include("backend.blogtags.form") @include("backend.blogtags.form")
<div class="edit-form-btn"> <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']) }} {{ Form::submit(trans('buttons.general.crud.create'), ['class' => 'btn btn-primary btn-md']) }}
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
@endsection @endsection
@section('content') @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 box-info">
<div class="box-header with-border"> <div class="box-header with-border">
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<div class="form-group"> <div class="form-group">
@include("backend.blogtags.form") @include("backend.blogtags.form")
<div class="edit-form-btn"> <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']) }} {{ Form::submit(trans('buttons.general.crud.update'), ['class' => 'btn btn-primary btn-md']) }}
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
processing: true, processing: true,
serverSide: true, serverSide: true,
ajax: { ajax: {
url: '{{ route("admin.blogtags.get") }}', url: '{{ route("admin.blogTags.get") }}',
type: 'post' type: 'post'
}, },
columns: [ columns: [
......
<!--Action Button--> <!--Action Button-->
@if(Active::checkUriPattern('admin/blogtags')) @if(Active::checkUriPattern('admin/blogTags'))
<div class="btn-group"> <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="caret"></span>
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
<span class="sr-only">Toggle Dropdown</span> <span class="sr-only">Toggle Dropdown</span>
</button> </button>
<ul class="dropdown-menu" role="menu"> <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') @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 @endauth
</ul> </ul>
</div> </div>
......
...@@ -97,8 +97,8 @@ ...@@ -97,8 +97,8 @@
</li> </li>
@endauth @endauth
@permission('view-blog-tag') @permission('view-blog-tag')
<li class="{{ active_class(Active::checkUriPattern('admin/blogtags*')) }}"> <li class="{{ active_class(Active::checkUriPattern('admin/blogTags*')) }}">
<a href="{{ route('admin.blogtags.index') }}"> <a href="{{ route('admin.blogTags.index') }}">
<span>{{ trans('menus.backend.blogtags.management') }}</span> <span>{{ trans('menus.backend.blogtags.management') }}</span>
</a> </a>
</li> </li>
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
* Blogs Tags Management * Blogs Tags Management
*/ */
Route::group(['namespace' => 'BlogTags'], function () { Route::group(['namespace' => 'BlogTags'], function () {
Route::resource('blogtags', 'BlogTagsController', ['except' => ['show']]); Route::resource('blogTags', 'BlogTagsController', ['except' => ['show']]);
//For DataTables //For DataTables
Route::post('blogtags/get', 'BlogTagsTableController') Route::post('blogTags/get', 'BlogTagsTableController')
->name('blogtags.get'); ->name('blogTags.get');
}); });
<?php
namespace Tests\Feature\Backend;
use Tests\TestCase;
use App\Models\BlogTags\BlogTag;
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\Unit\Models;
use Tests\TestCase;
use App\Models\BlogTags\BlogTag;
use App\Models\Access\User\User;
class BlogTagTest extends TestCase
{
/** @test */
public function it_has_a_creator()
{
$this->actingAs($this->admin);
$tag = create(BlogTag::class, ['created_by' => access()->id()]);
$this->assertInstanceOf(User::class, $tag->creator);
$this->assertEquals($tag->creator->id, access()->id());
}
}
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