create(['portal' => Portal::Presseecho, 'is_active' => true]); $category->translations()->create(['locale' => 'de', 'name' => 'Handel', 'slug' => 'handel']); $category->translations()->create(['locale' => 'en', 'name' => 'Commerce', 'slug' => 'commerce']); return $category; } function archiveRelease(Category $category, string $slug, string $publishedAt, array $attributes = []): PressRelease { return PressRelease::factory() ->published() ->forPortal(Portal::Presseecho) ->for($category) ->for(Company::factory()->presseecho()->create(['name' => 'Archiv GmbH'])) ->create(['slug' => $slug, 'published_at' => $publishedAt, ...$attributes]); } test('the archive lists the releases of one year, newest first, with a year navigation', function () { /** @var TestCase $this */ $category = archiveCategory(); archiveRelease($category, 'alt-2019', '2019-03-01 10:00:00', ['title' => 'Meldung aus 2019']); archiveRelease($category, 'alt-2019-spaeter', '2019-11-01 10:00:00', ['title' => 'Spätere Meldung 2019']); archiveRelease($category, 'alt-2021', '2021-05-01 10:00:00', ['title' => 'Meldung aus 2021']); $response = $this->get('https://presseecho.test/de/category/handel/archiv/2019')->assertSuccessful(); $response ->assertSee('Pressemitteilungen Handel 2019') ->assertSee('Spätere Meldung 2019') ->assertSee('Meldung aus 2019') ->assertSee('Archiv GmbH') ->assertSee('/de/category/handel/archiv/2021', false) ->assertSee('', false) ->assertSee('"@type":"CollectionPage"', false) ->assertSee('hreflang="en" href="https://presseecho.test/en/category/commerce/archiv/2019"', false); // Nur die Liste prüfen — der Live-Ticker im Kopf zeigt die jüngste Meldung (2021). $list = Str::between((string) $response->getContent(), '
    ', '
'); expect($list)->toContain('Spätere Meldung 2019'); $this->assertStringNotContainsString('Meldung aus 2021', $list); expect(strpos($list, 'Spätere Meldung 2019'))->toBeLessThan((int) strpos($list, 'Meldung aus 2019')); }); test('without a year the archive opens the latest year with releases', function () { /** @var TestCase $this */ $category = archiveCategory(); archiveRelease($category, 'alt-2019', '2019-03-01 10:00:00'); archiveRelease($category, 'alt-2021', '2021-05-01 10:00:00', ['title' => 'Meldung aus 2021']); $this->get('https://presseecho.test/de/category/handel/archiv') ->assertSuccessful() ->assertSee('Pressemitteilungen Handel 2021') ->assertSee('Meldung aus 2021'); }); test('years without releases, unknown categories and empty pages are 404', function () { /** @var TestCase $this */ $category = archiveCategory(); archiveRelease($category, 'alt-2019', '2019-03-01 10:00:00'); $this->get('https://presseecho.test/de/category/handel/archiv/2018')->assertNotFound(); $this->get('https://presseecho.test/de/category/gibt-es-nicht/archiv/2019')->assertNotFound(); $this->get('https://presseecho.test/de/category/handel/archiv/2019?page=2')->assertNotFound(); }); test('follow-up pages carry the page in canonical and title', function () { /** @var TestCase $this */ $category = archiveCategory(); foreach (range(1, CategoryArchivePageData::PerPage + 1) as $i) { archiveRelease($category, 'meldung-'.$i, sprintf('2020-01-%02d 10:00:00', min($i, 28)), ['title' => 'Meldung Nr. '.$i]); } $this->get('https://presseecho.test/de/category/handel/archiv/2020?page=2') ->assertSuccessful() ->assertSee('', false) ->assertSee('Seite 2') ->assertDontSee('hreflang=', false); }); test('the category page links its archive years and the sitemap lists them', function () { /** @var TestCase $this */ $category = archiveCategory(); archiveRelease($category, 'alt-2019', '2019-03-01 10:00:00'); archiveRelease($category, 'neu', now()->subDay()->toDateTimeString()); $this->get('https://presseecho.test/de/category/handel') ->assertSuccessful() ->assertSee('Archiv Handel') ->assertSee('/de/category/handel/archiv/2019', false) ->assertSee('/de/category/handel/archiv/'.now()->year, false); $this->get('https://presseecho.test/sitemap.xml') ->assertSuccessful() ->assertSee('https://presseecho.test/de/category/handel/archiv/2019', false); });