published()
->forPortal($portal)
->for(Category::factory()->create(['portal' => $portal]))
->for(Company::factory()->businessportal24()->create())
->create(['slug' => $slug, ...$attributes]);
}
test('the news sitemap lists only releases of the last 48 hours of the own portal', function () {
/** @var TestCase $this */
newsSitemapRelease(Portal::Businessportal24, 'frisch', ['title' => 'Frische Meldung & mehr', 'published_at' => now()->subHours(3)]);
newsSitemapRelease(Portal::Both, 'beide-portale', ['published_at' => now()->subHours(20)]);
newsSitemapRelease(Portal::Businessportal24, 'zu-alt', ['published_at' => now()->subDays(3)]);
newsSitemapRelease(Portal::Presseecho, 'fremdes-portal', ['published_at' => now()->subHour()]);
newsSitemapRelease(Portal::Businessportal24, 'terminiert', ['published_at' => now()->addHour()]);
$response = $this->get('https://businessportal24.test/sitemap-news.xml')->assertSuccessful();
expect($response->headers->get('Content-Type'))->toContain('application/xml');
$xml = (string) $response->getContent();
expect($xml)
->toContain('xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"')
->toContain('https://businessportal24.test/de/press-release/frisch')
->toContain('businessportal24')
->toContain('de')
->toContain('Frische Meldung & mehr')
->toContain('https://businessportal24.test/de/press-release/beide-portale');
$this->assertStringNotContainsString('zu-alt', $xml);
$this->assertStringNotContainsString('fremdes-portal', $xml);
$this->assertStringNotContainsString('terminiert', $xml);
});
test('the hub serves an empty news sitemap and does not advertise it in robots.txt', function () {
/** @var TestCase $this */
newsSitemapRelease(Portal::Presseecho, 'nicht-im-hub', ['published_at' => now()->subHour()]);
$xml = (string) $this->get('https://pressekonto.test/sitemap-news.xml')->assertSuccessful()->getContent();
expect($xml)->toContain('assertStringNotContainsString('', $xml);
$robots = (string) $this->get('https://pressekonto.test/robots.txt')->getContent();
$this->assertStringNotContainsString('sitemap-news.xml', $robots);
$this->get('https://presseecho.test/robots.txt')
->assertSee('Sitemap: https://presseecho.test/sitemap-news.xml', false);
});
test('the news sitemap is cached per host and cleared with the other sitemaps', function () {
/** @var TestCase $this */
$this->get('https://presseecho.test/sitemap-news.xml')->assertSuccessful();
expect(Cache::has('web.sitemap-news.presseecho.test'))->toBeTrue();
WebCaches::forgetSitemaps();
expect(Cache::has('web.sitemap-news.presseecho.test'))->toBeFalse();
});