Browse Source

Find author when author is a property of the h-feed

closes #32
pull/49/head
Aaron Parecki 3 years ago
parent
commit
15743d411d
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 72 additions and 0 deletions
  1. +15
    -0
      lib/XRay/Formats/Mf2.php
  2. +20
    -0
      tests/FeedTest.php
  3. +37
    -0
      tests/data/feed.example.com/h-feed-with-child-author

+ 15
- 0
lib/XRay/Formats/Mf2.php View File

@ -675,6 +675,21 @@ class Mf2 extends Format {
}
}
// Also check the "author" property
// (for finding the author of an h-feed's children when the author is the p-author property of the h-feed)
if(isset($i['properties']['author'])) {
foreach($i['properties']['author'] as $ic) {
if(self::isHCard($ic)) {
if(array_key_exists('url', $ic['properties'])
and in_array($authorPage, $ic['properties']['url'])
) {
return self::parseAsHCard($ic, $http)['data'];
}
}
}
}
}
}

+ 20
- 0
tests/FeedTest.php View File

@ -87,6 +87,26 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('Four', $data->items[3]->name);
}
public function testTopLevelHFeedWithChildAuthor() {
$url = 'http://feed.example.com/h-feed-with-child-author';
$response = $this->parse(['url' => $url, 'expect' => 'feed']);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$this->assertEquals('feed', $data->type);
$this->assertEquals(4, count($data->items));
$this->assertEquals('One', $data->items[0]->name);
$this->assertEquals('Two', $data->items[1]->name);
$this->assertEquals('Three', $data->items[2]->name);
$this->assertEquals('Four', $data->items[3]->name);
$this->assertEquals('Author Name', $data->items[0]->author->name);
$this->assertEquals('Author Name', $data->items[1]->author->name);
$this->assertEquals('Author Name', $data->items[2]->author->name);
$this->assertEquals('Author Name', $data->items[3]->author->name);
}
public function testHCardWithChildHEntrys() {
$url = 'http://feed.example.com/h-card-with-child-h-entrys';
$response = $this->parse(['url' => $url, 'expect' => 'feed']);

+ 37
- 0
tests/data/feed.example.com/h-feed-with-child-author View File

@ -0,0 +1,37 @@
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
<html>
<head>
<title>Test</title>
</head>
<body>
<div class="h-feed">
<ul>
<li class="h-entry">
<a href="/1" class="u-url p-name">One</a>
<a href="/author" class="u-author"></a>
</li>
<li class="h-entry">
<a href="/2" class="u-url p-name">Two</a>
<a href="/author" class="u-author"></a>
</li>
<li class="h-entry">
<a href="/3" class="u-url p-name">Three</a>
<a href="/author" class="u-author"></a>
</li>
<li class="h-entry">
<a href="/4" class="u-url p-name">Four</a>
<a href="/author" class="u-author"></a>
</li>
</ul>
<a href="/author" class="u-author h-card">Author Name</a>
</div>
</body>
</html>

Loading…
Cancel
Save