From cef3d61a4c27d484755f9c3fdefa6662d8a61ae6 Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Sat, 25 Aug 2018 12:31:45 -0700 Subject: [PATCH] Add failing test and fix for #182 --- Mf2/Parser.php | 2 +- tests/Mf2/ParseUTest.php | 54 ++++++++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/Mf2/Parser.php b/Mf2/Parser.php index fe5590b..d3ccbe4 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -634,7 +634,7 @@ public function parseP(\DOMElement $p) { public function parseU(\DOMElement $u) { if (($u->tagName == 'a' or $u->tagName == 'area' or $u->tagName == 'link') and $u->hasAttribute('href')) { $uValue = $u->getAttribute('href'); - } elseif (in_array($u->tagName, array('img', 'audio', 'video', 'source')) and $u->hasAttribute('src')) { + } elseif (in_array($u->tagName, array('img', 'audio', 'video', 'source', 'iframe')) and $u->hasAttribute('src')) { $uValue = $u->getAttribute('src'); } elseif ($u->tagName == 'video' and !$u->hasAttribute('src') and $u->hasAttribute('poster')) { $uValue = $u->getAttribute('poster'); diff --git a/tests/Mf2/ParseUTest.php b/tests/Mf2/ParseUTest.php index 0473280..53ebcdf 100644 --- a/tests/Mf2/ParseUTest.php +++ b/tests/Mf2/ParseUTest.php @@ -275,33 +275,49 @@ public function testImpliedUWithEmptyHref() { $this->assertEquals('http://example.com/', $output['items'][4]['children'][0]['properties']['url'][0]); } - public function testValueFromLinkTag() { - $input = <<< END + public function testValueFromLinkTag() { + $input = <<< END - - - - + + + + END; - $parser = new Parser($input, 'https://example.com'); - $output = $parser->parse(); + $parser = new Parser($input, 'https://example.com'); + $output = $parser->parse(); + + $this->assertArrayHasKey('url', $output['items'][0]['properties']); + $this->assertEquals('https://example.com/', $output['items'][0]['properties']['url'][0]); - $this->assertArrayHasKey('url', $output['items'][0]['properties']); - $this->assertEquals('https://example.com/', $output['items'][0]['properties']['url'][0]); + $this->assertArrayHasKey('name', $output['items'][0]['properties']); + $this->assertEquals('Example.com homepage', $output['items'][0]['properties']['name'][0]); + } - $this->assertArrayHasKey('name', $output['items'][0]['properties']); - $this->assertEquals('Example.com homepage', $output['items'][0]['properties']['name'][0]); - } + public function testResolveFromDataElement() { + $parser = new Parser('
', 'https://example.com/index.html'); + $output = $parser->parse(); - public function testResolveFromDataElement() { - $parser = new Parser('
', 'https://example.com/index.html'); - $output = $parser->parse(); + $this->assertArrayHasKey('url', $output['items'][0]['properties']); + $this->assertEquals('https://example.com/relative.html', $output['items'][0]['properties']['url'][0]); + } - $this->assertArrayHasKey('url', $output['items'][0]['properties']); - $this->assertEquals('https://example.com/relative.html', $output['items'][0]['properties']['url'][0]); - } + /** + * @see https://github.com/microformats/php-mf2/issues/182 + */ + public function testResolveFromIframeElement() { + $input = '
+

Title

+ +
'; + $parser = new Parser($input, 'https://example.com'); + $output = $parser->parse(); + $this->assertArrayHasKey('url', $output['items'][0]['properties']); + $this->assertEquals('https://example.com/index.html', $output['items'][0]['properties']['url'][0]); + } }