2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Models\Faq;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Domain\Enums\UserRole;
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
describe('FaqsController', function (): void {
|
|
|
|
|
beforeEach(function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// GIVEN
|
|
|
|
|
$user = User::factory()->create(['role' => UserRole::SuperAdmin]);
|
|
|
|
|
$this->actingAs($user, 'backend');
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
it('can access index', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// WHEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$response = $this->get('/bo/faqs');
|
2026-09-29 14:53:02 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-06-14 21:32:07 +02:00
|
|
|
expect($response->status())->toBe(200);
|
|
|
|
|
$response->assertViewIs('bo.faqs.index');
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
it('can access create', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// WHEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$response = $this->get('/bo/faqs/create');
|
2026-09-29 14:53:02 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-06-14 21:32:07 +02:00
|
|
|
expect($response->status())->toBe(200);
|
|
|
|
|
$response->assertViewIs('bo.faqs.create');
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
it('can store a faq', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// GIVEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$data = [
|
|
|
|
|
'question' => 'How does it work?',
|
2026-09-29 14:59:07 +02:00
|
|
|
'answer' => '<p>Like <strong>this</strong>.</p>',
|
2026-06-14 21:32:07 +02:00
|
|
|
];
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
// WHEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$response = $this->post('/bo/faqs', $data);
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
// THEN
|
|
|
|
|
$faq = Faq::query()->firstOrFail();
|
|
|
|
|
expect($faq->question)->toBe('How does it work?');
|
2026-09-29 14:59:07 +02:00
|
|
|
expect($faq->answer)->toBe('<p>Like <strong>this</strong>.</p>');
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
$response->assertRedirect("/bo/faqs/{$faq->id}/edit");
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
it('can access edit', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// GIVEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$faq = new Faq();
|
2026-09-29 14:53:02 +02:00
|
|
|
$faq->question = 'What is this?';
|
|
|
|
|
$faq->answer = 'This is an answer.';
|
2026-06-14 21:32:07 +02:00
|
|
|
$faq->save();
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
// WHEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$response = $this->get("/bo/faqs/{$faq->id}/edit");
|
2026-09-29 14:53:02 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-06-14 21:32:07 +02:00
|
|
|
expect($response->status())->toBe(200);
|
|
|
|
|
$response->assertViewIs('bo.faqs.edit');
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
it('can update a faq', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// GIVEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$faq = new Faq();
|
2026-09-29 14:53:02 +02:00
|
|
|
$faq->question = 'Initial question?';
|
|
|
|
|
$faq->answer = 'Initial answer.';
|
2026-06-14 21:32:07 +02:00
|
|
|
$faq->save();
|
|
|
|
|
|
|
|
|
|
$data = [
|
2026-09-29 14:53:02 +02:00
|
|
|
'question' => 'Updated question?',
|
2026-09-29 14:59:07 +02:00
|
|
|
'answer' => '<p>Updated <em>answer</em>.</p>',
|
2026-06-14 21:32:07 +02:00
|
|
|
];
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
// WHEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$response = $this->put("/bo/faqs/{$faq->id}", $data);
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
// THEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$faq->refresh();
|
2026-09-29 14:53:02 +02:00
|
|
|
expect($faq->question)->toBe('Updated question?');
|
2026-09-29 14:59:07 +02:00
|
|
|
expect($faq->answer)->toBe('<p>Updated <em>answer</em>.</p>');
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
$response->assertRedirect("/bo/faqs/{$faq->id}/edit");
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
it('can delete a faq', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// GIVEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$faq = new Faq();
|
2026-09-29 14:53:02 +02:00
|
|
|
$faq->question = 'Question to delete?';
|
|
|
|
|
$faq->answer = 'Answer to delete.';
|
2026-06-14 21:32:07 +02:00
|
|
|
$faq->save();
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
// WHEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$response = $this->delete("/bo/faqs/{$faq->id}");
|
|
|
|
|
|
2026-09-29 14:53:02 +02:00
|
|
|
// THEN
|
|
|
|
|
expect(Faq::query()->find($faq->id))->toBeNull();
|
2026-06-14 21:32:07 +02:00
|
|
|
$response->assertRedirect('/bo/faqs');
|
|
|
|
|
});
|
2026-09-29 14:53:02 +02:00
|
|
|
|
|
|
|
|
it('can change order', function (): void {
|
|
|
|
|
/** @var \Tests\TestCase $this */
|
|
|
|
|
// GIVEN
|
|
|
|
|
$faq = new Faq();
|
|
|
|
|
$faq->question = 'Question to reorder?';
|
|
|
|
|
$faq->answer = 'Answer to reorder.';
|
|
|
|
|
$faq->save();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$response = $this->patch("/bo/faqs/{$faq->id}/up");
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($response->status())->toBe(302);
|
|
|
|
|
});
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|