Browse Source

recognize h-event "content" in addition to "description"

pull/78/head
Aaron Parecki 6 years ago
parent
commit
470639f486
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 59 additions and 11 deletions
  1. +9
    -4
      lib/XRay/Formats/Mf2.php
  2. +26
    -7
      tests/ParseTest.php
  3. +24
    -0
      tests/data/source.example.com/h-event-text-content

+ 9
- 4
lib/XRay/Formats/Mf2.php View File

@ -617,10 +617,15 @@ class Mf2 extends Format {
// If the value is an h-* object with a URL, the URL is used and a "ref" is added as well // If the value is an h-* object with a URL, the URL is used and a "ref" is added as well
self::collectArrayURLValues(['photo','video','audio','syndication'], $item, $data, $refs, $http); self::collectArrayURLValues(['photo','video','audio','syndication'], $item, $data, $refs, $http);
// If there is a description, always return the plaintext description, and return HTML description if it's different
$description = self::parseHTMLValue('description', $item);
if($description) {
$data['description'] = $description;
// If there is a description, always return the plaintext content, and return HTML content if it's different
$content = self::parseHTMLValue('content', $item);
if($content) {
$data['content'] = $content;
} else {
// Fall back to looking for "description"
$content = self::parseHTMLValue('description', $item);
if($content)
$data['content'] = $content;
} }
$data['post-type'] = \p3k\XRay\PostType::discover($data); $data['post-type'] = \p3k\XRay\PostType::discover($data);

+ 26
- 7
tests/ParseTest.php View File

@ -498,10 +498,10 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($url, $data['data']['url']); $this->assertEquals($url, $data['data']['url']);
$this->assertEquals('2016-03-09T18:30', $data['data']['start']); $this->assertEquals('2016-03-09T18:30', $data['data']['start']);
$this->assertEquals('2016-03-09T19:30', $data['data']['end']); $this->assertEquals('2016-03-09T19:30', $data['data']['end']);
$this->assertStringStartsWith("Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...", $data['data']['description']['text']);
$this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['description']['text']);
$this->assertStringStartsWith("<p>Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...</p>", $data['data']['description']['html']);
$this->assertStringEndsWith('<p>See the <a href="http://tantek.com/2013/332/b1/homebrew-website-club-newsletter">Homebrew Website Club Newsletter Volume 1 Issue 1</a> for a description of the first meeting.</p>', $data['data']['description']['html']);
$this->assertStringStartsWith("Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...", $data['data']['content']['text']);
$this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['content']['text']);
$this->assertStringStartsWith("<p>Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...</p>", $data['data']['content']['html']);
$this->assertStringEndsWith('<p>See the <a href="http://tantek.com/2013/332/b1/homebrew-website-club-newsletter">Homebrew Website Club Newsletter Volume 1 Issue 1</a> for a description of the first meeting.</p>', $data['data']['content']['html']);
} }
public function testEventWithTextDescription() { public function testEventWithTextDescription() {
@ -518,9 +518,28 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($url, $data['data']['url']); $this->assertEquals($url, $data['data']['url']);
$this->assertEquals('2016-03-09T18:30', $data['data']['start']); $this->assertEquals('2016-03-09T18:30', $data['data']['start']);
$this->assertEquals('2016-03-09T19:30', $data['data']['end']); $this->assertEquals('2016-03-09T19:30', $data['data']['end']);
$this->assertStringStartsWith("Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...", $data['data']['description']['text']);
$this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['description']['text']);
$this->assertArrayNotHasKey('html', $data['data']['description']);
$this->assertStringStartsWith("Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...", $data['data']['content']['text']);
$this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['content']['text']);
$this->assertArrayNotHasKey('html', $data['data']['content']);
}
public function testEventWithTextContent() {
$url = 'http://source.example.com/h-event-text-content';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('event', $data['data']['type']);
$this->assertEquals('event', $data['data']['post-type']);
$this->assertEquals('Homebrew Website Club', $data['data']['name']);
$this->assertEquals($url, $data['data']['url']);
$this->assertEquals('2016-03-09T18:30', $data['data']['start']);
$this->assertEquals('2016-03-09T19:30', $data['data']['end']);
$this->assertStringStartsWith("Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...", $data['data']['content']['text']);
$this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['content']['text']);
$this->assertArrayNotHasKey('html', $data['data']['content']);
} }
public function testEventWithHCardLocation() { public function testEventWithHCardLocation() {

+ 24
- 0
tests/data/source.example.com/h-event-text-content View File

@ -0,0 +1,24 @@
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>Homebrew Website Club</title>
</head>
<body class="h-event">
<h2 class="p-name">Homebrew Website Club</h2>
<a href="/h-event-text-content" class="u-url">permalink</a>
<time class="dt-start" datetime="2016-03-09T18:30">March 9, 6:30pm</time> - <time class="dt-end" datetime="2016-03-09T19:30">7:30pm</time>
<div class="p-content">
<p>Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...</p>
<p>See the <a href="http://tantek.com/2013/332/b1/homebrew-website-club-newsletter">Homebrew Website Club Newsletter Volume 1 Issue 1</a> for a description of the first meeting.</p>
</div>
</body>
</html>

Loading…
Cancel
Save