58 lines
2.0 KiB
PHP
58 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Services\ArtworkService;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Support\Collection;
|
|
|
|
/** Return an empty LengthAwarePaginator with the given path. */
|
|
function emptyPaginator(string $path = '/'): LengthAwarePaginator
|
|
{
|
|
return (new LengthAwarePaginator(collect(), 0, 20, 1))->setPath($path);
|
|
}
|
|
|
|
beforeEach(function () {
|
|
// Swap ArtworkService so tests need no database
|
|
$this->artworksMock = Mockery::mock(ArtworkService::class);
|
|
$this->artworksMock->shouldReceive('getFeaturedArtworks')->andReturn(emptyPaginator('/'))->byDefault();
|
|
$this->artworksMock->shouldReceive('getLatestArtworks')->andReturn(collect())->byDefault();
|
|
$this->app->instance(ArtworkService::class, $this->artworksMock);
|
|
});
|
|
|
|
it('renders the home page successfully', function () {
|
|
$this->get('/')
|
|
->assertStatus(200);
|
|
});
|
|
|
|
it('renders the home page with grid=v2 without errors', function () {
|
|
$this->get('/?grid=v2')
|
|
->assertStatus(200);
|
|
});
|
|
|
|
it('home page contains the gallery section', function () {
|
|
$this->get('/')
|
|
->assertStatus(200)
|
|
->assertSee('data-nova-gallery', false);
|
|
});
|
|
|
|
it('home page includes a canonical link tag', function () {
|
|
$this->get('/')
|
|
->assertStatus(200)
|
|
->assertSee('rel="canonical"', false);
|
|
});
|
|
|
|
it('home page with ?page=2 renders without errors', function () {
|
|
// getLatestArtworks() returns a plain Collection (no pagination),
|
|
// so seoNext/seoPrev for home are always null — but the page must still render cleanly.
|
|
$this->get('/?page=2')
|
|
->assertStatus(200)
|
|
->assertSee('rel="canonical"', false);
|
|
});
|
|
|
|
it('home page does not throw undefined variable errors', function () {
|
|
// If any Blade variable is undefined an exception is thrown → non-200 status
|
|
// This test explicitly guards against regressions on $gridV2 / $seoCanonical
|
|
expect(
|
|
fn () => $this->get('/')->assertStatus(200)
|
|
)->not->toThrow(\ErrorException::class);
|
|
});
|