128 lines
4.3 KiB
PHP
128 lines
4.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\User;
|
|
use App\Models\World;
|
|
use App\Services\HomepageService;
|
|
use Illuminate\Support\Carbon;
|
|
use Inertia\Testing\AssertableInertia;
|
|
|
|
function publicWorld(array $attributes = []): World
|
|
{
|
|
$creator = $attributes['creator'] ?? User::factory()->create([
|
|
'username' => 'publicworlds',
|
|
'name' => 'Public Worlds',
|
|
]);
|
|
|
|
unset($attributes['creator']);
|
|
|
|
return World::query()->create(array_merge([
|
|
'title' => 'Summer Slam 2026',
|
|
'slug' => 'summer-slam-2026',
|
|
'tagline' => 'Sunlit publishing and warm-color campaigns.',
|
|
'summary' => 'A bright world for summer culture across the platform.',
|
|
'description' => 'Public world description',
|
|
'theme_key' => 'summer',
|
|
'status' => World::STATUS_PUBLISHED,
|
|
'type' => World::TYPE_SEASONAL,
|
|
'is_featured' => true,
|
|
'starts_at' => Carbon::parse('2026-06-01 00:00:00'),
|
|
'ends_at' => Carbon::parse('2026-08-31 23:59:59'),
|
|
'published_at' => Carbon::parse('2026-04-01 10:00:00'),
|
|
'created_by_user_id' => $creator->id,
|
|
], $attributes));
|
|
}
|
|
|
|
it('renders public worlds index and detail pages', function (): void {
|
|
$world = publicWorld();
|
|
|
|
$this->get(route('worlds.index'))
|
|
->assertOk()
|
|
->assertInertia(fn (AssertableInertia $page) => $page
|
|
->component('World/WorldIndex')
|
|
->where('featuredWorld.title', 'Summer Slam 2026')
|
|
->has('activeWorlds'));
|
|
|
|
$this->get(route('worlds.show', ['world' => $world->slug]))
|
|
->assertOk()
|
|
->assertInertia(fn (AssertableInertia $page) => $page
|
|
->component('World/WorldShow')
|
|
->where('world.title', 'Summer Slam 2026')
|
|
->where('world.slug', 'summer-slam-2026'));
|
|
});
|
|
|
|
it('falls back to the theme icon when the stored world icon is blank whitespace', function (): void {
|
|
$world = publicWorld([
|
|
'title' => 'Spring Vibes',
|
|
'slug' => 'spring-vibes',
|
|
'theme_key' => 'summer',
|
|
'icon_name' => ' ',
|
|
]);
|
|
|
|
$this->get(route('worlds.show', ['world' => $world->slug]))
|
|
->assertOk()
|
|
->assertInertia(fn (AssertableInertia $page) => $page
|
|
->component('World/WorldShow')
|
|
->where('world.title', 'Spring Vibes')
|
|
->where('world.icon_name', 'fa-solid fa-sun')
|
|
->where('world.theme.icon_name', 'fa-solid fa-sun'));
|
|
});
|
|
|
|
it('omits disabled sections from the public world payload', function (): void {
|
|
$world = publicWorld([
|
|
'title' => 'Curated Autumn 2026',
|
|
'slug' => 'curated-autumn-2026',
|
|
'section_visibility_json' => [
|
|
'featured_creators' => false,
|
|
],
|
|
]);
|
|
|
|
$world->worldRelations()->create([
|
|
'section_key' => 'featured_creators',
|
|
'related_type' => 'user',
|
|
'related_id' => $world->created_by_user_id,
|
|
'context_label' => 'Editorial spotlight',
|
|
'sort_order' => 0,
|
|
'is_featured' => true,
|
|
]);
|
|
|
|
$this->get(route('worlds.show', ['world' => $world->slug]))
|
|
->assertOk()
|
|
->assertInertia(fn (AssertableInertia $page) => $page
|
|
->component('World/WorldShow')
|
|
->where('world.title', 'Curated Autumn 2026')
|
|
->where('sections', []));
|
|
});
|
|
|
|
it('keeps archived worlds publicly visible', function (): void {
|
|
$world = publicWorld([
|
|
'title' => 'Halloween World 2025',
|
|
'slug' => 'halloween-world-2025',
|
|
'theme_key' => 'halloween',
|
|
'status' => World::STATUS_ARCHIVED,
|
|
'starts_at' => Carbon::parse('2025-10-01 00:00:00'),
|
|
'ends_at' => Carbon::parse('2025-11-01 00:00:00'),
|
|
'published_at' => Carbon::parse('2025-09-20 10:00:00'),
|
|
]);
|
|
|
|
$this->get(route('worlds.show', ['world' => $world->slug]))
|
|
->assertOk()
|
|
->assertSee('Halloween World 2025');
|
|
});
|
|
|
|
it('exposes a homepage world spotlight when a featured world exists', function (): void {
|
|
publicWorld([
|
|
'title' => 'Pixel Week 2026',
|
|
'slug' => 'pixel-week-2026',
|
|
'theme_key' => 'pixel-week',
|
|
]);
|
|
|
|
app(HomepageService::class)->clearGuestPayloadCache();
|
|
|
|
$this->get(route('index'))
|
|
->assertOk()
|
|
->assertSee(route('worlds.index'), false)
|
|
->assertSee('pixel-week-2026')
|
|
->assertSee('Pixel Week 2026');
|
|
}); |