Commit 7f0cd844 authored by Vipul Basapati's avatar Vipul Basapati

Faqs Tests Completed

parent 75264183
<?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)
];
});
...@@ -9,7 +9,6 @@ use Illuminate\Http\UploadedFile; ...@@ -9,7 +9,6 @@ use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use App\Models\BlogCategories\BlogCategory; use App\Models\BlogCategories\BlogCategory;
use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ManageBlogsTest extends TestCase class ManageBlogsTest extends TestCase
{ {
......
<?php
namespace Tests\Feature\Backend;
use Tests\TestCase;
use App\Models\Faqs\Faq;
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]);
}
}
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