Files
amare/tests/Feature/PublicSite/AccessibilityStructureTest.php
Manoel Freitas 3dc1f449ee feat: ship public site with SEO and visuals (#3)
* 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>
2026-07-29 10:12:24 -03:00

87 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\PublicSite;
use App\Models\PortfolioCase;
use App\Models\PortfolioImage;
use App\Models\SiteSetting;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class AccessibilityStructureTest extends TestCase
{
use RefreshDatabase;
public function test_public_pages_have_single_h1_and_landmarks(): void
{
Storage::fake('public');
SiteSetting::instance();
$case = PortfolioCase::factory()->published()->create([
'slug' => 'casamento-jardim',
'title' => 'Casamento Jardim',
'cover_image_path' => 'cases/cover.jpg',
'cover_image_alt' => 'Capa do casamento',
]);
$routes = [
route('home'),
route('services.index'),
route('portfolio.index'),
route('portfolio.show', $case->slug),
route('about'),
route('privacy'),
route('contact'),
];
foreach ($routes as $url) {
$html = $this->get($url)->assertOk()->getContent();
$this->assertSame(1, preg_match_all('/<h1\b/i', $html), "Expected one h1 on {$url}");
$this->assertMatchesRegularExpression('/<header\b/i', $html);
$this->assertMatchesRegularExpression('/<nav\b/i', $html);
$this->assertMatchesRegularExpression('/<main\b/i', $html);
$this->assertMatchesRegularExpression('/<footer\b/i', $html);
$this->assertStringContainsString('href="#conteudo"', $html);
}
}
public function test_content_images_expose_alt_text(): void
{
Storage::fake('public');
SiteSetting::instance();
$case = PortfolioCase::factory()->published()->create([
'slug' => 'casamento-jardim',
'title' => 'Casamento Jardim',
'cover_image_path' => 'cases/cover.jpg',
'cover_image_alt' => 'Capa do casamento',
]);
PortfolioImage::query()->create([
'portfolio_case_id' => $case->id,
'path' => 'content/gallery-a.jpg',
'alt_text' => 'Galeria A',
'caption' => null,
'sort_order' => 1,
]);
$this->get(route('portfolio.show', $case->slug))
->assertOk()
->assertSee('alt="Capa do casamento"', false)
->assertSee('alt="Galeria A"', false);
}
public function test_interactive_elements_have_visible_focus_styles(): void
{
$css = file_get_contents(resource_path('css/app.css'));
$this->assertIsString($css);
$this->assertStringContainsString(':focus-visible', $css);
$this->assertStringContainsString('outline', $css);
}
}