Skip to content

Commit 35c846c

Browse files
committed
Update hreview backcompat
Set backcompat parser for `item hproduct` correctly. Add tests for `item vevent` and `item hproduct`.
1 parent 46a90f9 commit 35c846c

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

Mf2/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ public function backcompat(DOMElement $el, $context = '', $isParentMf2 = false)
16411641
foreach ( $item_and_hproduct as $tempEl ) {
16421642
if ( !$this->hasRootMf2($tempEl) ) {
16431643
$this->addMfClasses($tempEl, 'p-item h-product');
1644-
$this->backcompat($tempEl, 'vevent');
1644+
$this->backcompat($tempEl, 'hproduct');
16451645
$this->addUpgraded($tempEl, array('item', 'hproduct'));
16461646
}
16471647
}

tests/Mf2/ClassicMicroformatsTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,54 @@ public function testHReviewRelTag() {
947947
$this->assertContains('Garçon', $output['items'][0]['properties']['category']);
948948
}
949949

950+
public function testHReviewItemVevent()
951+
{
952+
$input = '<div class="hreview">
953+
<span><span class="rating">5</span> out of 5 stars</span>
954+
<span class="item vevent">
955+
<span class="summary">IndieWebCamp 2014</span> -
956+
<a href="http://indiewebcamp.com/2014/" class="url">indiewebcamp.com/2014/</a>
957+
</span>
958+
</div>';
959+
$parser = new Parser($input);
960+
$output = $parser->parse();
961+
962+
$this->assertArrayHasKey('item', $output['items'][0]['properties']);
963+
964+
# assert item type is h-event
965+
$this->assertCount(1, $output['items'][0]['properties']['item'][0]['type']);
966+
$this->assertEquals('h-event', $output['items'][0]['properties']['item'][0]['type'][0]);
967+
968+
# assert expected h-event properties
969+
$properties = $output['items'][0]['properties']['item'][0]['properties'];
970+
$this->assertArrayHasKey('name', $properties);
971+
$this->assertArrayHasKey('url', $properties);
972+
}
973+
974+
public function testHReviewItemHproduct()
975+
{
976+
$input = '<div class="hreview">
977+
<span><span class="rating">4</span> out of 5 stars</span>
978+
<span class="item hproduct">
979+
<span class="fn">Widget</span> -
980+
<a href="http://example.com/widget/" class="url">example.com/widget/</a>
981+
</span>
982+
</div>';
983+
$parser = new Parser($input);
984+
$output = $parser->parse();
985+
986+
$this->assertArrayHasKey('item', $output['items'][0]['properties']);
987+
988+
# assert item type is h-product
989+
$this->assertCount(1, $output['items'][0]['properties']['item'][0]['type']);
990+
$this->assertEquals('h-product', $output['items'][0]['properties']['item'][0]['type'][0]);
991+
992+
# assert expected h-product properties
993+
$properties = $output['items'][0]['properties']['item'][0]['properties'];
994+
$this->assertArrayHasKey('name', $properties);
995+
$this->assertArrayHasKey('url', $properties);
996+
}
997+
950998
/**
951999
* Should return the last non-empty URL segment
9521000
* @see https://github.com/indieweb/php-mf2/issues/157

0 commit comments

Comments
 (0)