From 2515f618c770be20ffab937dba8e8363a81e44b1 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 13 Jan 2018 16:08:28 -0800 Subject: [PATCH] include featured image for h-entry closes #51 --- lib/XRay/Formats/Mf2.php | 2 +- tests/ParseTest.php | 23 +++++++++++++++++++ .../article-with-featured-image | 17 ++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/data/source.example.com/article-with-featured-image diff --git a/lib/XRay/Formats/Mf2.php b/lib/XRay/Formats/Mf2.php index b46ed1d..dbb03e0 100644 --- a/lib/XRay/Formats/Mf2.php +++ b/lib/XRay/Formats/Mf2.php @@ -360,7 +360,7 @@ class Mf2 extends Format { $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']); diff --git a/tests/ParseTest.php b/tests/ParseTest.php index ab01e38..ff4dde5 100644 --- a/tests/ParseTest.php +++ b/tests/ParseTest.php @@ -118,6 +118,18 @@ class ParseTest extends PHPUnit_Framework_TestCase { $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]); @@ -247,6 +259,17 @@ class ParseTest extends PHPUnit_Framework_TestCase { $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]); diff --git a/tests/data/source.example.com/article-with-featured-image b/tests/data/source.example.com/article-with-featured-image new file mode 100644 index 0000000..35b5fbb --- /dev/null +++ b/tests/data/source.example.com/article-with-featured-image @@ -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 + + + + Test + + + + +

Post Title

+

This is a blog post.

+ +