Skip to content

Commit f8480ec

Browse files
Merge pull request #92 from aaronpk/reltags
add failing test and fix for #91
2 parents 0762d6b + 70cc3c1 commit f8480ec

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

Mf2/Parser.php

+1-1
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

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 testRelValueOrder() {
45+
$input = '<map><area rel="webmention" href="http://example.com/area"/></map>
46+
<a rel="webmention" href="http://example.com/a">webmention me</a>
47+
<link rel="webmention" href="http://example.com/link">';
48+
$parser = new Parser($input);
49+
$output = $parser->parse();
50+
51+
$this->assertArrayHasKey('webmention', $output['rels']);
52+
$this->assertEquals('http://example.com/area', $output['rels']['webmention'][0]);
53+
$this->assertEquals('http://example.com/a', $output['rels']['webmention'][1]);
54+
$this->assertEquals('http://example.com/link', $output['rels']['webmention'][2]);
55+
}
56+
57+
public function testRelValueOrder2() {
58+
$input = '<map><area rel="webmention" href="http://example.com/area"/></map>
59+
<link rel="webmention" href="http://example.com/link">
60+
<a rel="webmention" href="http://example.com/a">webmention me</a>';
61+
$parser = new Parser($input);
62+
$output = $parser->parse();
63+
64+
$this->assertArrayHasKey('webmention', $output['rels']);
65+
$this->assertEquals('http://example.com/area', $output['rels']['webmention'][0]);
66+
$this->assertEquals('http://example.com/link', $output['rels']['webmention'][1]);
67+
$this->assertEquals('http://example.com/a', $output['rels']['webmention'][2]);
68+
}
69+
70+
public function testRelValueOrder3() {
71+
$input = '<html>
72+
<head>
73+
<link rel="webmention" href="http://example.com/link">
74+
</head>
75+
<body>
76+
<a rel="webmention" href="http://example.com/a">webmention me</a>
77+
<map><area rel="webmention" href="http://example.com/area"/></map>
78+
</body>
79+
</html>';
80+
$parser = new Parser($input);
81+
$output = $parser->parse();
82+
83+
$this->assertArrayHasKey('webmention', $output['rels']);
84+
$this->assertEquals('http://example.com/link', $output['rels']['webmention'][0]);
85+
$this->assertEquals('http://example.com/a', $output['rels']['webmention'][1]);
86+
$this->assertEquals('http://example.com/area', $output['rels']['webmention'][2]);
87+
}
88+
89+
public function testRelValueOnBTag() {
90+
$input = '<b rel="webmention" href="http://example.com/webmention">this makes no sense</b>';
91+
$parser = new Parser($input);
92+
$output = $parser->parse();
93+
94+
$this->assertArrayNotHasKey('webmention', $output['rels']);
95+
}
96+
97+
}

0 commit comments

Comments
 (0)