Browse Source

fix tests for new mf2 parser

main difference is the deprecated rel handling
pull/64/head
Aaron Parecki 3 years ago
parent
commit
8026279cba
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 27 additions and 25 deletions
  1. +22
    -20
      lib/XRay/Feeds.php
  2. +4
    -4
      tests/ParseTest.php
  3. +1
    -1
      tests/data/source.example.com/h-entry-rsvp

+ 22
- 20
lib/XRay/Feeds.php View File

@ -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'
];
}
}
}
}

+ 4
- 4
tests/ParseTest.php View File

@ -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']);
}

+ 1
- 1
tests/data/source.example.com/h-entry-rsvp View File

@ -10,7 +10,7 @@ Connection: keep-alive
</head>
<body>
<div class="h-entry">
<data class="p-rsvp" value="yes">I'll be there!</data>
<data class="p-rsvp" value="yes"><span class="p-content">I'll be there!</span></data>
</div>
</body>
</html>

Loading…
Cancel
Save