Browse Source

recognize h-card if it's the only object

closes #36
pull/39/head
Aaron Parecki 7 years ago
parent
commit
a1234f61e3
No known key found for this signature in database GPG Key ID: 276C2817346D6056
4 changed files with 79 additions and 0 deletions
  1. +8
    -0
      lib/Formats/Mf2.php
  2. +28
    -0
      tests/AuthorTest.php
  3. +22
    -0
      tests/data/author.example.com/about-no-url
  4. +21
    -0
      tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-no-url

+ 8
- 0
lib/Formats/Mf2.php View File

@ -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"); Parse::debug("mf2:0: Recognized $url as an h-feed because it is the only item on the page");
return self::parseAsHFeed($mf2, $http); 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, // 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 = [ $response = [
'data' => $data 'data' => $data
]; ];

+ 28
- 0
tests/AuthorTest.php View File

@ -98,6 +98,20 @@ class AuthorTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo); $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() { public function testHEntryHasHCardAndUrlAuthor() {
$url = 'http://author.example.com/h-entry-has-h-card-and-url-author'; $url = 'http://author.example.com/h-entry-has-h-card-and-url-author';
$response = $this->parse(['url' => $url]); $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); $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() { public function testHEntryAuthorIs0() {
$url = 'http://author.example.com/author-name-is-0'; $url = 'http://author.example.com/author-name-is-0';
$response = $this->parse(['url' => $url]); $response = $this->parse(['url' => $url]);

+ 22
- 0
tests/data/author.example.com/about-no-url View File

@ -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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Author</title>
</head>
<body>
<div class="h-card">
<h2 class="p-name">Author Full Name</h2>
<a href="xmpp://user@host.example" class="u-url" rel="me">xmpp</a>
<img src="/photo.jpg" class="u-photo">
</div>
<!-- this page has no u-url or rel=me pointing to itself but there is only one h-card -->
</body>
</html>

+ 21
- 0
tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-no-url View File

@ -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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example</title>
</head>
<body>
<div class="h-entry">
<a href="/about-no-url" class="u-author">Author</a>
<p class="p-name e-content">Hello World</p>
<a href="/h-entry-author-is-url-to-h-card-with-no-url" class="u-url">permalink</a>
</div>
</body>
</html>

Loading…
Cancel
Save