Commit b27dc8d5 authored by Gregor Morrill's avatar Gregor Morrill

Added failing test and fix for #57

parent d653341e
......@@ -770,6 +770,19 @@ class Parser {
$children = array();
$dates = array();
foreach ( $this->xpath->query('.//a[@rel and @href]', $e) as $el )
{
// rel-bookmark found
if ($el->getAttribute('rel') == 'bookmark') {
$class = 'u-url';
// rel-bookmark already has class-attribute; append current value
if ($el->hasAttribute('class')) {
$class .= ' ' . $el->getAttribute('class');
}
$el->setAttribute('class', $class);
}
}
// Handle nested microformats (h-*)
foreach ($this->xpath->query('.//*[contains(concat(" ", @class)," h-")]', $e) as $subMF) {
// Parse
......
......@@ -171,4 +171,71 @@ EOT;
$this->assertEquals('1998-03-12T09:30', $output['items'][0]['properties']['end'][0]);
}
/**
* @see https://github.com/indieweb/php-mf2/issues/57
* @see https://github.com/kartikprabhu/mf2py/pull/50/
*/
public function testRelBookmarkUrl() {
$input = <<< END
<!DOCTYPE html>
<html>
<head>
<title>Backcompat test for hEntry with nested rel=bookmark</title>
<!-- This should not affect parsing elsewhere -->
<link rel="bookmark" href="/about">
</head>
<body>
<!-- This should not affect parsing elsewhere -->
<a rel="bookmark" href="/"></a>
<article class="hentry">
<span class="author">Lee Adama</span>
<span class="entry-title">Jumping Rope for Weight Loss</span>
<div class="entry-content">Some Content</div>
<a rel="bookmark" href="/2014/11/24/jump-rope">Nov 24, 2014</a>
</article>
<article class="hentry">
<span class="author">Kara Thrace</span>
<span class="entry-title">Abstract Art in Graffiti</span>
<div class="entry-content">More Content</div>
<a rel="bookmark" href="/2014/11/23/graffiti">Nov 23, 2014</a>
</article>
<article class="hentry">
<span class="author">President Roslyn</span>
<span class="entry-title">Dreams of Earth</span>
<div class="entry-content">Additional Content</div>
<a rel="bookmark" href="/2014/11/21/earth">Nov 21, 2014</a>
</article>
<article class="hentry">
<span class="author">Chief Tyrrol</span>
<span class="entry-title">Organized Labor in Mining Colonies</span>
<div class="entry-content">More Content</div>
<a rel="bookmark" href="/2014/11/19/labor">Nov 19, 2014</a>
</article>
</body>
</html>
END;
$output = Mf2\parse($input);
$u_urls = array(
'/2014/11/24/jump-rope',
'/2014/11/23/graffiti',
'/2014/11/21/earth',
'/2014/11/19/labor',
);
foreach ( $u_urls as $key => $url )
{
$this->assertEquals('h-entry', $output['items'][$key]['type'][0]);
$this->assertArrayHasKey('url', $output['items'][$key]['properties']);
$this->assertEquals($url, $output['items'][$key]['properties']['url'][0]);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment