Commit 9fb3c217 authored by Aaron Parecki's avatar Aaron Parecki Committed by GitHub

Merge branch 'master' into issue-114

parents a462c96c 26e4ed43
......@@ -588,13 +588,13 @@ class Parser {
$this->resolveChildUrls($p);
if ($p->tagName == 'img' and $p->getAttribute('alt') !== '') {
if ($p->tagName == 'img' and $p->hasAttribute('alt')) {
$pValue = $p->getAttribute('alt');
} elseif ($p->tagName == 'area' and $p->getAttribute('alt') !== '') {
} elseif ($p->tagName == 'area' and $p->hasAttribute('alt')) {
$pValue = $p->getAttribute('alt');
} elseif ($p->tagName == 'abbr' and $p->getAttribute('title') !== '') {
} elseif ($p->tagName == 'abbr' and $p->hasAttribute('title')) {
$pValue = $p->getAttribute('title');
} elseif (in_array($p->tagName, array('data', 'input')) and $p->getAttribute('value') !== '') {
} elseif (in_array($p->tagName, array('data', 'input')) and $p->hasAttribute('value')) {
$pValue = $p->getAttribute('value');
} else {
$pValue = unicodeTrim($this->innerText($p));
......@@ -611,13 +611,13 @@ class Parser {
* @todo make this adhere to value-class
*/
public function parseU(\DOMElement $u) {
if (($u->tagName == 'a' or $u->tagName == 'area') and $u->getAttribute('href') !== null) {
if (($u->tagName == 'a' or $u->tagName == 'area') and $u->hasAttribute('href')) {
$uValue = $u->getAttribute('href');
} elseif (in_array($u->tagName, array('img', 'audio', 'video', 'source')) and $u->getAttribute('src') !== null) {
} elseif (in_array($u->tagName, array('img', 'audio', 'video', 'source')) and $u->hasAttribute('src')) {
$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) {
} elseif ($u->tagName == 'object' and $u->hasAttribute('data')) {
$uValue = $u->getAttribute('data');
}
......@@ -629,9 +629,9 @@ class Parser {
if ($classTitle !== null) {
return $classTitle;
} elseif ($u->tagName == 'abbr' and $u->getAttribute('title') !== null) {
} elseif ($u->tagName == 'abbr' and $u->hasAttribute('title')) {
return $u->getAttribute('title');
} elseif (in_array($u->tagName, array('data', 'input')) and $u->getAttribute('value') !== null) {
} elseif (in_array($u->tagName, array('data', 'input')) and $u->hasAttribute('value')) {
return $u->getAttribute('value');
} else {
return unicodeTrim($this->textContent($u));
......@@ -1130,7 +1130,7 @@ class Parser {
if ($el->tagName == 'img') {
return $el->getAttribute('src');
} else if ($el->tagName == 'object' && $el->getAttribute('data') != '') {
} else if ($el->tagName == 'object' && $el->hasAttribute('data')) {
return $el->getAttribute('data');
}
......
......@@ -67,6 +67,18 @@ class ParsePTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('Example User', $output['items'][0]['properties']['name'][0]);
}
/**
* @group parseP
*/
public function testParsePHandlesDataWithBlankValueAttribute() {
$input = '<div class="h-card"><data class="p-name" value="">Example User</data></div>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('name', $output['items'][0]['properties']);
$this->assertEquals('', $output['items'][0]['properties']['name'][0]);
}
/**
* @group parseP
*/
......
......@@ -25,7 +25,31 @@ class ParseUTest extends PHPUnit_Framework_TestCase {
$this->assertArrayHasKey('url', $output['items'][0]['properties']);
$this->assertEquals('http://example.com', $output['items'][0]['properties']['url'][0]);
}
/**
* @group parseU
*/
public function testParseUHandlesEmptyHrefAttribute() {
$input = '<div class="h-card"><a class="u-url" href="">Awesome example website</a></div>';
$parser = new Parser($input, "http://example.com/");
$output = $parser->parse();
$this->assertArrayHasKey('url', $output['items'][0]['properties']);
$this->assertEquals('http://example.com/', $output['items'][0]['properties']['url'][0]);
}
/**
* @group parseU
*/
public function testParseUHandlesMissingHrefAttribute() {
$input = '<div class="h-card"><a class="u-url">Awesome example website</a></div>';
$parser = new Parser($input, "http://example.com/");
$output = $parser->parse();
$this->assertArrayHasKey('url', $output['items'][0]['properties']);
$this->assertEquals('Awesome example website', $output['items'][0]['properties']['url'][0]);
}
/**
* @group parseU
*/
......@@ -73,6 +97,18 @@ class ParseUTest extends PHPUnit_Framework_TestCase {
$this->assertArrayHasKey('photo', $output['items'][0]['properties']);
$this->assertEquals('http://example.com/someimage.png', $output['items'][0]['properties']['photo'][0]);
}
/**
* @group parseU
*/
public function testParseUHandlesAbbrNoTitle() {
$input = '<div class="h-card"><abbr class="u-photo">no title attribute</abbr></div>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('photo', $output['items'][0]['properties']);
$this->assertEquals('no title attribute', $output['items'][0]['properties']['photo'][0]);
}
/**
* @group parseU
......@@ -161,6 +197,17 @@ class ParseUTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('http://example.com/video.mp4', $output['items'][0]['properties']['video'][0]);
}
/**
* @group parseU
*/
public function testParseUHandlesVideoNoSrc() {
$input = '<div class="h-entry"><video class="u-video">no video support</video></div>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('video', $output['items'][0]['properties']);
$this->assertEquals('no video support', $output['items'][0]['properties']['video'][0]);
}
/**
* @group parseU
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment