mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Add ability to discover multiple feeds
This commit is contained in:
parent
2a0d6e6599
commit
669e17a1f6
4 changed files with 36 additions and 0 deletions
11
lib/Feed.php
11
lib/Feed.php
|
@ -47,6 +47,17 @@ class Feed {
|
||||||
return $out;
|
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) {
|
public function __construct(int $feedID = null, string $url, string $lastModified = '', string $etag = '', string $username = '', string $password = '', bool $scrape = false) {
|
||||||
// fetch the feed
|
// fetch the feed
|
||||||
$this->resource = self::download($url, $lastModified, $etag, $username, $password);
|
$this->resource = self::download($url, $lastModified, $etag, $username, $password);
|
||||||
|
|
|
@ -150,6 +150,27 @@ class TestFeed extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
Feed::discover($this->base."Discovery/Invalid");
|
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 {
|
public function testParseEntityExpansionAttack(): void {
|
||||||
$this->assertException("xmlEntity", "Feed");
|
$this->assertException("xmlEntity", "Feed");
|
||||||
new Feed(null, $this->base."Parsing/XEEAttack");
|
new Feed(null, $this->base."Parsing/XEEAttack");
|
||||||
|
|
3
tests/docroot/Feed/Discovery/Missing.php
Normal file
3
tests/docroot/Feed/Discovery/Missing.php
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?php return [
|
||||||
|
'code' => 404,
|
||||||
|
];
|
|
@ -4,6 +4,7 @@
|
||||||
<html>
|
<html>
|
||||||
<title>Example article</title>
|
<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/Feed">
|
||||||
|
<link rel="alternate" type="application/rss+xml" href="http://localhost:8000/Feed/Discovery/Missing">
|
||||||
</html>
|
</html>
|
||||||
MESSAGE_BODY
|
MESSAGE_BODY
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue