* feat: ship public site with SEO and visuals Publish CMS content on public routes with responsive media, accessibility checks, and deterministic visual baselines. Co-authored-by: Cursor <cursoragent@cursor.com> * fix: make browser visual CI deterministic for media Mount host public storage into FrankenPHP so seeded fixtures are served, and replace PNG-as-JPG fixtures with real JPEGs so Chromium can render them. Co-authored-by: Cursor <cursoragent@cursor.com> * fix: serve public media on same-origin storage paths Pest Browser hosts on 127.0.0.1:port while Storage::url used http://localhost, so screenshots captured broken images. Use relative /storage URLs for media and absolutize only OG tags via url(). Co-authored-by: Cursor <cursoragent@cursor.com> * test: refresh visual baselines from CI Ubuntu screenshots Media now loads on same-origin /storage paths, so baselines must capture the rendered fixtures. Use full-page snapshots from the CI runner to keep Pest's exact snapshot match stable across environments. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
132 lines
4.8 KiB
PHP
132 lines
4.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\Data;
|
|
|
|
use App\Application\Data\PageMeta;
|
|
use App\Models\PortfolioCase;
|
|
use App\Models\SiteSetting;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\TestCase;
|
|
|
|
class PageMetaTest extends TestCase
|
|
{
|
|
public function test_for_page_falls_back_to_site_settings_defaults(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$settings = new SiteSetting([
|
|
'brand_name' => 'Amare Assessoria',
|
|
'default_meta_title' => 'Amare Assessoria de Eventos',
|
|
'default_meta_description' => 'Assessoria premium.',
|
|
'default_og_image_path' => 'og/default.jpg',
|
|
'default_og_image_alt' => 'Marca Amare',
|
|
]);
|
|
|
|
$meta = PageMeta::forPage(
|
|
canonical: 'https://amare.test/sobre',
|
|
settings: $settings,
|
|
);
|
|
|
|
$this->assertSame('Amare Assessoria de Eventos', $meta->title);
|
|
$this->assertSame('Assessoria premium.', $meta->description);
|
|
$this->assertSame('https://amare.test/sobre', $meta->canonical);
|
|
$this->assertSame('website', $meta->ogType);
|
|
$this->assertSame(url(Storage::disk('public')->url('og/default.jpg')), $meta->ogImageUrl);
|
|
$this->assertSame('Marca Amare', $meta->ogImageAlt);
|
|
}
|
|
|
|
public function test_for_page_uses_explicit_overrides_when_provided(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$settings = new SiteSetting([
|
|
'default_meta_title' => 'Default Title',
|
|
'default_meta_description' => 'Default Description',
|
|
'default_og_image_path' => 'og/default.jpg',
|
|
'default_og_image_alt' => 'Default alt',
|
|
]);
|
|
|
|
$meta = PageMeta::forPage(
|
|
canonical: 'https://amare.test/servicos',
|
|
settings: $settings,
|
|
title: 'Serviços',
|
|
description: 'Catálogo de serviços',
|
|
ogImageUrl: 'https://amare.test/storage/services/cover.jpg',
|
|
ogImageAlt: 'Capa serviços',
|
|
);
|
|
|
|
$this->assertSame('Serviços', $meta->title);
|
|
$this->assertSame('Catálogo de serviços', $meta->description);
|
|
$this->assertSame('https://amare.test/storage/services/cover.jpg', $meta->ogImageUrl);
|
|
$this->assertSame('Capa serviços', $meta->ogImageAlt);
|
|
}
|
|
|
|
public function test_for_case_prefers_case_meta_and_cover_over_defaults(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$settings = new SiteSetting([
|
|
'default_meta_title' => 'Default Title',
|
|
'default_meta_description' => 'Default Description',
|
|
'default_og_image_path' => 'og/default.jpg',
|
|
'default_og_image_alt' => 'Default alt',
|
|
]);
|
|
|
|
$case = new PortfolioCase([
|
|
'title' => 'Casamento Jardim',
|
|
'summary' => 'Resumo do caso',
|
|
'meta_title' => 'Meta do Casamento',
|
|
'meta_description' => 'Descrição SEO do casamento',
|
|
'cover_image_path' => 'cases/cover.jpg',
|
|
'cover_image_alt' => 'Capa do casamento',
|
|
]);
|
|
|
|
$meta = PageMeta::forCase(
|
|
case: $case,
|
|
canonical: 'https://amare.test/portfolio/casamento-jardim',
|
|
settings: $settings,
|
|
);
|
|
|
|
$this->assertSame('Meta do Casamento', $meta->title);
|
|
$this->assertSame('Descrição SEO do casamento', $meta->description);
|
|
$this->assertSame('https://amare.test/portfolio/casamento-jardim', $meta->canonical);
|
|
$this->assertSame('article', $meta->ogType);
|
|
$this->assertSame(url(Storage::disk('public')->url('cases/cover.jpg')), $meta->ogImageUrl);
|
|
$this->assertSame('Capa do casamento', $meta->ogImageAlt);
|
|
}
|
|
|
|
public function test_for_case_falls_back_to_title_summary_and_site_defaults(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$settings = new SiteSetting([
|
|
'default_meta_title' => 'Default Title',
|
|
'default_meta_description' => 'Default Description',
|
|
'default_og_image_path' => 'og/default.jpg',
|
|
'default_og_image_alt' => 'Default alt',
|
|
]);
|
|
|
|
$case = new PortfolioCase([
|
|
'title' => 'Casamento Praia',
|
|
'summary' => 'Resumo praia',
|
|
'meta_title' => null,
|
|
'meta_description' => null,
|
|
'cover_image_path' => null,
|
|
'cover_image_alt' => null,
|
|
]);
|
|
|
|
$meta = PageMeta::forCase(
|
|
case: $case,
|
|
canonical: 'https://amare.test/portfolio/casamento-praia',
|
|
settings: $settings,
|
|
);
|
|
|
|
$this->assertSame('Casamento Praia', $meta->title);
|
|
$this->assertSame('Resumo praia', $meta->description);
|
|
$this->assertSame(url(Storage::disk('public')->url('og/default.jpg')), $meta->ogImageUrl);
|
|
$this->assertSame('Default alt', $meta->ogImageAlt);
|
|
}
|
|
}
|