96 lines
3.8 KiB
PHP
96 lines
3.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\PublicSite;
|
|
|
|
use App\Models\PortfolioCase;
|
|
use App\Models\Service;
|
|
use App\Models\SiteSetting;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class MediaPerformanceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_only_the_first_visible_content_image_is_prioritized(): void
|
|
{
|
|
SiteSetting::instance()->update(['about_image_path' => 'content/about.jpg']);
|
|
|
|
Service::factory()->published()->create([
|
|
'cover_image_path' => 'content/service-first.jpg',
|
|
'sort_order' => 1,
|
|
]);
|
|
Service::factory()->published()->create([
|
|
'cover_image_path' => 'content/service-later.jpg',
|
|
'sort_order' => 2,
|
|
]);
|
|
|
|
$firstCase = PortfolioCase::factory()->published()->create([
|
|
'cover_image_path' => 'content/case-first.jpg',
|
|
'slug' => 'case-first',
|
|
'sort_order' => 1,
|
|
]);
|
|
PortfolioCase::factory()->published()->create([
|
|
'cover_image_path' => 'content/case-later.jpg',
|
|
'sort_order' => 2,
|
|
]);
|
|
|
|
$services = $this->get(route('services.index'))->assertOk()->getContent();
|
|
$portfolio = $this->get(route('portfolio.index'))->assertOk()->getContent();
|
|
$about = $this->get(route('about'))->assertOk()->getContent();
|
|
$detail = $this->get(route('portfolio.show', $firstCase->slug))->assertOk()->getContent();
|
|
|
|
$this->assertStringNotContainsString('service-first.jpg', $services);
|
|
$this->assertStringNotContainsString('service-later.jpg', $services);
|
|
$this->assertMatchesRegularExpression('/case-first\.jpg"[^>]*loading="eager"[^>]*fetchpriority="high"/', $portfolio);
|
|
$this->assertMatchesRegularExpression('/case-later\.jpg"[^>]*loading="lazy"(?![^>]*fetchpriority)/', $portfolio);
|
|
$this->assertMatchesRegularExpression('/about\.jpg"[^>]*loading="eager"[^>]*fetchpriority="high"/', $about);
|
|
$this->assertMatchesRegularExpression('/case-first\.jpg"[^>]*loading="eager"[^>]*fetchpriority="high"/', $detail);
|
|
}
|
|
|
|
public function test_public_layout_preconnects_only_to_an_external_r2_media_origin(): void
|
|
{
|
|
config([
|
|
'app.url' => 'https://amare.example.test',
|
|
'filesystems.default' => 'r2',
|
|
'filesystems.disks.r2.url' => 'https://media.example.test/public',
|
|
]);
|
|
|
|
$external = $this->get(route('home'));
|
|
|
|
$external
|
|
->assertOk()
|
|
->assertSee('<link rel="preconnect" href="https://media.example.test" crossorigin>', false);
|
|
|
|
config([
|
|
'filesystems.default' => 'public',
|
|
'filesystems.disks.public.url' => '/storage',
|
|
]);
|
|
|
|
$local = $this->get(route('home'));
|
|
|
|
$local
|
|
->assertOk()
|
|
->assertDontSee('rel="preconnect"', false);
|
|
}
|
|
|
|
public function test_first_visible_index_images_are_prioritized_when_earlier_records_have_no_cover(): void
|
|
{
|
|
SiteSetting::instance();
|
|
|
|
Service::factory()->published()->create(['cover_image_path' => '', 'sort_order' => 1]);
|
|
Service::factory()->published()->create(['cover_image_path' => 'content/visible-service.jpg', 'sort_order' => 2]);
|
|
|
|
PortfolioCase::factory()->published()->create(['cover_image_path' => '', 'sort_order' => 1]);
|
|
PortfolioCase::factory()->published()->create(['cover_image_path' => 'content/visible-case.jpg', 'sort_order' => 2]);
|
|
|
|
$services = $this->get(route('services.index'))->assertOk()->getContent();
|
|
$portfolio = $this->get(route('portfolio.index'))->assertOk()->getContent();
|
|
|
|
$this->assertStringNotContainsString('visible-service.jpg', $services);
|
|
$this->assertMatchesRegularExpression('/visible-case\.jpg"[^>]*loading="eager"[^>]*fetchpriority="high"/', $portfolio);
|
|
}
|
|
}
|