aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2020-03-05 21:34:40 +0100
committerChristian Weiske <cweiske@cweiske.de>2020-03-05 21:34:40 +0100
commit54fbef1610d1c2ecb48fb149602e3b88f80747df (patch)
treef07238ab56a49b5dab6fc213b632242fd54394c3
parentab2ebeda104555928ef044c662b1e672c067e218 (diff)
downloadphinde-54fbef1610d1c2ecb48fb149602e3b88f80747df.tar.gz
phinde-54fbef1610d1c2ecb48fb149602e3b88f80747df.zip
Support web linking in rss feed (atom:link)
-rw-r--r--src/phinde/HubUrlExtractor.php2
-rw-r--r--tests/HubUrlExtractorTest.php62
2 files changed, 54 insertions, 10 deletions
diff --git a/src/phinde/HubUrlExtractor.php b/src/phinde/HubUrlExtractor.php
index b33abfe..a7f38a0 100644
--- a/src/phinde/HubUrlExtractor.php
+++ b/src/phinde/HubUrlExtractor.php
@@ -77,7 +77,7 @@ class HubUrlExtractor
$tagQuery = '/atom:feed/atom:link[';
} else if ($type === 'application/rss+xml') {
- $tagQuery = '/rss/channel/link[';
+ $tagQuery = '/rss/channel/*[(self::link or self::atom:link) and ';
} else {
$tagQuery = '/*[self::html or self::h:html]'
diff --git a/tests/HubUrlExtractorTest.php b/tests/HubUrlExtractorTest.php
index 4c0a44b..418185e 100644
--- a/tests/HubUrlExtractorTest.php
+++ b/tests/HubUrlExtractorTest.php
@@ -13,7 +13,7 @@ class HubUrlExtractorTest extends \PHPUnit\Framework\TestCase
. "\r\n",
'http://example.org/'
);
-
+
$extractor = new phinde\HubUrlExtractor();
$extractor->setRequestTemplate(
new HTTP_Request2(null, null, ['adapter' => $mock])
@@ -27,7 +27,7 @@ class HubUrlExtractorTest extends \PHPUnit\Framework\TestCase
$extractor->getUrls('http://example.org/')
);
}
-
+
public function testGetUrlsHtml()
{
$mock = new HTTP_Request2_Adapter_Mock();
@@ -55,7 +55,7 @@ class HubUrlExtractorTest extends \PHPUnit\Framework\TestCase
HTM,
'http://example.org/'
);
-
+
$extractor = new phinde\HubUrlExtractor();
$extractor->setRequestTemplate(
new HTTP_Request2(null, null, ['adapter' => $mock])
@@ -69,7 +69,7 @@ HTM,
$extractor->getUrls('http://example.org/')
);
}
-
+
public function testGetUrlsXHtml()
{
$mock = new HTTP_Request2_Adapter_Mock();
@@ -97,7 +97,7 @@ HTM,
HTM,
'http://example.org/'
);
-
+
$extractor = new phinde\HubUrlExtractor();
$extractor->setRequestTemplate(
new HTTP_Request2(null, null, ['adapter' => $mock])
@@ -111,7 +111,7 @@ HTM,
$extractor->getUrls('http://example.org/')
);
}
-
+
public function testGetUrlsAtom()
{
$mock = new HTTP_Request2_Adapter_Mock();
@@ -139,7 +139,7 @@ HTM,
HTM,
'http://example.org/'
);
-
+
$extractor = new phinde\HubUrlExtractor();
$extractor->setRequestTemplate(
new HTTP_Request2(null, null, ['adapter' => $mock])
@@ -153,7 +153,7 @@ HTM,
$extractor->getUrls('http://example.org/')
);
}
-
+
public function testGetUrlsRss2()
{
$mock = new HTTP_Request2_Adapter_Mock();
@@ -183,7 +183,51 @@ HTM,
HTM,
'http://example.org/'
);
-
+
+ $extractor = new phinde\HubUrlExtractor();
+ $extractor->setRequestTemplate(
+ new HTTP_Request2(null, null, ['adapter' => $mock])
+ );
+
+ $this->assertEquals(
+ [
+ 'hub' => 'https://hub.example.com/',
+ 'self' => 'http://example.com/feed',
+ ],
+ $extractor->getUrls('http://example.org/')
+ );
+ }
+
+ public function testGetUrlsRss2WebLinking()
+ {
+ $mock = new HTTP_Request2_Adapter_Mock();
+ //HEAD
+ $this->addResponse(
+ $mock,
+ "HTTP/1.0 200 OK\r\n"
+ . "Content-type: application/rss+xml\r\n"
+ . "\r\n",
+ 'http://example.org/'
+ );
+ //HEAD
+ $this->addResponse(
+ $mock,
+ "HTTP/1.0 200 OK\r\n"
+ . "Content-type: application/rss+xml\r\n"
+ . "\r\n"
+ . <<<HTM
+<?xml version="1.0" encoding="utf-8"?>
+<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
+ <channel>
+ <link>http://www.example.com/main.html</link>
+ <atom:link rel="self" href="http://example.com/feed"/>
+ <atom:link rel="hub" href="https://hub.example.com/"/>
+ </channel>
+</rss>
+HTM,
+ 'http://example.org/'
+ );
+
$extractor = new phinde\HubUrlExtractor();
$extractor->setRequestTemplate(
new HTTP_Request2(null, null, ['adapter' => $mock])