Files
amare/tests/Feature/PublicSite/PublicPagesTest.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

180 lines
5.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\PublicSite;
use App\Models\PortfolioCase;
use App\Models\PortfolioImage;
use App\Models\Service;
use App\Models\SiteSetting;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
use Tests\TestCase;
class PublicPagesTest extends TestCase
{
use RefreshDatabase;
public function test_services_index_lists_published_services_in_sort_order(): void
{
SiteSetting::instance();
Service::factory()->create(['title' => 'Rascunho', 'published_at' => null]);
Service::factory()->published()->create(['title' => 'Serviço B', 'sort_order' => 20]);
Service::factory()->published()->create(['title' => 'Serviço A', 'sort_order' => 10]);
$this->get(route('services.index'))
->assertOk()
->assertSeeInOrder(['Serviço A', 'Serviço B'])
->assertDontSee('Rascunho');
}
public function test_portfolio_index_paginates_and_excludes_drafts(): void
{
SiteSetting::instance();
PortfolioCase::factory()->create(['title' => 'Rascunho', 'published_at' => null]);
foreach (range(1, 10) as $index) {
PortfolioCase::factory()->published()->create([
'title' => 'Caso '.$index,
'slug' => 'caso-pagina-'.$index,
'sort_order' => $index,
]);
}
$this->assertSame(10, PortfolioCase::query()->published()->count());
$this->get(route('portfolio.index'))
->assertOk()
->assertSee('>Caso 1</', false)
->assertSee('>Caso 9</', false)
->assertDontSee('>Caso 10</', false)
->assertDontSee('Rascunho');
$this->get(route('portfolio.index', ['page' => 2]))
->assertOk()
->assertSee('>Caso 10</', false)
->assertDontSee('>Caso 9</', false);
}
public function test_portfolio_show_renders_published_case_gallery_order_and_404_for_draft(): void
{
SiteSetting::instance();
$published = PortfolioCase::factory()->published()->create([
'slug' => 'casamento-jardim',
'title' => 'Casamento Jardim',
'challenge' => 'Desafio do caso',
'solution' => 'Solução do caso',
'result' => 'Resultado do caso',
]);
PortfolioImage::query()->create([
'portfolio_case_id' => $published->id,
'path' => 'content/gallery-b.jpg',
'alt_text' => 'Imagem B',
'caption' => null,
'sort_order' => 2,
]);
PortfolioImage::query()->create([
'portfolio_case_id' => $published->id,
'path' => 'content/gallery-a.jpg',
'alt_text' => 'Imagem A',
'caption' => null,
'sort_order' => 1,
]);
PortfolioCase::factory()->create([
'slug' => 'rascunho',
'published_at' => null,
]);
$this->get(route('portfolio.show', 'casamento-jardim'))
->assertOk()
->assertSee('Casamento Jardim')
->assertSee('Desafio do caso')
->assertSee('Solução do caso')
->assertSee('Resultado do caso')
->assertSeeInOrder(['Imagem A', 'Imagem B']);
$this->get(route('portfolio.show', 'rascunho'))->assertNotFound();
}
public function test_about_privacy_and_contact_use_site_settings_without_creating_leads(): void
{
$settings = SiteSetting::instance();
$settings->update([
'about_summary' => 'Sobre a Amare boutique',
'email' => 'contato@amare.test',
'phone' => '(85) 90000-0000',
'social_links' => ['instagram' => 'https://instagram.com/amare'],
]);
$this->get(route('about'))
->assertOk()
->assertSee('Sobre a Amare boutique');
$this->get(route('privacy'))
->assertOk()
->assertSee('Política de privacidade')
->assertSee('contato@amare.test');
$this->get(route('contact'))
->assertOk()
->assertSee('contato@amare.test')
->assertSee('(85) 90000-0000')
->assertSee('https://instagram.com/amare', false);
}
public function test_branded_404_and_500_without_stack_trace_when_debug_disabled(): void
{
SiteSetting::instance();
$this->get('/rota-inexistente-amare')
->assertNotFound()
->assertSee('Página não encontrada')
->assertSee('Voltar para a home');
Route::get('/__test-server-error', function (): never {
throw new \RuntimeException('segredo-interno-amare');
});
config(['app.debug' => false]);
$response = $this->get('/__test-server-error');
$response
->assertStatus(500)
->assertSee('Algo deu errado')
->assertDontSee('segredo-interno-amare')
->assertDontSee('RuntimeException');
}
public function test_portfolio_show_avoids_n_plus_one_on_gallery(): void
{
SiteSetting::instance();
$case = PortfolioCase::factory()->published()->create(['slug' => 'caso-n1']);
foreach (range(1, 8) as $order) {
PortfolioImage::query()->create([
'portfolio_case_id' => $case->id,
'path' => "content/gallery-{$order}.jpg",
'alt_text' => "Imagem {$order}",
'caption' => null,
'sort_order' => $order,
]);
}
DB::enableQueryLog();
$this->get(route('portfolio.show', 'caso-n1'))->assertOk();
$queryCount = count(DB::getQueryLog());
DB::disableQueryLog();
$this->assertLessThan(15, $queryCount);
}
}