Http::response(file_get_contents(__DIR__.'/Fixtures/rss-press.xml')),
]);
$cision = new Cision('test-company');
$data = $cision->press();
expect($data)->toBeArray();
expect($data)->toHaveKey('items');
expect($data['items'])->not->toBeEmpty();
$item = $data['items'][0];
expect($item)->toHaveKeys(['guid', 'title', 'description', 'link', 'created_at']);
});
it('can fetch and parse full article content', function () {
Http::fake([
'news.cision.com/*' => Http::response(file_get_contents(__DIR__.'/Fixtures/article.html')),
]);
$cision = new Cision('test-company');
$content = $cision->fetchContent('https://news.cision.com/se/example/r/test,c123456');
expect($content)->toHaveKeys(['header', 'published_at', 'content']);
expect($content['header'])->not->toBeEmpty();
expect($content['content'])->toContain('
<<
- aADL{$date}
XML;
Http::fakeSequence()
->push($rss('Fri, 04 Jul 2025 07:55:00 GMT'))
->push($rss('Wed, 15 Jan 2025 07:55:00 GMT'));
$cision = new Cision('test-company');
expect($cision->press()['items'][0]['created_at'])->toBe('2025-07-04 09:55:00');
expect($cision->press()['items'][0]['created_at'])->toBe('2025-01-15 08:55:00');
});
it('returns empty strings for empty feed elements', function () {
Http::fake([
'news.cision.com/*' => Http::response(<<<'XML'
- aALFri, 04 Jul 2025 07:55:00 GMT
XML),
]);
expect((new Cision('test-company'))->press()['items'][0]['description'])->toBe('');
});
it('returns false when the feed request fails', function () {
Http::fake(['news.cision.com/*' => Http::response('', 500)]);
expect((new Cision('test-company'))->press())->toBeFalse();
});
it('returns false when the article request fails', function () {
Http::fake(['news.cision.com/*' => Http::response('', 404)]);
expect((new Cision('test-company'))->fetchContent('https://news.cision.com/se/x'))->toBeFalse();
});
it('returns false when the page has no article', function () {
Http::fake(['news.cision.com/*' => Http::response('Nope
')]);
expect((new Cision('test-company'))->fetchContent('https://news.cision.com/se/x'))->toBeFalse();
});
it('marks paragraphs that start with italic text', function () {
Http::fake([
'news.cision.com/*' => Http::response(file_get_contents(__DIR__.'/Fixtures/article.html')),
]);
$content = (new Cision('test-company'))->fetchContent('https://news.cision.com/se/x')['content'];
expect($content)
->toContain('Italic sentence.
')
->toContain('Lead: This is a test article paragraph.
')
->not->toContain('Test Article Header');
});
it('uses the configured slug when none is given', function () {
config()->set('cision.slug', 'configured-company');
Http::fake([
'news.cision.com/*' => Http::response(file_get_contents(__DIR__.'/Fixtures/rss-press.xml')),
]);
Mattitja\Cision\Facades\Cision::press();
Http::assertSent(fn ($request) => str_contains($request->url(), 'n=configured-company'));
});