Skip to content

Commit 8a7db43

Browse files
gRegorLoveaaronpk
authored andcommitted
Add tests and fix for #151 (#152)
* Add tests and fix for #151 * Re-commit combined tests without the whitespace changes
1 parent 42ef6eb commit 8a7db43

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

Mf2/Parser.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,13 +1398,16 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) {
13981398
// Note: handling microformat nesting under multiple conflicting prefixes is not currently specified by the mf2 parsing spec.
13991399
$prefixSpecificResult = $result;
14001400
if (in_array('p-', $prefixes)) {
1401-
$prefixSpecificResult['value'] = (empty($prefixSpecificResult['properties']['name'][0])) ? '' : $prefixSpecificResult['properties']['name'][0];
1401+
$prefixSpecificResult['value'] = (empty($prefixSpecificResult['properties']['name'][0])) ? $this->parseP($node) : $prefixSpecificResult['properties']['name'][0];
14021402
} elseif (in_array('e-', $prefixes)) {
14031403
$eParsedResult = $this->parseE($node);
14041404
$prefixSpecificResult['html'] = $eParsedResult['html'];
14051405
$prefixSpecificResult['value'] = $eParsedResult['value'];
14061406
} elseif (in_array('u-', $prefixes)) {
14071407
$prefixSpecificResult['value'] = (empty($result['properties']['url'])) ? $this->parseU($node) : reset($result['properties']['url']);
1408+
} elseif (in_array('dt-', $prefixes)) {
1409+
$parsed_property = $this->parseDT($node);
1410+
$prefixSpecificResult['value'] = ($parsed_property) ? $parsed_property : '';
14081411
}
14091412

14101413
$mfs['properties'][$property][] = $prefixSpecificResult;

tests/Mf2/CombinedMicroformatsTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,5 +359,43 @@ public function testNoUrlFromRelOnMf2() {
359359
$this->assertArrayNotHasKey('url', $output['items'][0]['properties']);
360360
}
361361

362+
/**
363+
* Simplified h-entry with `p-location h-adr` from https://aaronparecki.com/2018/03/14/3/
364+
* Whitespace cleaned up for easier test assertion
365+
* @see https://github.com/indieweb/php-mf2/issues/151
366+
*/
367+
public function testNestedValuePProperty() {
368+
$input = <<< END
369+
<div class="h-entry">
370+
<span class="p-location h-adr">
371+
<span class="p-locality">Portland</span>, <span class="p-region">Oregon</span> <span class="weather"><span>&bull;</span><i class="wi wi-night-alt-cloudy" title="Mostly Cloudy"></i> 44&deg;F</span>
372+
<data class="p-latitude" value="45.535623"></data>
373+
<data class="p-longitude" value="-122.621209"></data>
374+
</span>
375+
</div>
376+
END;
377+
$parser = new Parser($input);
378+
$output = $parser->parse();
379+
380+
$this->assertArrayHasKey('value', $output['items'][0]['properties']['location'][0]);
381+
$this->assertEquals("Portland, Oregon • 44°F", $output['items'][0]['properties']['location'][0]['value']);
382+
}
383+
384+
/**
385+
* @see https://github.com/indieweb/php-mf2/issues/151
386+
*/
387+
public function testNestedValueDTProperty() {
388+
$input = <<< END
389+
<div class="h-entry">
390+
<div class="dt-acme h-acme-object">1997-12-12</div>
391+
</div>
392+
END;
393+
$parser = new Parser($input);
394+
$output = $parser->parse();
395+
396+
$this->assertArrayHasKey('value', $output['items'][0]['properties']['acme'][0]);
397+
$this->assertEquals('1997-12-12', $output['items'][0]['properties']['acme'][0]['value']);
398+
}
399+
362400
}
363401

0 commit comments

Comments
 (0)