Skip to content
Snippets Groups Projects
Select Git revision
  • af35f786444326aed81cfd475ec7c3d61981aa0d
  • pre-2.1b default protected
  • pre-2.1
  • pre-2.0
  • testTag
  • pre2.1b
6 results

index.php

Blame
  • 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]);
        }
    }