Skip to content

Commit a462c96

Browse files
committed
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.
1 parent eb22f33 commit a462c96

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Mf2/Parser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ public function parseU(\DOMElement $u) {
615615
$uValue = $u->getAttribute('href');
616616
} elseif (in_array($u->tagName, array('img', 'audio', 'video', 'source')) and $u->getAttribute('src') !== null) {
617617
$uValue = $u->getAttribute('src');
618+
} elseif ($u->tagName == 'video' and !$u->hasAttribute('src') and $u->hasAttribute('poster')) {
619+
$uValue = $u->getAttribute('poster');
618620
} elseif ($u->tagName == 'object' and $u->getAttribute('data') !== null) {
619621
$uValue = $u->getAttribute('data');
620622
}

tests/Mf2/ParseUTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ public function testParseUHandlesSource() {
175175
$this->assertEquals('http://example.com/video.ogg', $output['items'][0]['properties']['video'][1]);
176176
}
177177

178+
/**
179+
* @group parseU
180+
*/
181+
public function testParseUHandlesVideoPoster() {
182+
$input = '<div class="h-entry"><video class="u-photo" poster="http://example.com/posterimage.jpg"><source class="u-video" src="http://example.com/video.mp4" type="video/mp4"></video></div>';
183+
$parser = new Parser($input);
184+
$output = $parser->parse();
185+
186+
$this->assertArrayHasKey('video', $output['items'][0]['properties']);
187+
$this->assertEquals('http://example.com/video.mp4', $output['items'][0]['properties']['video'][0]);
188+
$this->assertEquals('http://example.com/posterimage.jpg', $output['items'][0]['properties']['photo'][0]);
189+
}
190+
178191
/**
179192
* @group parseU
180193
*/

0 commit comments

Comments
 (0)