Commit 67404283 authored by Gregor Morrill's avatar Gregor Morrill

Update backcompat handling for adr

parent 392ec670
......@@ -1317,19 +1317,6 @@ class Parser {
// special handling for specific properties
switch ( $classname )
{
case 'vcard':
$adr = $this->xpath->query('.//*[contains(concat(" ", normalize-space(@class), " "), " adr ")]', $el);
if ( $adr->length ) {
foreach ( $adr as $tempEl ) {
if ( !$this->hasRootMf2($tempEl) ) {
$this->backcompat($tempEl, 'adr');
$this->addMfClasses($tempEl, 'p-adr h-adr');
}
}
}
break;
case 'hreview':
$item_and_vcard = $this->xpath->query('.//*[contains(concat(" ", normalize-space(@class), " "), " item ") and contains(concat(" ", normalize-space(@class), " "), " vcard ")]', $el);
......@@ -1405,7 +1392,7 @@ class Parser {
}
}
if ( empty($context) && isset($this->classicRootMap[$classname]) ) {
if ( empty($context) && isset($this->classicRootMap[$classname]) && !$this->hasRootMf2($el) ) {
$this->addMfClasses($el, $this->classicRootMap[$classname]);
}
}
......@@ -1522,7 +1509,8 @@ class Parser {
'hresume' => 'h-resume',
'vevent' => 'h-event',
'hreview' => 'h-review',
'hproduct' => 'h-product'
'hproduct' => 'h-product',
'adr' => 'h-adr',
);
/**
......@@ -1571,8 +1559,7 @@ class Parser {
'replace' => 'p-category'
),
'adr' => array(
'replace' => 'p-adr h-adr',
'context' => 'adr',
'replace' => 'p-adr',
),
'extended-address' => array(
'replace' => 'p-extended-address'
......
......@@ -239,22 +239,59 @@ END;
}
/**
* @see http://microformats.org/wiki/microformats2-parsing-issues#any_h-_root_class_name_overrides_and_stops_backcompat_root
*/
public function testMf2RootStopsBackcompatRoot() {
$input = '<div class="adr h-adr">
<div class="locality">MF1 adr locality</div>
<div class="p-locality">MF2 adr locality</div>
</div>';
$parser = new Parser($input);
$result = $parser->parse();
$this->assertCount(1, $result['items'][0]['type']);
$this->assertEquals('h-adr', $result['items'][0]['type'][0]);
$this->assertCount(1, $result['items'][0]['properties']['locality']);
$this->assertEquals('MF2 adr locality', $result['items'][0]['properties']['locality'][0]);
}
/**
* @see http://microformats.org/wiki/microformats2-parsing-issues#any_h-_root_class_name_overrides_and_stops_backcompat_root
*/
public function testMf2CustomRootStopsBackcompatRoot() {
$input = '<div class="adr h-acme-address">
<div class="locality">MF1 acme locality</div>
<div class="p-locality">MF2 acme locality</div>
</div>';
$parser = new Parser($input);
$result = $parser->parse();
$this->assertCount(1, $result['items'][0]['type']);
$this->assertEquals('h-acme-address', $result['items'][0]['type'][0]);
$this->assertCount(1, $result['items'][0]['properties']['locality']);
$this->assertEquals('MF2 acme locality', $result['items'][0]['properties']['locality'][0]);
}
/**
* @see http://microformats.org/wiki/microformats2-parsing-issues#uf2_children_on_backcompat_properties
*/
public function testMf2ChildrenOnBackcompatProperties()
{
public function testMf2ChildrenOnBackcompatProperties() {
$input = '<div class="vcard">
<div class="adr h-custom">
<div class="locality">MF1</div>
<div class="p-locality">MF2</div>
<div class="adr h-acme-some-acme-object">
<div class="locality">MF1 some acme locality</div>
<div class="p-locality">MF2 some acme locality</div>
</div>
</div>';
$parser = new Parser($input);
$result = $parser->parse();
$this->assertCount(1, $result['items'][0]['properties']['adr'][0]['type']);
$this->assertEquals('h-acme-some-acme-object', $result['items'][0]['properties']['adr'][0]['type'][0]);
$this->assertCount(1, $result['items'][0]['properties']['adr'][0]['properties']['locality']);
$this->assertEquals('MF2', $result['items'][0]['properties']['adr'][0]['properties']['locality'][0]);
$this->assertEquals('MF2 some acme locality', $result['items'][0]['properties']['adr'][0]['properties']['locality'][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