Browse Source

More Feed tests: more cache header handling

microsub
J. King 7 years ago
parent
commit
ed3e3c12d6
  1. 7
      lib/Feed.php
  2. 2
      locale/en.php
  3. 27
      tests/Feed/TestFeed.php
  4. 13
      tests/docroot/Feed/Caching/200Future.php
  5. 13
      tests/docroot/Feed/Caching/200Past.php
  6. 29
      tests/docroot/Feed/Caching/200RSS2Multiple.php
  7. 18
      tests/docroot/Feed/Caching/200RSS2PubDateOnly.php
  8. 19
      tests/docroot/Feed/Caching/200RSS2UpdateDate.php
  9. 6
      tests/phpunit.xml
  10. 1
      tests/test
  11. 1
      tests/test.bat

7
lib/Feed.php

@ -153,9 +153,14 @@ class Feed {
return $out;
}
public function matchToDatabase(int $feedID): bool {
public function matchToDatabase(int $feedID = null): bool {
// first perform deduplication on items
$items = $this->deduplicateItems($this->data->items);
// if we haven't been given a database feed ID to check against, all items are new
if(is_null($feedID)) {
$this->newItems = $items;
return true;
}
// get as many of the latest articles in the database as there are in the feed
$articles = Data::$db->articleMatchLatest($feedID, sizeof($items));
// arrays holding new, edited, and tentatively new items; items may be tentatively new because we perform two passes

2
locale/en.php

@ -96,5 +96,5 @@ return [
'Exception.JKingWeb/Arsse/Feed/Exception.malformed' => 'Could not parse feed "{url}" because it is malformed',
'Exception.JKingWeb/Arsse/Feed/Exception.xmlEntity' => 'Refused to parse feed "{url}" because it contains an XXE attack',
'Exception.JKingWeb/Arsse/Feed/Exception.subscriptionNotFound' => 'Unable to find a feed at location "{url}"',
'Exception.JKingWeb/Arsse/Feed/Exception.unsupportedFormat' => 'Feed "{url}" is of an unsupported format'
'Exception.JKingWeb/Arsse/Feed/Exception.unsupportedFeedFormat' => 'Feed "{url}" is of an unsupported format'
];

27
tests/Feed/TestFeed.php

@ -19,7 +19,8 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
Data::$conf = new Conf();
}
function testHandleCacheHeaders() {
function testHandleCacheHeadersOn304() {
// upon 304, the client should re-use the caching header values it supplied the server
$t = time();
$e = "78567a";
$f = new Feed(null, $this->base."Caching/304Random", $this->dateTransform($t, "http"), $e);
@ -35,6 +36,30 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
$this->assertTime($t, $f->lastModified);
$this->assertSame($e, $f->resource->getETag());
}
function testHandleCacheHeadersOn200() {
// these tests should trust the server-returned time, even in cases of obviously incorrect results
$t = time() - 2000;
$f = new Feed(null, $this->base."Caching/200Past");
$this->assertTime($t, $f->lastModified);
$this->assertNotEmpty($f->resource->getETag());
$t = time() - 2000;
$f = new Feed(null, $this->base."Caching/200Past", $this->dateTransform(time(), "http"));
$this->assertTime($t, $f->lastModified);
$this->assertNotEmpty($f->resource->getETag());
$t = time() + 2000;
$f = new Feed(null, $this->base."Caching/200Future");
$this->assertTime($t, $f->lastModified);
$this->assertNotEmpty($f->resource->getETag());
// these tests have no HTTP headers and rely on article dates
$t = strtotime("2002-05-19T15:21:36Z");
$f = new Feed(null, $this->base."Caching/200RSS2PubDateOnly");
$this->assertTime($t, $f->lastModified);
$f = new Feed(null, $this->base."Caching/200RSS2UpdateDate");
$this->assertTime($t, $f->lastModified);
$f = new Feed(null, $this->base."Caching/200RSS2Multiple");
$this->assertTime($t, $f->lastModified);
}
function testComputeNextFetchOnError() {
for($a = 0; $a < 100; $a++) {

13
tests/docroot/Feed/Caching/200Future.php

@ -0,0 +1,13 @@
<?php return [
'code' => 200,
'lastMod' => time() + 2000,
'content' => <<<MESSAGE_BODY
<rss version="2.0">
<channel>
<title>Test feed</title>
<link>http://example.com/</link>
<description>A basic feed for testing</description>
</channel>
</rss>
MESSAGE_BODY
];

13
tests/docroot/Feed/Caching/200Past.php

@ -0,0 +1,13 @@
<?php return [
'code' => 200,
'lastMod' => time() - 2000,
'content' => <<<MESSAGE_BODY
<rss version="2.0">
<channel>
<title>Test feed</title>
<link>http://example.com/</link>
<description>A basic feed for testing</description>
</channel>
</rss>
MESSAGE_BODY
];

29
tests/docroot/Feed/Caching/200RSS2Multiple.php

@ -0,0 +1,29 @@
<?php return [
'code' => 200,
'cache' => false,
'content' => <<<MESSAGE_BODY
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Test feed</title>
<link>http://example.com/</link>
<description>A basic feed for testing</description>
<item>
<description>Sample article 1</description>
<pubDate>Sun, 18 May 1995 15:21:36 GMT</pubDate>
<atom:updated>2002-02-19T15:21:36Z</atom:updated>
</item>
<item>
<description>Sample article 2</description>
<pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate>
<atom:updated>2002-04-19T15:21:36Z</atom:updated>
</item>
<item>
<description>Sample article 3</description>
<pubDate>Sun, 18 May 2000 15:21:36 GMT</pubDate>
<atom:updated>1999-05-19T15:21:36Z</atom:updated>
</item>
</channel>
</rss>
MESSAGE_BODY
];

18
tests/docroot/Feed/Caching/200RSS2PubDateOnly.php

@ -0,0 +1,18 @@
<?php return [
'code' => 200,
'cache' => false,
'content' => <<<MESSAGE_BODY
<rss version="2.0">
<channel>
<title>Test feed</title>
<link>http://example.com/</link>
<description>A basic feed for testing</description>
<item>
<description>Sample article</description>
<pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate>
</item>
</channel>
</rss>
MESSAGE_BODY
];

19
tests/docroot/Feed/Caching/200RSS2UpdateDate.php

@ -0,0 +1,19 @@
<?php return [
'code' => 200,
'cache' => false,
'content' => <<<MESSAGE_BODY
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Test feed</title>
<link>http://example.com/</link>
<description>A basic feed for testing</description>
<item>
<description>Sample article</description>
<pubDate>Sun, 18 May 2002 15:21:36 GMT</pubDate>
<atom:updated>2002-05-19T15:21:36Z</atom:updated>
</item>
</channel>
</rss>
MESSAGE_BODY
];

6
tests/phpunit.xml

@ -19,7 +19,7 @@
<file>Lang/TestLangComplex.php</file>
<file>Lang/TestLangErrors.php</file>
</testsuite>
<testsuite name="Configuration loading and saving">
<testsuite name="Configuration">
<file>Conf/TestConf.php</file>
</testsuite>
<testsuite name="User management">
@ -28,13 +28,13 @@
<file>User/TestUserInternalDriver.php</file>
<file>User/TestAuthorization.php</file>
</testsuite>
<testsuite name="SQLite3 database driver">
<testsuite name="SQLite3 driver">
<file>Db/SQLite3/TestDbResultSQLite3.php</file>
<file>Db/SQLite3/TestDbStatementSQLite3.php</file>
<file>Db/SQLite3/TestDbDriverSQLite3.php</file>
<file>Db/SQLite3/TestDbUpdateSQLite3.php</file>
</testsuite>
<testsuite name="SQLite3 database functions">
<testsuite name="SQLite3 functions">
<file>Db/SQLite3/Database/TestDatabaseUserSQLite3.php</file>
<file>Db/SQLite3/Database/TestDatabaseFolderSQLite3.php</file>
<file>Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php</file>

1
tests/test

@ -1,6 +1,7 @@
#! /bin/sh
base=`dirname "$0"`
php -n -S localhost:8000 "$base/server.php" >/dev/null &
sleep 1s
php "$base/../vendor/phpunit/phpunit/phpunit" -c "$base/phpunit.xml" $*
sleep 1s
pid=`lsof -n -i:8000 | grep -Eo "php\s+[0-9]+" | grep -Eo "[0-9]+"`

1
tests/test.bat

@ -2,6 +2,7 @@
setlocal
set base=%~dp0
start /b php -n -S localhost:8000 "%base%\server.php" >nul
timeout /nobreak /t 1 >nul
php "%base%\..\vendor\phpunit\phpunit\phpunit" -c "%base%\phpunit.xml" %*
timeout /nobreak /t 1 >nul
for /f "usebackq tokens=5" %%a in (`netstat -aon ^| find "LISTENING" ^| find ":8000"`) do (

Loading…
Cancel
Save