Browse Source

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

microsub
J. King 7 years ago
parent
commit
3e5343e3e8
  1. 6
      lib/Feed.php
  2. 27
      tests/Feed/TestFeed.php
  3. 29
      tests/docroot/Feed/NextFetch/1h.php
  4. 29
      tests/docroot/Feed/NextFetch/3-36h.php
  5. 29
      tests/docroot/Feed/NextFetch/30m.php
  6. 29
      tests/docroot/Feed/NextFetch/36h.php
  7. 29
      tests/docroot/Feed/NextFetch/3h.php
  8. 29
      tests/docroot/Feed/NextFetch/Fallback.php

6
lib/Feed.php

@ -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]) {

27
tests/Feed/TestFeed.php

@ -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);
}
}

29
tests/docroot/Feed/NextFetch/1h.php

@ -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
];

29
tests/docroot/Feed/NextFetch/3-36h.php

@ -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
];

29
tests/docroot/Feed/NextFetch/30m.php

@ -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
];

29
tests/docroot/Feed/NextFetch/36h.php

@ -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
];

29
tests/docroot/Feed/NextFetch/3h.php

@ -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
];

29
tests/docroot/Feed/NextFetch/Fallback.php

@ -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
];
Loading…
Cancel
Save