1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Add ability to discover multiple feeds

This commit is contained in:
J. King 2020-12-01 17:12:19 -05:00
parent 2a0d6e6599
commit 669e17a1f6
4 changed files with 36 additions and 0 deletions

View file

@ -47,6 +47,17 @@ class Feed {
return $out;
}
public static function discoverAll(string $url, string $username = '', string $password = ''): array {
// fetch the candidate feed
$f = self::download($url, "", "", $username, $password);
if ($f->reader->detectFormat($f->getContent())) {
// if the prospective URL is a feed, use it
return [$url];
} else {
return $f->reader->find($f->getUrl(), $f->getContent());
}
}
public function __construct(int $feedID = null, string $url, string $lastModified = '', string $etag = '', string $username = '', string $password = '', bool $scrape = false) {
// fetch the feed
$this->resource = self::download($url, $lastModified, $etag, $username, $password);

View file

@ -150,6 +150,27 @@ class TestFeed extends \JKingWeb\Arsse\Test\AbstractTest {
Feed::discover($this->base."Discovery/Invalid");
}
public function testDiscoverAMissingFeed(): void {
$this->assertException("invalidUrl", "Feed");
Feed::discover($this->base."Discovery/Missing");
}
public function testDiscoverMultipleFeedsSuccessfully(): void {
$exp1 = [$this->base."Discovery/Feed", $this->base."Discovery/Missing"];
$exp2 = [$this->base."Discovery/Feed"];
$this->assertSame($exp1, Feed::discoverAll($this->base."Discovery/Valid"));
$this->assertSame($exp2, Feed::discoverAll($this->base."Discovery/Feed"));
}
public function testDiscoverMultipleFeedsUnsuccessfully(): void {
$this->assertSame([], Feed::discoverAll($this->base."Discovery/Invalid"));
}
public function testDiscoverMultipleMissingFeeds(): void {
$this->assertException("invalidUrl", "Feed");
Feed::discoverAll($this->base."Discovery/Missing");
}
public function testParseEntityExpansionAttack(): void {
$this->assertException("xmlEntity", "Feed");
new Feed(null, $this->base."Parsing/XEEAttack");

View file

@ -0,0 +1,3 @@
<?php return [
'code' => 404,
];

View file

@ -4,6 +4,7 @@
<html>
<title>Example article</title>
<link rel="alternate" type="application/rss+xml" href="http://localhost:8000/Feed/Discovery/Feed">
<link rel="alternate" type="application/rss+xml" href="http://localhost:8000/Feed/Discovery/Missing">
</html>
MESSAGE_BODY
];