Skip to content

Commit

Permalink
Add tests and fix for #151 (#152)
Browse files Browse the repository at this point in the history
* Add tests and fix for #151

* Re-commit combined tests without the whitespace changes
  • Loading branch information
gRegorLove authored and aaronpk committed Mar 15, 2018
1 parent 42ef6eb commit 8a7db43
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1398,13 +1398,16 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) {
// Note: handling microformat nesting under multiple conflicting prefixes is not currently specified by the mf2 parsing spec.
$prefixSpecificResult = $result;
if (in_array('p-', $prefixes)) {
$prefixSpecificResult['value'] = (empty($prefixSpecificResult['properties']['name'][0])) ? '' : $prefixSpecificResult['properties']['name'][0];
$prefixSpecificResult['value'] = (empty($prefixSpecificResult['properties']['name'][0])) ? $this->parseP($node) : $prefixSpecificResult['properties']['name'][0];
} elseif (in_array('e-', $prefixes)) {
$eParsedResult = $this->parseE($node);
$prefixSpecificResult['html'] = $eParsedResult['html'];
$prefixSpecificResult['value'] = $eParsedResult['value'];
} elseif (in_array('u-', $prefixes)) {
$prefixSpecificResult['value'] = (empty($result['properties']['url'])) ? $this->parseU($node) : reset($result['properties']['url']);
} elseif (in_array('dt-', $prefixes)) {
$parsed_property = $this->parseDT($node);
$prefixSpecificResult['value'] = ($parsed_property) ? $parsed_property : '';
}

$mfs['properties'][$property][] = $prefixSpecificResult;
Expand Down
38 changes: 38 additions & 0 deletions tests/Mf2/CombinedMicroformatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,5 +359,43 @@ public function testNoUrlFromRelOnMf2() {
$this->assertArrayNotHasKey('url', $output['items'][0]['properties']);
}

/**
* Simplified h-entry with `p-location h-adr` from https://aaronparecki.com/2018/03/14/3/
* Whitespace cleaned up for easier test assertion
* @see https://github.com/indieweb/php-mf2/issues/151
*/
public function testNestedValuePProperty() {
$input = <<< END
<div class="h-entry">
<span class="p-location h-adr">
<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>
<data class="p-latitude" value="45.535623"></data>
<data class="p-longitude" value="-122.621209"></data>
</span>
</div>
END;
$parser = new Parser($input);
$output = $parser->parse();

$this->assertArrayHasKey('value', $output['items'][0]['properties']['location'][0]);
$this->assertEquals("Portland, Oregon • 44°F", $output['items'][0]['properties']['location'][0]['value']);
}

/**
* @see https://github.com/indieweb/php-mf2/issues/151
*/
public function testNestedValueDTProperty() {
$input = <<< END
<div class="h-entry">
<div class="dt-acme h-acme-object">1997-12-12</div>
</div>
END;
$parser = new Parser($input);
$output = $parser->parse();

$this->assertArrayHasKey('value', $output['items'][0]['properties']['acme'][0]);
$this->assertEquals('1997-12-12', $output['items'][0]['properties']['acme'][0]['value']);
}

}

0 comments on commit 8a7db43

Please sign in to comment.