mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
More Feed tests: more cache header handling
This commit is contained in:
parent
ceeb23aea3
commit
ed3e3c12d6
11 changed files with 130 additions and 6 deletions
|
@ -153,9 +153,14 @@ class Feed {
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function matchToDatabase(int $feedID): bool {
|
public function matchToDatabase(int $feedID = null): bool {
|
||||||
// first perform deduplication on items
|
// first perform deduplication on items
|
||||||
$items = $this->deduplicateItems($this->data->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
|
// get as many of the latest articles in the database as there are in the feed
|
||||||
$articles = Data::$db->articleMatchLatest($feedID, sizeof($items));
|
$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
|
// arrays holding new, edited, and tentatively new items; items may be tentatively new because we perform two passes
|
||||||
|
|
|
@ -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.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.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.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'
|
||||||
];
|
];
|
|
@ -19,7 +19,8 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
|
||||||
Data::$conf = new Conf();
|
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();
|
$t = time();
|
||||||
$e = "78567a";
|
$e = "78567a";
|
||||||
$f = new Feed(null, $this->base."Caching/304Random", $this->dateTransform($t, "http"), $e);
|
$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->assertTime($t, $f->lastModified);
|
||||||
$this->assertSame($e, $f->resource->getETag());
|
$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() {
|
function testComputeNextFetchOnError() {
|
||||||
for($a = 0; $a < 100; $a++) {
|
for($a = 0; $a < 100; $a++) {
|
||||||
|
|
13
tests/docroot/Feed/Caching/200Future.php
Normal file
13
tests/docroot/Feed/Caching/200Future.php
Normal file
|
@ -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
Normal file
13
tests/docroot/Feed/Caching/200Past.php
Normal file
|
@ -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
Normal file
29
tests/docroot/Feed/Caching/200RSS2Multiple.php
Normal file
|
@ -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
Normal file
18
tests/docroot/Feed/Caching/200RSS2PubDateOnly.php
Normal file
|
@ -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
Normal file
19
tests/docroot/Feed/Caching/200RSS2UpdateDate.php
Normal file
|
@ -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
|
||||||
|
];
|
|
@ -19,7 +19,7 @@
|
||||||
<file>Lang/TestLangComplex.php</file>
|
<file>Lang/TestLangComplex.php</file>
|
||||||
<file>Lang/TestLangErrors.php</file>
|
<file>Lang/TestLangErrors.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="Configuration loading and saving">
|
<testsuite name="Configuration">
|
||||||
<file>Conf/TestConf.php</file>
|
<file>Conf/TestConf.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="User management">
|
<testsuite name="User management">
|
||||||
|
@ -28,13 +28,13 @@
|
||||||
<file>User/TestUserInternalDriver.php</file>
|
<file>User/TestUserInternalDriver.php</file>
|
||||||
<file>User/TestAuthorization.php</file>
|
<file>User/TestAuthorization.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="SQLite3 database driver">
|
<testsuite name="SQLite3 driver">
|
||||||
<file>Db/SQLite3/TestDbResultSQLite3.php</file>
|
<file>Db/SQLite3/TestDbResultSQLite3.php</file>
|
||||||
<file>Db/SQLite3/TestDbStatementSQLite3.php</file>
|
<file>Db/SQLite3/TestDbStatementSQLite3.php</file>
|
||||||
<file>Db/SQLite3/TestDbDriverSQLite3.php</file>
|
<file>Db/SQLite3/TestDbDriverSQLite3.php</file>
|
||||||
<file>Db/SQLite3/TestDbUpdateSQLite3.php</file>
|
<file>Db/SQLite3/TestDbUpdateSQLite3.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="SQLite3 database functions">
|
<testsuite name="SQLite3 functions">
|
||||||
<file>Db/SQLite3/Database/TestDatabaseUserSQLite3.php</file>
|
<file>Db/SQLite3/Database/TestDatabaseUserSQLite3.php</file>
|
||||||
<file>Db/SQLite3/Database/TestDatabaseFolderSQLite3.php</file>
|
<file>Db/SQLite3/Database/TestDatabaseFolderSQLite3.php</file>
|
||||||
<file>Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php</file>
|
<file>Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php</file>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
base=`dirname "$0"`
|
base=`dirname "$0"`
|
||||||
php -n -S localhost:8000 "$base/server.php" >/dev/null &
|
php -n -S localhost:8000 "$base/server.php" >/dev/null &
|
||||||
|
sleep 1s
|
||||||
php "$base/../vendor/phpunit/phpunit/phpunit" -c "$base/phpunit.xml" $*
|
php "$base/../vendor/phpunit/phpunit/phpunit" -c "$base/phpunit.xml" $*
|
||||||
sleep 1s
|
sleep 1s
|
||||||
pid=`lsof -n -i:8000 | grep -Eo "php\s+[0-9]+" | grep -Eo "[0-9]+"`
|
pid=`lsof -n -i:8000 | grep -Eo "php\s+[0-9]+" | grep -Eo "[0-9]+"`
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
setlocal
|
setlocal
|
||||||
set base=%~dp0
|
set base=%~dp0
|
||||||
start /b php -n -S localhost:8000 "%base%\server.php" >nul
|
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" %*
|
php "%base%\..\vendor\phpunit\phpunit\phpunit" -c "%base%\phpunit.xml" %*
|
||||||
timeout /nobreak /t 1 >nul
|
timeout /nobreak /t 1 >nul
|
||||||
for /f "usebackq tokens=5" %%a in (`netstat -aon ^| find "LISTENING" ^| find ":8000"`) do (
|
for /f "usebackq tokens=5" %%a in (`netstat -aon ^| find "LISTENING" ^| find ":8000"`) do (
|
||||||
|
|
Loading…
Reference in a new issue