Commit c8ddd266 authored by Aaron Parecki's avatar Aaron Parecki

add failing test and fix for #91

only looks on `a`,`link`, and `area` for rel attributes, since these are the only elements that HTML allows to have the rel attribute.
parent d653341e
......@@ -1025,7 +1025,7 @@ class Parser {
$alternates = array();
// Iterate through all a, area and link elements with rel attributes
foreach ($this->xpath->query('//*[@rel and @href]') as $hyperlink) {
foreach ($this->xpath->query('//a[@rel and @href] | //link[@rel and @href] | //area[@rel and @href]') as $hyperlink) {
if ($hyperlink->getAttribute('rel') == '')
continue;
......
<?php
/**
* Tests of the parsing methods within mf2\Parser
*/
namespace Mf2\Parser\Test;
use Mf2;
use Mf2\Parser;
use PHPUnit_Framework_TestCase;
class RelTest extends PHPUnit_Framework_TestCase {
public function setUp() {
date_default_timezone_set('Europe/London');
}
public function testRelValueOnLinkTag() {
$input = '<link rel="webmention" href="http://example.com/webmention">';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/webmention', $output['rels']['webmention'][0]);
}
public function testRelValueOnATag() {
$input = '<a rel="webmention" href="http://example.com/webmention">webmention me</a>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/webmention', $output['rels']['webmention'][0]);
}
public function testRelValueOnAreaTag() {
$input = '<map><area rel="webmention" href="http://example.com/webmention"/></map>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/webmention', $output['rels']['webmention'][0]);
}
public function testRelValueOnBTag() {
$input = '<b rel="webmention" href="http://example.com/webmention">this makes no sense</b>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayNotHasKey('webmention', $output['rels']);
}
}
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