Skip to content

Commit

Permalink
include featured image for h-entry
Browse files Browse the repository at this point in the history
closes #51
  • Loading branch information
aaronpk committed Jan 14, 2018
1 parent c376833 commit 2515f61
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/XRay/Formats/Mf2.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private static function parseAsHEntry($mf2, $item, $http, $url) {
$refs = [];

// Single plaintext and URL values
self::collectSingleValues(['published','summary','rsvp','swarm-coins'], ['url'], $item, $url, $data);
self::collectSingleValues(['published','summary','rsvp','swarm-coins'], ['url','featured'], $item, $url, $data);

if(isset($data['rsvp']))
$data['rsvp'] = strtolower($data['rsvp']);
Expand Down
23 changes: 23 additions & 0 deletions tests/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ public function testTextContent() {
$this->assertEquals('This page has a link to target.example.com and some formatted text but is in a p-content element so is plaintext.', $data->data->content->text);
}

public function testArticleWithFeaturedImage() {
$url = 'http://source.example.com/article-with-featured-image';
$response = $this->parse(['url' => $url]);

$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('Post Title', $data->data->name);
$this->assertEquals('This is a blog post.', $data->data->content->text);
$this->assertEquals('http://source.example.com/featured.jpg', $data->data->featured);
}

public function testContentWithPrefixedName() {
$url = 'http://source.example.com/content-with-prefixed-name';
$response = $this->parse(['url' => $url]);
Expand Down Expand Up @@ -247,6 +259,17 @@ public function testSyndicationIsURL() {
$this->assertEquals('http://syndicated.example/', $data['data']['syndication'][0]);
}

public function testHEntryNoContent() {
$url = 'http://source.example.com/h-entry-no-content';
$response = $this->parse(['url' => $url]);

$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('content', $data->data);
$this->assertEquals('This is a Post', $data->data->name);
}

public function testHEntryIsNotFirstObject() {
$url = 'http://source.example.com/h-entry-is-not-first';
$response = $this->parse(['url' => $url]);
Expand Down
17 changes: 17 additions & 0 deletions tests/data/source.example.com/article-with-featured-image
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive

<html>
<head>
<title>Test</title>
</head>
<body class="h-entry">
<img src="/featured.jpg" class="u-featured" width="100%">
<img src="/featured2.jpg" class="u-featured" width="100%">
<h2 class="p-name">Post Title</h2>
<p class="e-content">This is a blog post.</p>
</body>
</html>

0 comments on commit 2515f61

Please sign in to comment.