Skip to content

Commit 6740428

Browse files
committed
Update backcompat handling for adr
1 parent 392ec67 commit 6740428

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

Mf2/Parser.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,19 +1317,6 @@ public function backcompat(DOMElement $el, $context = '', $isParentMf2 = false)
13171317
// special handling for specific properties
13181318
switch ( $classname )
13191319
{
1320-
case 'vcard':
1321-
$adr = $this->xpath->query('.//*[contains(concat(" ", normalize-space(@class), " "), " adr ")]', $el);
1322-
1323-
if ( $adr->length ) {
1324-
foreach ( $adr as $tempEl ) {
1325-
if ( !$this->hasRootMf2($tempEl) ) {
1326-
$this->backcompat($tempEl, 'adr');
1327-
$this->addMfClasses($tempEl, 'p-adr h-adr');
1328-
}
1329-
}
1330-
}
1331-
break;
1332-
13331320
case 'hreview':
13341321
$item_and_vcard = $this->xpath->query('.//*[contains(concat(" ", normalize-space(@class), " "), " item ") and contains(concat(" ", normalize-space(@class), " "), " vcard ")]', $el);
13351322

@@ -1405,7 +1392,7 @@ public function backcompat(DOMElement $el, $context = '', $isParentMf2 = false)
14051392
}
14061393
}
14071394

1408-
if ( empty($context) && isset($this->classicRootMap[$classname]) ) {
1395+
if ( empty($context) && isset($this->classicRootMap[$classname]) && !$this->hasRootMf2($el) ) {
14091396
$this->addMfClasses($el, $this->classicRootMap[$classname]);
14101397
}
14111398
}
@@ -1522,7 +1509,8 @@ public function query($expression, $context = null) {
15221509
'hresume' => 'h-resume',
15231510
'vevent' => 'h-event',
15241511
'hreview' => 'h-review',
1525-
'hproduct' => 'h-product'
1512+
'hproduct' => 'h-product',
1513+
'adr' => 'h-adr',
15261514
);
15271515

15281516
/**
@@ -1571,8 +1559,7 @@ public function query($expression, $context = null) {
15711559
'replace' => 'p-category'
15721560
),
15731561
'adr' => array(
1574-
'replace' => 'p-adr h-adr',
1575-
'context' => 'adr',
1562+
'replace' => 'p-adr',
15761563
),
15771564
'extended-address' => array(
15781565
'replace' => 'p-extended-address'

tests/Mf2/ClassicMicroformatsTest.php

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,59 @@ public function testRelBookmarkUrl() {
239239
}
240240

241241

242+
/**
243+
* @see http://microformats.org/wiki/microformats2-parsing-issues#any_h-_root_class_name_overrides_and_stops_backcompat_root
244+
*/
245+
public function testMf2RootStopsBackcompatRoot() {
246+
$input = '<div class="adr h-adr">
247+
<div class="locality">MF1 adr locality</div>
248+
<div class="p-locality">MF2 adr locality</div>
249+
</div>';
250+
$parser = new Parser($input);
251+
$result = $parser->parse();
252+
253+
$this->assertCount(1, $result['items'][0]['type']);
254+
$this->assertEquals('h-adr', $result['items'][0]['type'][0]);
255+
$this->assertCount(1, $result['items'][0]['properties']['locality']);
256+
$this->assertEquals('MF2 adr locality', $result['items'][0]['properties']['locality'][0]);
257+
}
258+
259+
260+
/**
261+
* @see http://microformats.org/wiki/microformats2-parsing-issues#any_h-_root_class_name_overrides_and_stops_backcompat_root
262+
*/
263+
public function testMf2CustomRootStopsBackcompatRoot() {
264+
$input = '<div class="adr h-acme-address">
265+
<div class="locality">MF1 acme locality</div>
266+
<div class="p-locality">MF2 acme locality</div>
267+
</div>';
268+
$parser = new Parser($input);
269+
$result = $parser->parse();
270+
271+
$this->assertCount(1, $result['items'][0]['type']);
272+
$this->assertEquals('h-acme-address', $result['items'][0]['type'][0]);
273+
$this->assertCount(1, $result['items'][0]['properties']['locality']);
274+
$this->assertEquals('MF2 acme locality', $result['items'][0]['properties']['locality'][0]);
275+
}
276+
277+
242278
/**
243279
* @see http://microformats.org/wiki/microformats2-parsing-issues#uf2_children_on_backcompat_properties
244280
*/
245-
public function testMf2ChildrenOnBackcompatProperties()
246-
{
281+
public function testMf2ChildrenOnBackcompatProperties() {
247282
$input = '<div class="vcard">
248-
<div class="adr h-custom">
249-
<div class="locality">MF1</div>
250-
<div class="p-locality">MF2</div>
283+
<div class="adr h-acme-some-acme-object">
284+
<div class="locality">MF1 some acme locality</div>
285+
<div class="p-locality">MF2 some acme locality</div>
251286
</div>
252287
</div>';
253288
$parser = new Parser($input);
254289
$result = $parser->parse();
255290

291+
$this->assertCount(1, $result['items'][0]['properties']['adr'][0]['type']);
292+
$this->assertEquals('h-acme-some-acme-object', $result['items'][0]['properties']['adr'][0]['type'][0]);
256293
$this->assertCount(1, $result['items'][0]['properties']['adr'][0]['properties']['locality']);
257-
$this->assertEquals('MF2', $result['items'][0]['properties']['adr'][0]['properties']['locality'][0]);
294+
$this->assertEquals('MF2 some acme locality', $result['items'][0]['properties']['adr'][0]['properties']['locality'][0]);
258295
}
259296

260297

0 commit comments

Comments
 (0)