Commit c68b710a authored by bvipul's avatar bvipul

Added page delete test and remaining blog category test

parent 4de44480
...@@ -12,8 +12,8 @@ trait BlogCategoryRelationship ...@@ -12,8 +12,8 @@ trait BlogCategoryRelationship
/** /**
* BlogCategories belongs to relationship with state. * 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');
} }
} }
<?php <?php
namespace Tests\Feature; namespace Tests\Feature\Backend;
use Tests\TestCase; use Tests\TestCase;
use App\Models\BlogCategories\BlogCategory; use App\Models\BlogCategories\BlogCategory;
...@@ -45,15 +45,16 @@ class ManageBlogCategoriesTest extends TestCase ...@@ -45,15 +45,16 @@ class ManageBlogCategoriesTest extends TestCase
->assertSessionHasErrors('name'); ->assertSessionHasErrors('name');
} }
// public function a_blog_category_requires_a_name_while_updating() /** @test */
// { public function a_blog_category_requires_a_name_while_updating()
// $this->actingAs($this->admin)->withExceptionHandling(); {
$this->actingAs($this->admin)->withExceptionHandling();
// $category = create(BlogCategory::class); $category = create(BlogCategory::class);
// $this->post(route('admin.blogCategories.store'), $category->toArray()) $this->patch(route('admin.blogCategories.update', $category), ['name' => ''])
// ->assertSessionHasErrors('name'); ->assertSessionHasErrors('name');
// } }
/** @test */ /** @test */
public function a_user_can_update_a_blog_category() public function a_user_can_update_a_blog_category()
......
...@@ -124,4 +124,16 @@ class ManagePagesTest extends TestCase ...@@ -124,4 +124,16 @@ class ManagePagesTest extends TestCase
->post(route('admin.pages.store'), $page3) ->post(route('admin.pages.store'), $page3)
->assertSessionHasErrors('description'); ->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 <?php
namespace Tests\Unit; namespace Tests\Unit\Models;
use Tests\TestCase; use Tests\TestCase;
use App\Models\Access\User\User;
use App\Models\BlogCategories\BlogCategory;
use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
class BlogCategoryTest extends TestCase class BlogCategoryTest extends TestCase
{ {
/** /** @test */
* A basic test example. public function it_has_a_creator()
*
* @return void
*/
public function testExample()
{ {
$this->assertTrue(true); $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());
} }
} }
<?php <?php
namespace Tests\Unit; namespace Tests\Unit\Models;
use Tests\TestCase; use Tests\TestCase;
use App\Models\Page\Page; use App\Models\Page\Page;
......
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