From 23aabcb8bc1a12dad81e20dd30cad887601c7230 Mon Sep 17 00:00:00 2001 From: Joschi Kuphal Date: Thu, 25 May 2017 18:41:24 +0200 Subject: [PATCH 1/3] Fixed language detection to support parsing of HTML fragments --- Mf2/Parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mf2/Parser.php b/Mf2/Parser.php index 575d10d..1f76f0a 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -508,7 +508,7 @@ public function language(DOMElement $el) return unicodeTrim($node->getAttribute('content')); } } - } else { + } elseif ($el->parentNode instanceof DOMElement) { // check the parent node return $this->language($el->parentNode); } From acda009e80c4245028e8a42b5c821171fab64644 Mon Sep 17 00:00:00 2001 From: Joschi Kuphal Date: Fri, 26 May 2017 16:58:00 +0200 Subject: [PATCH 2/3] Added test for HTML fragment language testing (#121) --- tests/Mf2/ParseLanguageTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Mf2/ParseLanguageTest.php b/tests/Mf2/ParseLanguageTest.php index eb6cbb3..9dd3d14 100644 --- a/tests/Mf2/ParseLanguageTest.php +++ b/tests/Mf2/ParseLanguageTest.php @@ -52,6 +52,18 @@ public function testHtmlAndHEntryLang() $this->assertEquals('es', $result['items'][0]['properties']['html-lang']); } # end method testHtmlAndHEntryLang() + /** + * Test HTML fragment with only h-entry lang + */ + public function testFragmentHEntryLangOnly() + { + $input = '
This test is in English.
'; + $parser = new Parser($input); + $result = $parser->parse(); + + $this->assertEquals('en', $result['items'][0]['properties']['html-lang']); + } # end method testFragmentHEntryLangOnly() + /** * Test with different , h-entry lang, and h-entry without lang, * which should inherit from the From f101447a3b04ecd4b012cd7220202a941b0fbd82 Mon Sep 17 00:00:00 2001 From: Joschi Kuphal Date: Sat, 27 May 2017 16:57:51 +0200 Subject: [PATCH 3/3] Added XML loading test for HTML fragment language testing (#121) --- tests/Mf2/ParseLanguageTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Mf2/ParseLanguageTest.php b/tests/Mf2/ParseLanguageTest.php index 9dd3d14..9ecb57f 100644 --- a/tests/Mf2/ParseLanguageTest.php +++ b/tests/Mf2/ParseLanguageTest.php @@ -64,6 +64,31 @@ public function testFragmentHEntryLangOnly() $this->assertEquals('en', $result['items'][0]['properties']['html-lang']); } # end method testFragmentHEntryLangOnly() + /** + * Test HTML fragment with no lang + */ + public function testFragmentHEntryNoLang() + { + $input = '
This test is in English.
'; + $parser = new Parser($input); + $result = $parser->parse(); + + $this->assertFalse(isset($result['items'][0]['properties']['html-lang'])); + } # end method testFragmentHEntryNoLang() + + /** + * Test HTML fragment with no lang, loaded with loadXML() + */ + public function testFragmentHEntryNoLangXML() + { + $input = new \DOMDocument(); + $input->loadXML('
This test is in English.
'); + $parser = new Parser($input); + $result = $parser->parse(); + + $this->assertFalse(isset($result['items'][0]['properties']['html-lang'])); + } # end method testFragmentHEntryNoLangXML() + /** * Test with different , h-entry lang, and h-entry without lang, * which should inherit from the