Skip to content

Commit c8ddd26

Browse files
committed
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.
1 parent d653341 commit c8ddd26

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

Mf2/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ public function parseRelsAndAlternates() {
10251025
$alternates = array();
10261026

10271027
// Iterate through all a, area and link elements with rel attributes
1028-
foreach ($this->xpath->query('//*[@rel and @href]') as $hyperlink) {
1028+
foreach ($this->xpath->query('//a[@rel and @href] | //link[@rel and @href] | //area[@rel and @href]') as $hyperlink) {
10291029
if ($hyperlink->getAttribute('rel') == '')
10301030
continue;
10311031

tests/Mf2/RelTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Tests of the parsing methods within mf2\Parser
4+
*/
5+
6+
namespace Mf2\Parser\Test;
7+
8+
use Mf2;
9+
use Mf2\Parser;
10+
use PHPUnit_Framework_TestCase;
11+
12+
class RelTest extends PHPUnit_Framework_TestCase {
13+
public function setUp() {
14+
date_default_timezone_set('Europe/London');
15+
}
16+
17+
public function testRelValueOnLinkTag() {
18+
$input = '<link rel="webmention" href="http://example.com/webmention">';
19+
$parser = new Parser($input);
20+
$output = $parser->parse();
21+
22+
$this->assertArrayHasKey('webmention', $output['rels']);
23+
$this->assertEquals('http://example.com/webmention', $output['rels']['webmention'][0]);
24+
}
25+
26+
public function testRelValueOnATag() {
27+
$input = '<a rel="webmention" href="http://example.com/webmention">webmention me</a>';
28+
$parser = new Parser($input);
29+
$output = $parser->parse();
30+
31+
$this->assertArrayHasKey('webmention', $output['rels']);
32+
$this->assertEquals('http://example.com/webmention', $output['rels']['webmention'][0]);
33+
}
34+
35+
public function testRelValueOnAreaTag() {
36+
$input = '<map><area rel="webmention" href="http://example.com/webmention"/></map>';
37+
$parser = new Parser($input);
38+
$output = $parser->parse();
39+
40+
$this->assertArrayHasKey('webmention', $output['rels']);
41+
$this->assertEquals('http://example.com/webmention', $output['rels']['webmention'][0]);
42+
}
43+
44+
public function testRelValueOnBTag() {
45+
$input = '<b rel="webmention" href="http://example.com/webmention">this makes no sense</b>';
46+
$parser = new Parser($input);
47+
$output = $parser->parse();
48+
49+
$this->assertArrayNotHasKey('webmention', $output['rels']);
50+
}
51+
52+
}

0 commit comments

Comments
 (0)