Skip to content

Commit b27dc8d

Browse files
committed
Added failing test and fix for microformats#57
1 parent d653341 commit b27dc8d

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

Mf2/Parser.php

+13
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,19 @@ public function parseH(\DOMElement $e) {
770770
$children = array();
771771
$dates = array();
772772

773+
foreach ( $this->xpath->query('.//a[@rel and @href]', $e) as $el )
774+
{
775+
// rel-bookmark found
776+
if ($el->getAttribute('rel') == 'bookmark') {
777+
$class = 'u-url';
778+
// rel-bookmark already has class-attribute; append current value
779+
if ($el->hasAttribute('class')) {
780+
$class .= ' ' . $el->getAttribute('class');
781+
}
782+
$el->setAttribute('class', $class);
783+
}
784+
}
785+
773786
// Handle nested microformats (h-*)
774787
foreach ($this->xpath->query('.//*[contains(concat(" ", @class)," h-")]', $e) as $subMF) {
775788
// Parse

tests/Mf2/ClassicMicroformatsTest.php

+67
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,71 @@ public function test_vevent() {
171171
$this->assertEquals('1998-03-12T09:30', $output['items'][0]['properties']['end'][0]);
172172
}
173173

174+
175+
/**
176+
* @see https://github.com/indieweb/php-mf2/issues/57
177+
* @see https://github.com/kartikprabhu/mf2py/pull/50/
178+
*/
179+
public function testRelBookmarkUrl() {
180+
$input = <<< END
181+
<!DOCTYPE html>
182+
<html>
183+
<head>
184+
<title>Backcompat test for hEntry with nested rel=bookmark</title>
185+
<!-- This should not affect parsing elsewhere -->
186+
<link rel="bookmark" href="/about">
187+
</head>
188+
<body>
189+
<!-- This should not affect parsing elsewhere -->
190+
<a rel="bookmark" href="/"></a>
191+
192+
<article class="hentry">
193+
<span class="author">Lee Adama</span>
194+
<span class="entry-title">Jumping Rope for Weight Loss</span>
195+
<div class="entry-content">Some Content</div>
196+
<a rel="bookmark" href="/2014/11/24/jump-rope">Nov 24, 2014</a>
197+
</article>
198+
199+
<article class="hentry">
200+
<span class="author">Kara Thrace</span>
201+
<span class="entry-title">Abstract Art in Graffiti</span>
202+
<div class="entry-content">More Content</div>
203+
<a rel="bookmark" href="/2014/11/23/graffiti">Nov 23, 2014</a>
204+
</article>
205+
206+
<article class="hentry">
207+
<span class="author">President Roslyn</span>
208+
<span class="entry-title">Dreams of Earth</span>
209+
<div class="entry-content">Additional Content</div>
210+
<a rel="bookmark" href="/2014/11/21/earth">Nov 21, 2014</a>
211+
</article>
212+
213+
<article class="hentry">
214+
<span class="author">Chief Tyrrol</span>
215+
<span class="entry-title">Organized Labor in Mining Colonies</span>
216+
<div class="entry-content">More Content</div>
217+
<a rel="bookmark" href="/2014/11/19/labor">Nov 19, 2014</a>
218+
</article>
219+
220+
</body>
221+
</html>
222+
END;
223+
$output = Mf2\parse($input);
224+
225+
$u_urls = array(
226+
'/2014/11/24/jump-rope',
227+
'/2014/11/23/graffiti',
228+
'/2014/11/21/earth',
229+
'/2014/11/19/labor',
230+
);
231+
232+
foreach ( $u_urls as $key => $url )
233+
{
234+
$this->assertEquals('h-entry', $output['items'][$key]['type'][0]);
235+
$this->assertArrayHasKey('url', $output['items'][$key]['properties']);
236+
$this->assertEquals($url, $output['items'][$key]['properties']['url'][0]);
237+
}
238+
239+
}
240+
174241
}

0 commit comments

Comments
 (0)