Select Git revision
TermsSectionTest.php 2.63 KiB
<?php
namespace Tests\Feature\Controller;
use App\Http\Controllers\Admin\TermsSectionController;
use App\Models\TermsSection;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use PHPUnit\Framework\Attributes\CoversClass;
use Tests\TestCase;
#[CoversClass(TermsSectionController::class)]
class TermsSectionTest extends TestCase
{
use RefreshDatabase, WithoutMiddleware;
public function test_it_can_list_terms_sections()
{
TermsSection::factory()->count(3)->create();
$response = $this->get(route('admin.terms.index'));
$response->assertStatus(200);
$response->assertViewIs('admin.terms.index');
$this->assertCount(3, $response->viewData('sections'));
}
public function test_it_can_create_a_terms_section()
{
$data = [
'lang' => 'fr',
'content' => 'Contenu des CGV',
'active' => 'on',
];
$response = $this->post(route('admin.terms.store'), $data);
$response->assertRedirect(route('admin.terms.index'));
$this->assertDatabaseHas('translations', ['text' => 'Contenu des CGV']);
$this->assertDatabaseHas('terms_sections', ['active' => true]);
}
public function test_it_can_update_a_terms_section()
{
$section = TermsSection::factory()->create();
$data = [
'lang' => 'fr',
'content' => 'Nouveau contenu',
'active' => 'on',
];
$response = $this->put(route('admin.terms.update', $section->id), $data);
$response->assertRedirect();
$this->assertDatabaseHas('translations', ['text' => 'Nouveau contenu']);
$this->assertDatabaseHas('terms_sections', ['active' => true]);
}
public function test_it_can_delete_a_terms_section()
{
$section = TermsSection::factory()->create();
$response = $this->get(route('admin.terms.delete', $section->id));
$response->assertRedirect(route('admin.terms.index'));
$this->assertDatabaseMissing('terms_sections', ['id' => $section->id]);
}
public function test_it_cannot_delete_a_nonexistent_terms_section()
{
$response = $this->get(route('admin.terms.delete', 999));
$response->assertStatus(404);
}
public function test_it_can_delete_an_active_terms_section()
{
$section = TermsSection::factory()->create(['active' => true]);
$response = $this->get(route('admin.terms.delete', $section->id));
$response->assertRedirect(route('admin.terms.index'));
$this->assertDatabaseMissing('terms_sections', ['id' => $section->id]);
}
}