Skip to content

Commit 7f0cd84

Browse files
committed
Faqs Tests Completed
1 parent 7526418 commit 7f0cd84

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

database/factories/FaqFactory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use App\Models\Faqs\Faq;
4+
use Faker\Generator as Faker;
5+
6+
$factory->define(Faq::class, function (Faker $faker) {
7+
return [
8+
'question' => rtrim($faker->sentence, '.') . '?',
9+
'answer' => $faker->paragraph,
10+
'status' => $faker->numberBetween(0,1)
11+
];
12+
});

tests/Feature/Backend/ManageBlogsTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Illuminate\Support\Facades\Storage;
1010
use App\Models\BlogCategories\BlogCategory;
1111
use Illuminate\Foundation\Testing\WithFaker;
12-
use Illuminate\Foundation\Testing\RefreshDatabase;
1312

1413
class ManageBlogsTest extends TestCase
1514
{
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace Tests\Feature\Backend;
4+
5+
use Tests\TestCase;
6+
use App\Models\Faqs\Faq;
7+
8+
class ManageFaqsTest extends TestCase
9+
{
10+
/** @test */
11+
public function a_user_can_view_faqs_index_page()
12+
{
13+
$this->actingAs($this->admin)
14+
->get(route('admin.faqs.index'))
15+
->assertViewIs('backend.faqs.index')
16+
->assertSee(trans('labels.backend.faqs.management'))
17+
->assertSee(trans('labels.backend.faqs.table.question'))
18+
->assertSee(trans('labels.backend.faqs.table.answer'))
19+
->assertSee(trans('labels.backend.faqs.table.status'))
20+
->assertSee('Export')
21+
->assertSee('Action');
22+
}
23+
24+
/** @test */
25+
public function a_user_can_create_faq()
26+
{
27+
$faq = make(Faq::class);
28+
29+
$this->actingAs($this->admin)
30+
->post(route('admin.faqs.store'), $faq->toArray());
31+
32+
$this->assertDatabaseHas(config('module.faqs.table'), ['question' => $faq->question, 'answer' => $faq->answer]);
33+
}
34+
35+
/** @test */
36+
public function it_requires_question_while_creating()
37+
{
38+
$faq = make(Faq::class, ['question' => '']);
39+
40+
$this->actingAs($this->admin)
41+
->withExceptionHandling()
42+
->post(route('admin.faqs.store'), $faq->toArray())
43+
->assertSessionHasErrors('question');
44+
}
45+
46+
47+
/** @test */
48+
public function it_requires_answer_while_creating()
49+
{
50+
$faq = make(Faq::class, ['answer' => '']);
51+
52+
$this->actingAs($this->admin)
53+
->withExceptionHandling()
54+
->post(route('admin.faqs.store'), $faq->toArray())
55+
->assertSessionHasErrors('answer');
56+
}
57+
58+
/** @test */
59+
public function it_requires_question_while_updating()
60+
{
61+
$faq = create(Faq::class);
62+
63+
$this->actingAs($this->admin)
64+
->withExceptionHandling()
65+
->patch(route('admin.faqs.update', $faq), ['question' => '', 'answer' => $faq->answer])
66+
->assertSessionHasErrors('question');
67+
}
68+
69+
/** @test */
70+
public function it_requires_answer_while_updating()
71+
{
72+
$faq = create(Faq::class);
73+
74+
$this->actingAs($this->admin)
75+
->withExceptionHandling()
76+
->patch(route('admin.faqs.update', $faq), ['question' => $faq->question, 'answer' => ''])
77+
->assertSessionHasErrors('answer');
78+
}
79+
80+
/** @test */
81+
public function a_user_can_update_faq()
82+
{
83+
$faq = create(Faq::class);
84+
85+
$changed_question = "What is Life?";
86+
$changed_answer = $faq->answer;
87+
$this->actingAs($this->admin)
88+
->patch(route('admin.faqs.update', $faq), ['question' => $changed_question, 'answer' => $changed_answer]);
89+
90+
$this->assertDatabaseHas(config('module.faqs.table'), ['id' => $faq->id, 'question' => $changed_question, 'answer' => $changed_answer]);
91+
}
92+
93+
/** @test */
94+
public function a_user_can_delete_faq()
95+
{
96+
$faq = create(Faq::class);
97+
98+
$this->actingAs($this->admin)
99+
->delete(route('admin.faqs.destroy' , $faq));
100+
101+
$this->assertDatabaseMissing(config('module.faqs.table'), ['id' => $faq->id, 'deleted_at' => null]);
102+
}
103+
}

0 commit comments

Comments
 (0)