From a1234f61e39b99f65949bf555140bb71385fa7cb Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 15 Apr 2017 08:50:16 -0700 Subject: [PATCH] recognize h-card if it's the only object closes #36 --- lib/Formats/Mf2.php | 8 ++++++ tests/AuthorTest.php | 28 +++++++++++++++++++ tests/data/author.example.com/about-no-url | 22 +++++++++++++++ ...-entry-author-is-url-to-h-card-with-no-url | 21 ++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 tests/data/author.example.com/about-no-url create mode 100644 tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-no-url diff --git a/lib/Formats/Mf2.php b/lib/Formats/Mf2.php index a60c21a..09ea6ef 100644 --- a/lib/Formats/Mf2.php +++ b/lib/Formats/Mf2.php @@ -37,6 +37,10 @@ class Mf2 { Parse::debug("mf2:0: Recognized $url as an h-feed because it is the only item on the page"); return self::parseAsHFeed($mf2, $http); } + if(in_array('h-card', $item['type'])) { + Parse::debug("mf2:0: Recognized $url as an h-card it is the only item on the page"); + return self::parseAsHCard($item, $http, $url); + } } // Check the list of items on the page to see if one matches the URL of the page, @@ -503,6 +507,10 @@ class Mf2 { } } + // If no URL property was found, use the $authorURL provided + if(!$data['url']) + $data['url'] = $authorURL; + $response = [ 'data' => $data ]; diff --git a/tests/AuthorTest.php b/tests/AuthorTest.php index 120e660..bf41b3d 100644 --- a/tests/AuthorTest.php +++ b/tests/AuthorTest.php @@ -98,6 +98,20 @@ class AuthorTest extends PHPUnit_Framework_TestCase { $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo); } + public function testHEntryAuthorIsUrlToHCardWithNoURL() { + $url = 'http://author.example.com/h-entry-author-is-url-to-h-card-with-no-url'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body); + + $this->assertEquals('http://author.example.com/about-no-url', $data->data->author->url); + $this->assertEquals('Author Full Name', $data->data->author->name); + $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo); + } + public function testHEntryHasHCardAndUrlAuthor() { $url = 'http://author.example.com/h-entry-has-h-card-and-url-author'; $response = $this->parse(['url' => $url]); @@ -138,6 +152,20 @@ class AuthorTest extends PHPUnit_Framework_TestCase { $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo); } + public function testPageIsHCardWithNoURL() { + $url = 'http://author.example.com/about-no-url'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body); + + $this->assertEquals('card', $data->data->type); + $this->assertEquals('Author Full Name', $data->data->name); + $this->assertEquals($url, $data->data->url); + $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo); + } + public function testHEntryAuthorIs0() { $url = 'http://author.example.com/author-name-is-0'; $response = $this->parse(['url' => $url]); diff --git a/tests/data/author.example.com/about-no-url b/tests/data/author.example.com/about-no-url new file mode 100644 index 0000000..99b9bde --- /dev/null +++ b/tests/data/author.example.com/about-no-url @@ -0,0 +1,22 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 09 Dec 2015 03:29:14 GMT +Content-Type: text/html; charset=utf-8 + + + + + + Author + + + +
+

Author Full Name

+ xmpp + +
+ + + + \ No newline at end of file diff --git a/tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-no-url b/tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-no-url new file mode 100644 index 0000000..4230604 --- /dev/null +++ b/tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-no-url @@ -0,0 +1,21 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 09 Dec 2015 03:29:14 GMT +Content-Type: text/html; charset=utf-8 + + + + + + Example + + + +
+ Author +

Hello World

+ permalink +
+ + + \ No newline at end of file