From a462c96c89f40e17068513cec7234de3ae4ef162 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Wed, 24 May 2017 11:23:10 -0700 Subject: [PATCH] parse poster attribute for video tags if there is a poster attribute and no src attribute on a video tag, the poster attribute is used as the value instead. This test won't pass until after #119 is merged to fix the other `getAttribute` issues. --- Mf2/Parser.php | 2 ++ tests/Mf2/ParseUTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/Mf2/Parser.php b/Mf2/Parser.php index ed1f28f..a9bd4c3 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -615,6 +615,8 @@ public function parseU(\DOMElement $u) { $uValue = $u->getAttribute('href'); } elseif (in_array($u->tagName, array('img', 'audio', 'video', 'source')) and $u->getAttribute('src') !== null) { $uValue = $u->getAttribute('src'); + } elseif ($u->tagName == 'video' and !$u->hasAttribute('src') and $u->hasAttribute('poster')) { + $uValue = $u->getAttribute('poster'); } elseif ($u->tagName == 'object' and $u->getAttribute('data') !== null) { $uValue = $u->getAttribute('data'); } diff --git a/tests/Mf2/ParseUTest.php b/tests/Mf2/ParseUTest.php index 1f017d4..4581665 100644 --- a/tests/Mf2/ParseUTest.php +++ b/tests/Mf2/ParseUTest.php @@ -175,6 +175,19 @@ public function testParseUHandlesSource() { $this->assertEquals('http://example.com/video.ogg', $output['items'][0]['properties']['video'][1]); } + /** + * @group parseU + */ + public function testParseUHandlesVideoPoster() { + $input = '
'; + $parser = new Parser($input); + $output = $parser->parse(); + + $this->assertArrayHasKey('video', $output['items'][0]['properties']); + $this->assertEquals('http://example.com/video.mp4', $output['items'][0]['properties']['video'][0]); + $this->assertEquals('http://example.com/posterimage.jpg', $output['items'][0]['properties']['photo'][0]); + } + /** * @group parseU */