From 8026279cba5b75e94282f8950fb590bfb0e5959c Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Thu, 8 Mar 2018 06:31:17 -0800 Subject: [PATCH] fix tests for new mf2 parser main difference is the deprecated rel handling --- lib/XRay/Feeds.php | 42 +++++++++++----------- tests/ParseTest.php | 8 ++--- tests/data/source.example.com/h-entry-rsvp | 2 +- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/XRay/Feeds.php b/lib/XRay/Feeds.php index d7fad22..5d5aa54 100644 --- a/lib/XRay/Feeds.php +++ b/lib/XRay/Feeds.php @@ -76,26 +76,28 @@ class Feeds { // Some other document was returned, parse the HTML and look for rel alternates and Microformats $mf2 = \mf2\Parse($body, $result['url']); - if(isset($mf2['alternates'])) { - foreach($mf2['alternates'] as $alt) { - if(isset($alt['type'])) { - if(strpos($alt['type'], 'application/json') !== false) { - $feeds[] = [ - 'url' => $alt['url'], - 'type' => 'jsonfeed' - ]; - } - if(strpos($alt['type'], 'application/atom+xml') !== false) { - $feeds[] = [ - 'url' => $alt['url'], - 'type' => 'atom' - ]; - } - if(strpos($alt['type'], 'application/rss+xml') !== false) { - $feeds[] = [ - 'url' => $alt['url'], - 'type' => 'rss' - ]; + if(isset($mf2['rel-urls'])) { + foreach($mf2['rel-urls'] as $rel=>$info) { + if(isset($info['rels']) && in_array('alternate', $info['rels'])) { + if(isset($info['type'])) { + if(strpos($info['type'], 'application/json') !== false) { + $feeds[] = [ + 'url' => $rel, + 'type' => 'jsonfeed' + ]; + } + if(strpos($info['type'], 'application/atom+xml') !== false) { + $feeds[] = [ + 'url' => $rel, + 'type' => 'atom' + ]; + } + if(strpos($info['type'], 'application/rss+xml') !== false) { + $feeds[] = [ + 'url' => $rel, + 'type' => 'rss' + ]; + } } } } diff --git a/tests/ParseTest.php b/tests/ParseTest.php index 2b0666f..24bda5c 100644 --- a/tests/ParseTest.php +++ b/tests/ParseTest.php @@ -215,7 +215,7 @@ class ParseTest extends PHPUnit_Framework_TestCase { $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); - $this->assertEquals('entry', $data['data']['type']); + $this->assertEquals('entry', $data['data']['type']); $this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]); $this->assertArrayHasKey('http://example.com/100', $data['data']['refs']); $this->assertEquals('Example Post', $data['data']['refs']['http://example.com/100']['name']); @@ -289,7 +289,7 @@ class ParseTest extends PHPUnit_Framework_TestCase { $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $this->assertEquals('entry', $data['data']['type']); - $this->assertEquals('I\'ll be there!', $data['data']['name']); + $this->assertEquals('I\'ll be there!', $data['data']['content']['text']); $this->assertEquals('yes', $data['data']['rsvp']); } @@ -537,7 +537,7 @@ class ParseTest extends PHPUnit_Framework_TestCase { $this->assertEquals('45.518716', $venue['latitude']); $this->assertEquals('Homebrew Website Club!', $data['data']['content']['text']); $this->assertEquals('https://aaronparecki.com/2017/06/07/12/photo.jpg', $data['data']['photo'][0]); - $this->assertEquals('2017-06-07T17:14:40-07:00', $data['data']['published']); + $this->assertEquals('2017-06-07T17:14:40-0700', $data['data']['published']); $this->assertArrayNotHasKey('name', $data['data']); } @@ -554,7 +554,7 @@ class ParseTest extends PHPUnit_Framework_TestCase { $this->assertEquals('https://foursquare.com/v/57104d2e498ece022e169dca', $venue['url']); $this->assertEquals('Homebrew Website Club!', $data['data']['content']['text']); $this->assertEquals('https://aaronparecki.com/2017/06/07/12/photo.jpg', $data['data']['photo'][0]); - $this->assertEquals('2017-06-07T17:14:40-07:00', $data['data']['published']); + $this->assertEquals('2017-06-07T17:14:40-0700', $data['data']['published']); $this->assertArrayNotHasKey('name', $data['data']); } diff --git a/tests/data/source.example.com/h-entry-rsvp b/tests/data/source.example.com/h-entry-rsvp index edbe224..425d1d7 100644 --- a/tests/data/source.example.com/h-entry-rsvp +++ b/tests/data/source.example.com/h-entry-rsvp @@ -10,7 +10,7 @@ Connection: keep-alive
- I'll be there! + I'll be there!