Skip to content

Commit

Permalink
Merge pull request #25 from aaronpk/master
Browse files Browse the repository at this point in the history
adds failing test and fix for #24
  • Loading branch information
aaronpk committed Apr 15, 2016
2 parents 83d2d4b + 80011d5 commit 042236b
Show file tree
Hide file tree
Showing 8 changed files with 428 additions and 376 deletions.
729 changes: 359 additions & 370 deletions coverage/MentionClient.php.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions coverage/dashboard.html
Expand Up @@ -136,7 +136,7 @@ <h3>Project Risks</h3>
<footer>
<hr/>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 3.3.0-3-g9b2a050</a> using <a href="http://php.net/" target="_top">PHP 5.6.19</a> and <a href="https://phpunit.de/">PHPUnit 5.4-g1206dd3</a> at Mon Apr 4 15:08:54 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 3.3.0-3-g9b2a050</a> using <a href="http://php.net/" target="_top">PHP 5.6.19</a> and <a href="https://phpunit.de/">PHPUnit 5.4-g1206dd3</a> at Fri Apr 15 6:43:46 UTC 2016.</small>
</p>
</footer>
</div>
Expand Down Expand Up @@ -225,7 +225,7 @@ <h3>Project Risks</h3>
chart.yAxis.axisLabel('Cyclomatic Complexity');

d3.select('#classComplexity svg')
.datum(getComplexityData([[100,84,"<a href=\"MentionClient.php.html#4\">MentionClient<\/a>"]], 'Class Complexity'))
.datum(getComplexityData([[100,83,"<a href=\"MentionClient.php.html#4\">MentionClient<\/a>"]], 'Class Complexity'))
.transition()
.duration(500)
.call(chart);
Expand All @@ -249,7 +249,7 @@ <h3>Project Risks</h3>
chart.yAxis.axisLabel('Method Complexity');

d3.select('#methodComplexity svg')
.datum(getComplexityData([[100,1,"<a href=\"MentionClient.php.html#24\">MentionClient::setProxy<\/a>"],[100,6,"<a href=\"MentionClient.php.html#28\">MentionClient::discoverPingbackEndpoint<\/a>"],[100,5,"<a href=\"MentionClient.php.html#63\">MentionClient::sendPingbackToEndpoint<\/a>"],[100,3,"<a href=\"MentionClient.php.html#92\">MentionClient::sendPingback<\/a>"],[100,6,"<a href=\"MentionClient.php.html#108\">MentionClient::_findWebmentionEndpointInHTML<\/a>"],[100,6,"<a href=\"MentionClient.php.html#121\">MentionClient::_findWebmentionEndpointInHeader<\/a>"],[100,9,"<a href=\"MentionClient.php.html#135\">MentionClient::discoverWebmentionEndpoint<\/a>"],[100,1,"<a href=\"MentionClient.php.html#180\">MentionClient::sendWebmentionToEndpoint<\/a>"],[100,3,"<a href=\"MentionClient.php.html#195\">MentionClient::sendWebmention<\/a>"],[100,7,"<a href=\"MentionClient.php.html#211\">MentionClient::findOutgoingLinks<\/a>"],[100,1,"<a href=\"MentionClient.php.html#241\">MentionClient::findLinksInText<\/a>"],[100,4,"<a href=\"MentionClient.php.html#246\">MentionClient::findLinksInJSON<\/a>"],[100,4,"<a href=\"MentionClient.php.html#257\">MentionClient::sendMentions<\/a>"],[100,8,"<a href=\"MentionClient.php.html#281\">MentionClient::sendFirstSupportedMention<\/a>"],[100,1,"<a href=\"MentionClient.php.html#308\">MentionClient::enableDebug<\/a>"],[100,2,"<a href=\"MentionClient.php.html#314\">MentionClient::_debug<\/a>"],[100,2,"<a href=\"MentionClient.php.html#322\">MentionClient::_head<\/a>"],[100,2,"<a href=\"MentionClient.php.html#339\">MentionClient::_get<\/a>"],[100,2,"<a href=\"MentionClient.php.html#357\">MentionClient::_post<\/a>"],[100,5,"<a href=\"MentionClient.php.html#375\">MentionClient::_parse_headers<\/a>"],[100,1,"<a href=\"MentionClient.php.html#384\">MentionClient::anonymous function<\/a>"],[100,2,"<a href=\"MentionClient.php.html#399\">MentionClient::xmlrpc_encode_request<\/a>"],[100,3,"<a href=\"MentionClient.php.html#412\">MentionClient::c<\/a>"]], 'Method Complexity'))
.datum(getComplexityData([[100,1,"<a href=\"MentionClient.php.html#24\">MentionClient::setProxy<\/a>"],[100,6,"<a href=\"MentionClient.php.html#28\">MentionClient::discoverPingbackEndpoint<\/a>"],[100,5,"<a href=\"MentionClient.php.html#63\">MentionClient::sendPingbackToEndpoint<\/a>"],[100,3,"<a href=\"MentionClient.php.html#82\">MentionClient::sendPingback<\/a>"],[100,6,"<a href=\"MentionClient.php.html#98\">MentionClient::_findWebmentionEndpointInHTML<\/a>"],[100,5,"<a href=\"MentionClient.php.html#112\">MentionClient::_findWebmentionEndpointInHeader<\/a>"],[100,9,"<a href=\"MentionClient.php.html#124\">MentionClient::discoverWebmentionEndpoint<\/a>"],[100,1,"<a href=\"MentionClient.php.html#169\">MentionClient::sendWebmentionToEndpoint<\/a>"],[100,3,"<a href=\"MentionClient.php.html#184\">MentionClient::sendWebmention<\/a>"],[100,7,"<a href=\"MentionClient.php.html#200\">MentionClient::findOutgoingLinks<\/a>"],[100,1,"<a href=\"MentionClient.php.html#230\">MentionClient::findLinksInText<\/a>"],[100,4,"<a href=\"MentionClient.php.html#235\">MentionClient::findLinksInJSON<\/a>"],[100,4,"<a href=\"MentionClient.php.html#246\">MentionClient::sendMentions<\/a>"],[100,8,"<a href=\"MentionClient.php.html#270\">MentionClient::sendFirstSupportedMention<\/a>"],[100,1,"<a href=\"MentionClient.php.html#297\">MentionClient::enableDebug<\/a>"],[100,2,"<a href=\"MentionClient.php.html#303\">MentionClient::_debug<\/a>"],[100,2,"<a href=\"MentionClient.php.html#311\">MentionClient::_head<\/a>"],[100,2,"<a href=\"MentionClient.php.html#328\">MentionClient::_get<\/a>"],[100,2,"<a href=\"MentionClient.php.html#346\">MentionClient::_post<\/a>"],[100,5,"<a href=\"MentionClient.php.html#364\">MentionClient::_parse_headers<\/a>"],[100,1,"<a href=\"MentionClient.php.html#373\">MentionClient::anonymous function<\/a>"],[100,2,"<a href=\"MentionClient.php.html#388\">MentionClient::xmlrpc_encode_request<\/a>"],[100,3,"<a href=\"MentionClient.php.html#401\">MentionClient::c<\/a>"]], 'Method Complexity'))
.transition()
.duration(500)
.call(chart);
Expand Down
6 changes: 3 additions & 3 deletions coverage/index.html
Expand Up @@ -49,7 +49,7 @@
</div>
</td>
<td class="success small"><div align="right">100.00%</div></td>
<td class="success small"><div align="right">203&nbsp;/&nbsp;203</div></td>
<td class="success small"><div align="right">196&nbsp;/&nbsp;196</div></td>
<td class="success big"> <div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: 100.00%">
<span class="sr-only">100.00% covered (success)</span>
Expand Down Expand Up @@ -77,7 +77,7 @@
</div>
</td>
<td class="success small"><div align="right">100.00%</div></td>
<td class="success small"><div align="right">203&nbsp;/&nbsp;203</div></td>
<td class="success small"><div align="right">196&nbsp;/&nbsp;196</div></td>
<td class="success big"> <div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: 100.00%">
<span class="sr-only">100.00% covered (success)</span>
Expand Down Expand Up @@ -108,7 +108,7 @@ <h4>Legend</h4>
<span class="success"><strong>High</strong>: 90% to 100%</span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 3.3.0-3-g9b2a050</a> using <a href="http://php.net/" target="_top">PHP 5.6.19</a> and <a href="https://phpunit.de/">PHPUnit 5.4-g1206dd3</a> at Mon Apr 4 15:08:54 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 3.3.0-3-g9b2a050</a> using <a href="http://php.net/" target="_top">PHP 5.6.19</a> and <a href="https://phpunit.de/">PHPUnit 5.4-g1206dd3</a> at Fri Apr 15 6:43:46 UTC 2016.</small>
</p>
</footer>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/IndieWeb/MentionClient.php
Expand Up @@ -97,6 +97,7 @@ public function sendPingback($sourceURL, $targetURL) {

protected function _findWebmentionEndpointInHTML($body, $targetURL=false) {
$endpoint = false;
$body = preg_replace('/<!--(.*)-->/Us', '', $body);
if(preg_match('/<(?:link|a)[ ]+href="([^"]+)"[ ]+rel="[^" ]* ?webmention ?[^" ]*"[ ]*\/?>/i', $body, $match)
|| preg_match('/<(?:link|a)[ ]+rel="[^" ]* ?webmention ?[^" ]*"[ ]+href="([^"]+)"[ ]*\/?>/i', $body, $match)) {
$endpoint = $match[1];
Expand Down
18 changes: 18 additions & 0 deletions tests/DiscoverTest.php
Expand Up @@ -69,6 +69,24 @@ public function testDiscoverWebmentionEndpointInBodyA() {
$this->assertEquals('http://webmention.example/webmention', $endpoint);
}

public function testShouldNotDiscoverWebmentionEndpointInBodyComment() {
$target = 'http://target.example.com/false-endpoint-in-comment.html';
$endpoint = $this->client->discoverWebmentionEndpoint($target);
$this->assertEquals('http://webmention.example/correct', $endpoint);
}

public function testDiscoverWebmentionEndpointInDocumentOrder1() {
$target = 'http://target.example.com/document-order-1.html';
$endpoint = $this->client->discoverWebmentionEndpoint($target);
$this->assertEquals('http://webmention.example/link', $endpoint);
}

public function testDiscoverWebmentionEndpointInDocumentOrder2() {
$target = 'http://target.example.com/document-order-2.html';
$endpoint = $this->client->discoverWebmentionEndpoint($target);
$this->assertEquals('http://webmention.example/a', $endpoint);
}

public function testDiscoverWebmentionEndpointInWebmentionRocksTest1() {
$target = "http://target.example.com/webmention-rocks-test-1.html";
$endpoint = $this->client->discoverWebmentionEndpoint($target);
Expand Down
14 changes: 14 additions & 0 deletions tests/data/target.example.com/document-order-1.html
@@ -0,0 +1,14 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive

<html>
<head>
<link rel="webmention" href="http://webmention.example/link">
</head>
<body>
<p>You can send me a <a rel="webmention" href="http://webmention.example/a">webmention</a> or pingback</p>
</body>
</html>
12 changes: 12 additions & 0 deletions tests/data/target.example.com/document-order-2.html
@@ -0,0 +1,12 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive

<html>
<body>
<p>You can send me a <a rel="webmention" href="http://webmention.example/a">webmention</a> or pingback</p>
<link rel="webmention" href="http://webmention.example/link">
</body>
</html>
18 changes: 18 additions & 0 deletions tests/data/target.example.com/false-endpoint-in-comment.html
@@ -0,0 +1,18 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive

<html>
<head>
<title>Test</title>
</head>
<body>
<p>You can send me a webmention</p>
<!--
<a rel="webmention" href="http://webmention.example/wrong"></a>
-->
<a rel="webmention" href="http://webmention.example/correct"></a>
</body>
</html>

0 comments on commit 042236b

Please sign in to comment.