Files
SkinbaseNova/tests/Unit/Seo/SeoDataBuilderTest.php

43 lines
1.4 KiB
PHP

<?php
use App\Support\Seo\SeoDataBuilder;
use Tests\TestCase;
uses(TestCase::class);
it('normalizes a single associative structured data schema', function () {
$seo = SeoDataBuilder::fromArray([
'title' => 'Categories',
'structured_data' => [
'@context' => 'https://schema.org',
'@type' => 'CollectionPage',
'name' => 'Categories',
],
])->build()->toArray();
expect($seo['json_ld'] ?? [])
->toHaveCount(1)
->and($seo['json_ld'][0]['@type'] ?? null)->toBe('CollectionPage');
});
it('normalizes JSON string structured data schemas', function () {
$seo = SeoDataBuilder::fromArray([
'title' => 'Categories',
'structured_data' => '{"@context":"https://schema.org","@type":"CollectionPage","name":"Categories"}',
])->build()->toArray();
expect($seo['json_ld'] ?? [])
->toHaveCount(1)
->and($seo['json_ld'][0]['@context'] ?? null)->toBe('https://schema.org')
->and($seo['json_ld'][0]['@type'] ?? null)->toBe('CollectionPage');
});
it('normalizes canonical page urls to the configured public app domain', function () {
config()->set('app.url', 'https://skinbase.org');
$seo = SeoDataBuilder::fromArray([
'canonical' => 'https://thumb.skinbase.top/search?q=winstep',
])->build()->toArray();
expect($seo['canonical'] ?? null)->toBe('https://skinbase.org/search?q=winstep');
});