2.0 #1
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
arch('it will not use debugging functions')
|
||||||
|
->expect(['dd', 'dump', 'ray'])
|
||||||
|
->each->not->toBeUsed();
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Mattitja\Cision\Cision;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
it('can fetch press releases from the RSS feed', function () {
|
||||||
|
Http::fake([
|
||||||
|
'news.cision.com/*' => 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();
|
||||||
|
$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('<p');
|
||||||
|
});
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
<article>
|
||||||
|
<div>
|
||||||
|
<h1>Test Article Header</h1>
|
||||||
|
<time pubdate="2025-07-04 07:55:00Z" datetime="2025-07-04 07:55:00Z">fre, jul 04, 2025 09:55 CET</time>
|
||||||
|
<p><strong>Lead:</strong> This is a test article paragraph.</p>
|
||||||
|
<p><em>Italic sentence.</em></p>
|
||||||
|
<ul>
|
||||||
|
<li><strong>Key:</strong> Value</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<rss version="2.0">
|
||||||
|
<channel>
|
||||||
|
<title>Test Press Releases</title>
|
||||||
|
<item>
|
||||||
|
<guid>test-guid</guid>
|
||||||
|
<title>Test Press Title</title>
|
||||||
|
<description>This is a test press release description.</description>
|
||||||
|
<link>https://news.cision.com/se/example/r/test,c123456</link>
|
||||||
|
<pubDate>Fri, 04 Jul 2025 07:55:00 GMT</pubDate>
|
||||||
|
</item>
|
||||||
|
</channel>
|
||||||
|
</rss>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Mattitja\Cision\Tests\TestCase;
|
||||||
|
|
||||||
|
uses(TestCase::class)->in(__DIR__);
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Mattitja\Cision\Tests;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
use Mattitja\Cision\CisionServiceProvider;
|
||||||
|
use Orchestra\Testbench\TestCase as Orchestra;
|
||||||
|
|
||||||
|
class TestCase extends Orchestra
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Factory::guessFactoryNamesUsing(
|
||||||
|
fn (string $modelName) => 'Mattitja\\Cision\\Database\\Factories\\'.class_basename($modelName).'Factory'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getPackageProviders($app)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
CisionServiceProvider::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
config()->set('database.default', 'testing');
|
||||||
|
|
||||||
|
/*
|
||||||
|
foreach (\Illuminate\Support\Facades\File::allFiles(__DIR__ . '/database/migrations') as $migration) {
|
||||||
|
(include $migration->getRealPath())->up();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
-4
@@ -114,30 +114,41 @@ class Cision
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Suppress XML parsing warnings
|
||||||
|
libxml_use_internal_errors(true);
|
||||||
$xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
|
$xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
|
||||||
|
libxml_clear_errors();
|
||||||
|
|
||||||
if ($xml === false) {
|
if ($xml === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert XML to JSON then to array
|
||||||
$json = json_encode($xml);
|
$json = json_encode($xml);
|
||||||
$rows = json_decode($json, true);
|
$rows = json_decode($json, true);
|
||||||
|
|
||||||
|
// Validate structure
|
||||||
if (!isset($rows['channel']['item'])) {
|
if (!isset($rows['channel']['item'])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = array_map(fn ($item) => [
|
// Ensure 'item' is always an array
|
||||||
|
$items = $rows['channel']['item'];
|
||||||
|
$items = isset($items[0]) ? $items : [$items];
|
||||||
|
|
||||||
|
// Format the result
|
||||||
|
$formatted = array_map(fn ($item) => [
|
||||||
'guid' => $item['guid'],
|
'guid' => $item['guid'],
|
||||||
'title' => $item['title'],
|
'title' => $item['title'],
|
||||||
'description' => $item['description'],
|
'description' => $item['description'],
|
||||||
'link' => $item['link'],
|
'link' => $item['link'],
|
||||||
'created_at' => Carbon::parse($item['pubDate'])->addHours(2)->format('Y-m-d H:i:s'),
|
'created_at' => Carbon::parse($item['pubDate'])->addHours(2)->format('Y-m-d H:i:s'),
|
||||||
], $rows['channel']['item']);
|
], $items);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'items' => $items,
|
'items' => $formatted,
|
||||||
'previous_page' => $page > 1 ? $page - 1 : false,
|
'previous_page' => $page > 1 ? $page - 1 : false,
|
||||||
'next_page' => count($items) === 24 ? $page + 1 : false,
|
'next_page' => count($formatted) === 24 ? $page + 1 : false,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user