Skip to content

Commit

Permalink
Merge pull request #92 from aaronpk/reltags
Browse files Browse the repository at this point in the history
add failing test and fix for #91
  • Loading branch information
barnabywalters committed Apr 17, 2016
2 parents 0762d6b + 70cc3c1 commit f8480ec
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ public function parseRelsAndAlternates() {
$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;

Expand Down
97 changes: 97 additions & 0 deletions tests/Mf2/RelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?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 testRelValueOrder() {
$input = '<map><area rel="webmention" href="http://example.com/area"/></map>
<a rel="webmention" href="http://example.com/a">webmention me</a>
<link rel="webmention" href="http://example.com/link">';
$parser = new Parser($input);
$output = $parser->parse();

$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/area', $output['rels']['webmention'][0]);
$this->assertEquals('http://example.com/a', $output['rels']['webmention'][1]);
$this->assertEquals('http://example.com/link', $output['rels']['webmention'][2]);
}

public function testRelValueOrder2() {
$input = '<map><area rel="webmention" href="http://example.com/area"/></map>
<link rel="webmention" href="http://example.com/link">
<a rel="webmention" href="http://example.com/a">webmention me</a>';
$parser = new Parser($input);
$output = $parser->parse();

$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/area', $output['rels']['webmention'][0]);
$this->assertEquals('http://example.com/link', $output['rels']['webmention'][1]);
$this->assertEquals('http://example.com/a', $output['rels']['webmention'][2]);
}

public function testRelValueOrder3() {
$input = '<html>
<head>
<link rel="webmention" href="http://example.com/link">
</head>
<body>
<a rel="webmention" href="http://example.com/a">webmention me</a>
<map><area rel="webmention" href="http://example.com/area"/></map>
</body>
</html>';
$parser = new Parser($input);
$output = $parser->parse();

$this->assertArrayHasKey('webmention', $output['rels']);
$this->assertEquals('http://example.com/link', $output['rels']['webmention'][0]);
$this->assertEquals('http://example.com/a', $output['rels']['webmention'][1]);
$this->assertEquals('http://example.com/area', $output['rels']['webmention'][2]);
}

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']);
}

}

0 comments on commit f8480ec

Please sign in to comment.