Skip to content

Commit 28fd812

Browse files
committed
Merge pull request #65 from gRegorLove/develop2
Added parse+tests for audio, video, and source elements.
2 parents 4b6fb63 + f07f0e3 commit 28fd812

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

‎Mf2/Parser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public function parseP(\DOMElement $p) {
442442
public function parseU(\DOMElement $u) {
443443
if (($u->tagName == 'a' or $u->tagName == 'area') and $u->getAttribute('href') !== null) {
444444
$uValue = $u->getAttribute('href');
445-
} elseif ($u->tagName == 'img' and $u->getAttribute('src') !== null) {
445+
} elseif (in_array($u->tagName, array('img', 'audio', 'video', 'source')) and $u->getAttribute('src') !== null) {
446446
$uValue = $u->getAttribute('src');
447447
} elseif ($u->tagName == 'object' and $u->getAttribute('data') !== null) {
448448
$uValue = $u->getAttribute('data');

‎tests/Mf2/ParseUTest.php

+39
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,43 @@ public function testParsesHrefBeforeValueClass() {
136136
$result = Mf2\parse($input);
137137
$this->assertEquals('http://example.com/right', $result['items'][0]['properties']['url'][0]);
138138
}
139+
140+
/**
141+
* @group parseU
142+
*/
143+
public function testParseUHandlesAudio() {
144+
$input = '<div class="h-entry"><audio class="u-audio" src="http://example.com/audio.mp3"></div>';
145+
$parser = new Parser($input);
146+
$output = $parser->parse();
147+
148+
$this->assertArrayHasKey('audio', $output['items'][0]['properties']);
149+
$this->assertEquals('http://example.com/audio.mp3', $output['items'][0]['properties']['audio'][0]);
150+
}
151+
152+
/**
153+
* @group parseU
154+
*/
155+
public function testParseUHandlesVideo() {
156+
$input = '<div class="h-entry"><video class="u-video" src="http://example.com/video.mp4"></video></div>';
157+
$parser = new Parser($input);
158+
$output = $parser->parse();
159+
160+
$this->assertArrayHasKey('video', $output['items'][0]['properties']);
161+
$this->assertEquals('http://example.com/video.mp4', $output['items'][0]['properties']['video'][0]);
162+
}
163+
164+
165+
/**
166+
* @group parseU
167+
*/
168+
public function testParseUHandlesSource() {
169+
$input = '<div class="h-entry"><video><source class="u-video" src="http://example.com/video.mp4" type="video/mp4"><source class="u-video" src="http://example.com/video.ogg" type="video/ogg"></video></div>';
170+
$parser = new Parser($input);
171+
$output = $parser->parse();
172+
173+
$this->assertArrayHasKey('video', $output['items'][0]['properties']);
174+
$this->assertEquals('http://example.com/video.mp4', $output['items'][0]['properties']['video'][0]);
175+
$this->assertEquals('http://example.com/video.ogg', $output['items'][0]['properties']['video'][1]);
176+
}
177+
139178
}

0 commit comments

Comments
 (0)