Skip to content

Commit

Permalink
Merge pull request #243 from leonghui/add-jsonfeed-icon
Browse files Browse the repository at this point in the history
Add support for Icon in JSON feed
  • Loading branch information
alexdebril authored Nov 27, 2019
2 parents 52eb1b3 + 232540e commit e0e5234
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/FeedIo/Formatter/JsonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function toArray(FeedInterface $feed) : array
'home_page_url' => $feed->getLink(),
'feed_url' => $feed->getUrl(),
'id' => $feed->getPublicId(),
'icon' => $feed->getLogo(),
'items' => iterator_to_array($this->itemsToArray($feed)),
]);
}
Expand Down
1 change: 1 addition & 0 deletions src/FeedIo/Parser/JsonParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function parseContent(Document $document, FeedInterface $feed) : FeedInte
$feed->setDescription($this->readOffset($data, 'description'));
$feed->setLink($this->readOffset($data, 'feed_url'));
$feed->setUrl($this->readOffset($data, 'home_page_url'));
$feed->setLogo($this->readOffset($data, 'icon'));

if (array_key_exists('items', $data)) {
$this->parseItems($data['items'], $feed);
Expand Down
5 changes: 5 additions & 0 deletions tests/FeedIo/JsonFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

class JsonFormatterTest extends TestCase
{

const LOGO = 'http://localhost/logo.jpeg';

public function testToString()
{
$items = [
Expand All @@ -27,6 +30,7 @@ public function testToString()

$feed = new Feed();
$feed->setTitle('feed title');
$feed->setLogo(self::LOGO);

foreach ($items as $item) {
$feed->add($item);
Expand All @@ -39,6 +43,7 @@ public function testToString()
$json = json_decode($string, true);

$this->assertEquals('feed title', $json['title']);
$this->assertEquals('http://localhost/logo.jpeg', $json['icon']);
$this->assertCount(2, $json['items']);

foreach ($json['items'] as $item) {
Expand Down
3 changes: 2 additions & 1 deletion tests/FeedIo/Parser/JsonParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function testParseContent()
$parser->parse($this->getDocument(), $feed);

$this->assertEquals('JSON Feed', $feed->getTitle());

$this->assertEquals('https://jsonfeed.org/graphics/icon.png', $feed->getLogo());

$items = $feed->toArray()['items'];

$this->assertCount(4, $items);
Expand Down
1 change: 1 addition & 0 deletions tests/samples/feed.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"feed_url": "https://jsonfeed.org/feed.json",
"user_comment": "This feed allows you to read the posts from this site in any feed reader that supports the JSON Feed format. To add this feed to your reader, copy the following URL — https://jsonfeed.org/feed.json — and add it your reader.",
"favicon": "https://jsonfeed.org/graphics/icon.png",
"icon" : "https://jsonfeed.org/graphics/icon.png",
"author": {
"name": "Brent Simmons and Manton Reece"
},
Expand Down

0 comments on commit e0e5234

Please sign in to comment.