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

Feed tests: last set of next-fetch tests, with fixes

This commit is contained in:
J. King 2017-05-27 23:14:43 -04:00
parent 4d8def4bfd
commit 3e5343e3e8
8 changed files with 206 additions and 1 deletions

View file

@ -287,11 +287,15 @@ class Feed {
$offset = $this->normalizeDateDiff($diff);
$now->modify("+".$offset);
} else {
// the algorithm for updated feeds (returning 200 rather than 304) uses the same parameters as for 304,
// save that the last three intervals between item dates are computed, and if any two fall within
// the same interval range, that interval is used (e.g. if the intervals are 23m, 12m, and 4h, the used
// interval is "less than 30m"). If there is no commonality, the feed is checked in 1 hour.
$offsets = [];
$dates = $this->gatherDates();
if(sizeof($dates) > 3) {
for($a = 0; $a < 3; $a++) {
$diff = $dates[$a+1] - $dates[$a];
$diff = $dates[$a] - $dates[$a+1];
$offsets[] = $this->normalizeDateDiff($diff);
}
if($offsets[0]==$offsets[1] || $offsets[0]==$offsets[2]) {

View file

@ -251,4 +251,31 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
$exp = strtotime("now + 3 hours");
$this->assertTime($exp, $f->nextFetch);
}
function testComputeNextFetchFrom200() {
// if less than half an hour, check in 15 minutes
$f = new Feed(null, $this->base."NextFetch/30m");
$exp = strtotime("now + 15 minutes");
$this->assertTime($exp, $f->nextFetch);
// if less than an hour, check in 30 minutes
$f = new Feed(null, $this->base."NextFetch/1h");
$exp = strtotime("now + 30 minutes");
$this->assertTime($exp, $f->nextFetch);
// if less than three hours, check in an hour
$f = new Feed(null, $this->base."NextFetch/3h");
$exp = strtotime("now + 1 hour");
$this->assertTime($exp, $f->nextFetch);
// if more than 36 hours, check in 24 hours
$f = new Feed(null, $this->base."NextFetch/36h");
$exp = strtotime("now + 24 hours");
$this->assertTime($exp, $f->nextFetch);
// otherwise check in three hours
$f = new Feed(null, $this->base."NextFetch/3-36h");
$exp = strtotime("now + 3 hours");
$this->assertTime($exp, $f->nextFetch);
// and if there is no common interval, check in an hour
$f = new Feed(null, $this->base."NextFetch/Fallback");
$exp = strtotime("now + 1 hour");
$this->assertTime($exp, $f->nextFetch);
}
}

View file

@ -0,0 +1,29 @@
<?php return [
'mime' => "application/rss+xml",
'content' => <<<MESSAGE_BODY
<rss version="2.0">
<channel>
<title>Example title</title>
<link>http://example.com</link>
<description>Example description</description>
<item>
<pubDate>Sat, 27 May 2017 22:02:00 GMT</pubDate>
<guid>http://example.com/1</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 21:12:00 GMT</pubDate>
<guid>http://example.com/2</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 22:00:00 GMT</pubDate>
<guid>http://example.com/3</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 20:21:00 GMT</pubDate>
<guid>http://example.com/4</guid>
</item>
</channel>
</rss>
MESSAGE_BODY
];

View file

@ -0,0 +1,29 @@
<?php return [
'mime' => "application/rss+xml",
'content' => <<<MESSAGE_BODY
<rss version="2.0">
<channel>
<title>Example title</title>
<link>http://example.com</link>
<description>Example description</description>
<item>
<pubDate>Sat, 27 May 2017 07:00:00 GMT</pubDate>
<guid>http://example.com/1</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 12:00:00 GMT</pubDate>
<guid>http://example.com/2</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 16:00:00 GMT</pubDate>
<guid>http://example.com/3</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 21:12:00 GMT</pubDate>
<guid>http://example.com/4</guid>
</item>
</channel>
</rss>
MESSAGE_BODY
];

View file

@ -0,0 +1,29 @@
<?php return [
'mime' => "application/rss+xml",
'content' => <<<MESSAGE_BODY
<rss version="2.0">
<channel>
<title>Example title</title>
<link>http://example.com</link>
<description>Example description</description>
<item>
<pubDate>Sat, 27 May 2017 11:00:00 GMT</pubDate>
<guid>http://example.com/1</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 21:12:00 GMT</pubDate>
<guid>http://example.com/2</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 22:00:00 GMT</pubDate>
<guid>http://example.com/3</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 21:31:00 GMT</pubDate>
<guid>http://example.com/4</guid>
</item>
</channel>
</rss>
MESSAGE_BODY
];

View file

@ -0,0 +1,29 @@
<?php return [
'mime' => "application/rss+xml",
'content' => <<<MESSAGE_BODY
<rss version="2.0">
<channel>
<title>Example title</title>
<link>http://example.com</link>
<description>Example description</description>
<item>
<pubDate>Mon, 22 May 2017 07:00:00 GMT</pubDate>
<guid>http://example.com/1</guid>
</item>
<item>
<pubDate>Wed, 24 May 2017 12:00:00 GMT</pubDate>
<guid>http://example.com/2</guid>
</item>
<item>
<pubDate>Fri, 26 May 2017 16:00:00 GMT</pubDate>
<guid>http://example.com/3</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 21:12:00 GMT</pubDate>
<guid>http://example.com/4</guid>
</item>
</channel>
</rss>
MESSAGE_BODY
];

View file

@ -0,0 +1,29 @@
<?php return [
'mime' => "application/rss+xml",
'content' => <<<MESSAGE_BODY
<rss version="2.0">
<channel>
<title>Example title</title>
<link>http://example.com</link>
<description>Example description</description>
<item>
<pubDate>Sat, 27 May 2017 07:00:00 GMT</pubDate>
<guid>http://example.com/1</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 09:12:00 GMT</pubDate>
<guid>http://example.com/2</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 12:00:00 GMT</pubDate>
<guid>http://example.com/3</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 21:12:00 GMT</pubDate>
<guid>http://example.com/4</guid>
</item>
</channel>
</rss>
MESSAGE_BODY
];

View file

@ -0,0 +1,29 @@
<?php return [
'mime' => "application/rss+xml",
'content' => <<<MESSAGE_BODY
<rss version="2.0">
<channel>
<title>Example title</title>
<link>http://example.com</link>
<description>Example description</description>
<item>
<pubDate>Sat, 27 May 2017 11:00:00 GMT</pubDate>
<guid>http://example.com/1</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 21:12:00 GMT</pubDate>
<guid>http://example.com/2</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 21:20:00 GMT</pubDate>
<guid>http://example.com/3</guid>
</item>
<item>
<pubDate>Sat, 27 May 2017 22:10:00 GMT</pubDate>
<guid>http://example.com/4</guid>
</item>
</channel>
</rss>
MESSAGE_BODY
];