Files
amare/tests/Feature/Marketing/PortfolioCasesTest.php
manoel freitas 8da8d19504 feat: CMS de conteúdo do site (WEB-02/03/04/06)
Implementa gestão Filament de configurações, serviços, portfólio e depoimentos com policies admin-only, upload validado e seed determinístico.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-28 23:16:25 -03:00

77 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Marketing;
use App\Filament\Resources\PortfolioCases\Pages\ListPortfolioCases;
use App\Models\PortfolioCase;
use App\Models\PortfolioImage;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class PortfolioCasesTest extends TestCase
{
use RefreshDatabase;
public function test_published_scope_excludes_draft_cases(): void
{
PortfolioCase::factory()->create(['published_at' => null]);
$published = PortfolioCase::factory()->published()->create();
$this->assertCount(1, PortfolioCase::query()->published()->get());
$this->assertTrue(PortfolioCase::query()->published()->first()?->is($published));
}
public function test_gallery_images_are_ordered_by_sort_order(): void
{
$case = PortfolioCase::factory()->create();
PortfolioImage::query()->create([
'portfolio_case_id' => $case->id,
'path' => 'content/b.jpg',
'alt_text' => 'Segunda',
'sort_order' => 2,
]);
PortfolioImage::query()->create([
'portfolio_case_id' => $case->id,
'path' => 'content/a.jpg',
'alt_text' => 'Primeira',
'sort_order' => 1,
]);
$ordered = $case->fresh()->images->pluck('alt_text')->all();
$this->assertSame(['Primeira', 'Segunda'], $ordered);
}
public function test_deleting_case_cascades_gallery_images(): void
{
$case = PortfolioCase::factory()->create();
PortfolioImage::query()->create([
'portfolio_case_id' => $case->id,
'path' => 'content/a.jpg',
'alt_text' => 'Imagem',
'sort_order' => 1,
]);
$case->delete();
$this->assertDatabaseCount('portfolio_images', 0);
}
public function test_assistant_cannot_access_portfolio_resource(): void
{
$assistant = User::factory()->assistant()->create();
$this->actingAs($assistant);
Livewire::test(ListPortfolioCases::class)
->assertForbidden();
}
}