Skip to content

Commit 5b188ec

Browse files
committed
Add failing test and fix for #156
1 parent ae49928 commit 5b188ec

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Mf2/Parser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,8 @@ public function backcompat(DOMElement $el, $context = '', $isParentMf2 = false)
15061506
$mf1Classes = array_intersect($classes, array_keys($this->classicRootMap));
15071507
}
15081508

1509+
$el_has_mf2 = $this->hasRootMf2($el);
1510+
15091511
foreach ($mf1Classes as $classname) {
15101512
// special handling for specific properties
15111513
switch ( $classname )
@@ -1600,7 +1602,7 @@ public function backcompat(DOMElement $el, $context = '', $isParentMf2 = false)
16001602
}
16011603
}
16021604

1603-
if ( empty($context) && isset($this->classicRootMap[$classname]) && !$this->hasRootMf2($el) ) {
1605+
if ( empty($context) && isset($this->classicRootMap[$classname]) && !$el_has_mf2 ) {
16041606
$this->addMfClasses($el, $this->classicRootMap[$classname]);
16051607
}
16061608
}

tests/Mf2/ClassicMicroformatsTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,5 +971,26 @@ public function testRelTagTrailingSlash() {
971971
$this->assertContains('phpmf2', $output['items'][1]['properties']['category']);
972972
$this->assertContains('mf2py', $output['items'][1]['properties']['category']);
973973
}
974+
975+
/**
976+
* Upgrade multiple mf1 roots on the same element
977+
* @see https://github.com/indieweb/php-mf2/issues/156
978+
*/
979+
public function testBackcompatMultipleRoots() {
980+
$input = '<article class="vevent hentry">
981+
<span class="entry-title">h-entry name</span>
982+
<span class="summary">h-event name</span>
983+
</article>';
984+
$result = Mf2\parse($input);
985+
986+
$this->assertCount(2, $result['items'][0]['type']);
987+
$this->assertContains('h-event', $result['items'][0]['type']);
988+
$this->assertContains('h-entry', $result['items'][0]['type']);
989+
$this->assertArrayHasKey('name', $result['items'][0]['properties']);
990+
$this->assertCount(2, $result['items'][0]['properties']['name']);
991+
$this->assertContains('h-event name', $result['items'][0]['properties']['name']);
992+
$this->assertContains('h-entry name', $result['items'][0]['properties']['name']);
993+
}
994+
974995
}
975996

0 commit comments

Comments
 (0)