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); } diff --git a/tests/Mf2/ParseLanguageTest.php b/tests/Mf2/ParseLanguageTest.php index eb6cbb3..9ecb57f 100644 --- a/tests/Mf2/ParseLanguageTest.php +++ b/tests/Mf2/ParseLanguageTest.php @@ -52,6 +52,43 @@ 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 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