From 46a90f94993d5ee7e81e90fbd919b77c333a8dbc Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Mon, 26 Sep 2022 21:43:25 -0700 Subject: [PATCH 1/6] Upate hreview backcompat Parse rel="self bookmark" as u-url --- Mf2/Parser.php | 9 +++++++++ tests/Mf2/ClassicMicroformatsTest.php | 1 + 2 files changed, 10 insertions(+) diff --git a/Mf2/Parser.php b/Mf2/Parser.php index 7ac471e..348652b 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -1647,6 +1647,15 @@ public function backcompat(DOMElement $el, $context = '', $isParentMf2 = false) } } + $rel_self_bookmark = $this->xpath->query('.//*[contains(concat(" ", normalize-space(@rel), " "), " self ") and contains(concat(" ", normalize-space(@rel), " "), " bookmark ")]', $el); + + if ( $rel_self_bookmark->length ) { + foreach ( $rel_self_bookmark as $tempEl ) { + $this->addMfClasses($tempEl, 'u-url'); + $this->addUpgraded($tempEl, array('self', 'bookmark')); + } + } + $this->upgradeRelTagToCategory($el); break; diff --git a/tests/Mf2/ClassicMicroformatsTest.php b/tests/Mf2/ClassicMicroformatsTest.php index 5b192c3..b53689e 100644 --- a/tests/Mf2/ClassicMicroformatsTest.php +++ b/tests/Mf2/ClassicMicroformatsTest.php @@ -761,6 +761,7 @@ public function testParsesClassicHreview() {

Visit date: April 2005

Food eaten: Florentine crepe

+

Permanent link for review: http://example.com/crepe

END; $parser = new Parser($input); From 35c846c33c3fcde25c00c6c3faf404e76415d62f Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Mon, 26 Sep 2022 22:30:12 -0700 Subject: [PATCH 2/6] Update hreview backcompat Set backcompat parser for `item hproduct` correctly. Add tests for `item vevent` and `item hproduct`. --- Mf2/Parser.php | 2 +- tests/Mf2/ClassicMicroformatsTest.php | 48 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Mf2/Parser.php b/Mf2/Parser.php index 348652b..b3d22b7 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -1641,7 +1641,7 @@ public function backcompat(DOMElement $el, $context = '', $isParentMf2 = false) foreach ( $item_and_hproduct as $tempEl ) { if ( !$this->hasRootMf2($tempEl) ) { $this->addMfClasses($tempEl, 'p-item h-product'); - $this->backcompat($tempEl, 'vevent'); + $this->backcompat($tempEl, 'hproduct'); $this->addUpgraded($tempEl, array('item', 'hproduct')); } } diff --git a/tests/Mf2/ClassicMicroformatsTest.php b/tests/Mf2/ClassicMicroformatsTest.php index b53689e..550c05a 100644 --- a/tests/Mf2/ClassicMicroformatsTest.php +++ b/tests/Mf2/ClassicMicroformatsTest.php @@ -947,6 +947,54 @@ public function testHReviewRelTag() { $this->assertContains('Garçon', $output['items'][0]['properties']['category']); } + public function testHReviewItemVevent() + { + $input = '
+ 5 out of 5 stars + + IndieWebCamp 2014 - + indiewebcamp.com/2014/ + +
'; + $parser = new Parser($input); + $output = $parser->parse(); + + $this->assertArrayHasKey('item', $output['items'][0]['properties']); + + # assert item type is h-event + $this->assertCount(1, $output['items'][0]['properties']['item'][0]['type']); + $this->assertEquals('h-event', $output['items'][0]['properties']['item'][0]['type'][0]); + + # assert expected h-event properties + $properties = $output['items'][0]['properties']['item'][0]['properties']; + $this->assertArrayHasKey('name', $properties); + $this->assertArrayHasKey('url', $properties); + } + + public function testHReviewItemHproduct() + { + $input = '
+ 4 out of 5 stars + + Widget - + example.com/widget/ + +
'; + $parser = new Parser($input); + $output = $parser->parse(); + + $this->assertArrayHasKey('item', $output['items'][0]['properties']); + + # assert item type is h-product + $this->assertCount(1, $output['items'][0]['properties']['item'][0]['type']); + $this->assertEquals('h-product', $output['items'][0]['properties']['item'][0]['type'][0]); + + # assert expected h-product properties + $properties = $output['items'][0]['properties']['item'][0]['properties']; + $this->assertArrayHasKey('name', $properties); + $this->assertArrayHasKey('url', $properties); + } + /** * Should return the last non-empty URL segment * @see https://github.com/indieweb/php-mf2/issues/157 From f1ffcab9d97236eedf83512e7fe9c5a99fcd3d3f Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Mon, 26 Sep 2022 22:37:38 -0700 Subject: [PATCH 3/6] Comment out a test with no assertions --- tests/Mf2/ClassicMicroformatsTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/Mf2/ClassicMicroformatsTest.php b/tests/Mf2/ClassicMicroformatsTest.php index 550c05a..adb23f4 100644 --- a/tests/Mf2/ClassicMicroformatsTest.php +++ b/tests/Mf2/ClassicMicroformatsTest.php @@ -113,10 +113,16 @@ public function testParsesFBerrimanClassicHEntry() { $this->assertContains('txjs', $e['properties']['category']); } - public function testParsesSnarfedOrgArticleCorrectly() { + /** + * This test appears to have never made assertions. When initially + * added it was only printing out the parsed results, probably for + * debugging. Left for reference in case assertions need to be added. + * @see https://github.com/microformats/php-mf2/commit/5fd2c961447f305f50f73e17bd8decf7ec77fa1d#diff-45371c4a595b936f718ab44eb3ff35c326e00a01f2f5cb3d327f34d03750b872 + */ + /*public function testParsesSnarfedOrgArticleCorrectly() { $input = file_get_contents(__DIR__ . '/snarfed.org.html'); $result = Mf2\parse($input, 'http://snarfed.org/2013-10-23_oauth-dropins'); - } + }*/ public function testParsesHProduct() { $input = <<<'EOT' From 8e571f8c155c5c5c19399c6482a89098a5b31587 Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Thu, 7 Mar 2024 21:02:44 -0800 Subject: [PATCH 4/6] Update tests Fixes some warnings in newer versions of PHPUnit. --- tests/Mf2/ParserTest.php | 2 ++ tests/Mf2/URLTest.php | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Mf2/ParserTest.php b/tests/Mf2/ParserTest.php index dcbedb0..7a5228a 100644 --- a/tests/Mf2/ParserTest.php +++ b/tests/Mf2/ParserTest.php @@ -139,6 +139,8 @@ public function testParseEWithWhitespace() { * @group parseH */ public function testInvalidClassnamesContainingHAreIgnored() { + self::expectNotToPerformAssertions(); + $input = '
'; $parser = new Parser($input); $output = $parser->parse(); diff --git a/tests/Mf2/URLTest.php b/tests/Mf2/URLTest.php index c670ba1..32d49ca 100644 --- a/tests/Mf2/URLTest.php +++ b/tests/Mf2/URLTest.php @@ -9,7 +9,7 @@ use Mf2; use Yoast\PHPUnitPolyfills\TestCases\TestCase; -class UrlTest extends TestCase { +class URLTest extends TestCase { protected function set_up() { date_default_timezone_set('Europe/London'); } @@ -149,7 +149,7 @@ public function testResolvesProtocolRelativeUrlsCorrectly() { } /** - * @dataProvider testData + * @dataProvider dataProvider */ public function testReturnsUrlIfAbsolute($assert, $base, $url, $expected) { $actual = mf2\resolveUrl($base, $url); @@ -157,7 +157,7 @@ public function testReturnsUrlIfAbsolute($assert, $base, $url, $expected) { $this->assertEquals($expected, $actual, $assert); } - public function testData() { + public function dataProvider() { // seriously, please update to PHP 5.4 so I can use nice array syntax ;) // fail message, base, url, expected $cases = array( From 113d3af897984c46b5c8e6bc245833baa2835695 Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Thu, 7 Mar 2024 21:44:13 -0800 Subject: [PATCH 5/6] Update hreview backcompat Fix reviewer -> p-author h-card backcompat --- Mf2/Parser.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Mf2/Parser.php b/Mf2/Parser.php index b3d22b7..e049ead 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -1656,6 +1656,16 @@ public function backcompat(DOMElement $el, $context = '', $isParentMf2 = false) } } + $reviewer_nodes = $this->xpath->query('.//*[contains(concat(" ", normalize-space(@class), " "), " reviewer ")]', $el); + + if ( $reviewer_nodes->length ) { + foreach ( $reviewer_nodes as $tempEl ) { + if ( !$this->hasRootMf2($tempEl) ) { + $this->addMfClasses($tempEl, 'p-author h-card'); + } + } + } + $this->upgradeRelTagToCategory($el); break; @@ -2070,10 +2080,7 @@ public function query($expression, $context = null) { 'replace' => 'p-item h-item', 'context' => 'item' ), - 'reviewer' => array( - 'replace' => 'p-author h-card', - 'context' => 'vcard', - ), + # reviewer: see backcompat() 'dtreviewed' => array( 'replace' => 'dt-published' ), From 774a6f8f74a19d323a84493aa1755b6082c2af72 Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Fri, 8 Mar 2024 14:45:57 -0800 Subject: [PATCH 6/6] Update hreview backcompat tests --- tests/Mf2/ClassicMicroformatsTest.php | 4 ++-- tests/Mf2/ParserTest.php | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/Mf2/ClassicMicroformatsTest.php b/tests/Mf2/ClassicMicroformatsTest.php index adb23f4..d84c0f2 100644 --- a/tests/Mf2/ClassicMicroformatsTest.php +++ b/tests/Mf2/ClassicMicroformatsTest.php @@ -959,7 +959,7 @@ public function testHReviewItemVevent() 5 out of 5 stars IndieWebCamp 2014 - - indiewebcamp.com/2014/ + indieweb.org/2014 '; $parser = new Parser($input); @@ -983,7 +983,7 @@ public function testHReviewItemHproduct() 4 out of 5 stars Widget - - example.com/widget/ + example.com/widget/ '; $parser = new Parser($input); diff --git a/tests/Mf2/ParserTest.php b/tests/Mf2/ParserTest.php index 7a5228a..c7b2ef0 100644 --- a/tests/Mf2/ParserTest.php +++ b/tests/Mf2/ParserTest.php @@ -139,17 +139,21 @@ public function testParseEWithWhitespace() { * @group parseH */ public function testInvalidClassnamesContainingHAreIgnored() { - self::expectNotToPerformAssertions(); - - $input = '
'; + $classname = 'asdfgh-jkl'; + $input = sprintf('
', $classname); $parser = new Parser($input); $output = $parser->parse(); - // Look through $output for an item which indicate failure + // Look through parsed items for `type` matching the classname. + // There shouldn't be any + $matches = 0; foreach ($output['items'] as $item) { - if (in_array('asdfgh-jkl', $item['type'])) - $this->fail(); + if (in_array($classname, $item['type'])) { + $matches++; + } } + + $this->assertEquals(0, $matches, sprintf('Class name "%s" should not have parsed as a root microformat', $classname)); } public function testHtmlSpecialCharactersWorks() {