From 87b2cf10d88c205e172ea15e8efa769871990ea9 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 9 Nov 2018 10:27:15 -0800 Subject: [PATCH] add follow-of posts replaces #78 --- README.md | 2 + lib/XRay/Formats/Mf2.php | 2 +- lib/XRay/PostType.php | 3 ++ tests/ParseTest.php | 23 +++++++++++ tests/data/source.example.com/bridgy-follow | 38 +++++++++++++++++++ .../data/source.example.com/follow-of-h-card | 38 +++++++++++++++++++ 6 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 tests/data/source.example.com/bridgy-follow create mode 100644 tests/data/source.example.com/follow-of-h-card diff --git a/README.md b/README.md index 326519d..f42eea6 100644 --- a/README.md +++ b/README.md @@ -384,6 +384,7 @@ If a property supports multiple values, it will always be returned as an array. * `like-of` * `repost-of` * `bookmark-of` +* `follow-of` * `syndication` * `photo` (of an entry, not of a card) * `video` @@ -410,6 +411,7 @@ The following post types are returned, which are slightly expanded from what is * `like` * `reply` * `bookmark` +* `follow` * `checkin` * `video` * `audio` diff --git a/lib/XRay/Formats/Mf2.php b/lib/XRay/Formats/Mf2.php index 9187d0c..4e6a10f 100644 --- a/lib/XRay/Formats/Mf2.php +++ b/lib/XRay/Formats/Mf2.php @@ -430,7 +430,7 @@ class Mf2 extends Format { $refs = []; // Single plaintext and URL values - self::collectSingleValues(['published','summary','rsvp','swarm-coins'], ['url','featured'], $item, $url, $data); + self::collectSingleValues(['published','summary','rsvp','swarm-coins'], ['url','featured','follow-of'], $item, $url, $data); if(isset($data['rsvp'])) $data['rsvp'] = strtolower($data['rsvp']); diff --git a/lib/XRay/PostType.php b/lib/XRay/PostType.php index 9d2e186..ed6610a 100644 --- a/lib/XRay/PostType.php +++ b/lib/XRay/PostType.php @@ -26,6 +26,9 @@ class PostType { if(isset($post['bookmark-of'])) return 'bookmark'; + if(isset($post['follow-of'])) + return 'follow'; + if(isset($post['checkin'])) return 'checkin'; diff --git a/tests/ParseTest.php b/tests/ParseTest.php index 141b7fb..86d5380 100644 --- a/tests/ParseTest.php +++ b/tests/ParseTest.php @@ -970,4 +970,27 @@ class ParseTest extends PHPUnit_Framework_TestCase { $this->assertEquals('mf2+html', $data['source-format']); } + public function testFollowOf() { + $url = 'http://source.example.com/bridgy-follow'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body, true); + + $this->assertEquals('https://realize.be/', $data['data']['follow-of']); + $this->assertEquals('follow', $data['data']['post-type']); + } + + public function testFollowOfHCard() { + $url = 'http://source.example.com/follow-of-h-card'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body, true); + + $this->assertEquals('https://realize.be/', $data['data']['follow-of']); + $this->assertEquals('follow', $data['data']['post-type']); + } } diff --git a/tests/data/source.example.com/bridgy-follow b/tests/data/source.example.com/bridgy-follow new file mode 100644 index 0000000..1eb9b2f --- /dev/null +++ b/tests/data/source.example.com/bridgy-follow @@ -0,0 +1,38 @@ +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 + + + + + +
+ https://mastodon.social/b8177a60-8f80-47a0-b943-a9df876cf5d5 + + + + + + https://mastodon.social/@swentel + + + + + +
+ + +
+ + + + + + + +
+ + + diff --git a/tests/data/source.example.com/follow-of-h-card b/tests/data/source.example.com/follow-of-h-card new file mode 100644 index 0000000..1ea05cf --- /dev/null +++ b/tests/data/source.example.com/follow-of-h-card @@ -0,0 +1,38 @@ +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 + + + + + +
+ https://mastodon.social/b8177a60-8f80-47a0-b943-a9df876cf5d5 + + + + + + https://mastodon.social/@swentel + + + + + +
+ + +
+ + + + + +swentel + +
+ + +