mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 05:54:55 +00:00
Partially working cleanup tests
This commit is contained in:
parent
c139f52ebc
commit
16af57cf90
7 changed files with 50 additions and 57 deletions
|
@ -1461,7 +1461,7 @@ class Database {
|
||||||
// first unmark any icons which are no longer orphaned; an icon is considered orphaned if it is not used or only used by feeds which are themselves orphaned
|
// first unmark any icons which are no longer orphaned; an icon is considered orphaned if it is not used or only used by feeds which are themselves orphaned
|
||||||
$this->db->query("UPDATE arsse_icons set orphaned = null where id in (select distinct icon from arsse_subscriptions where icon is not null and deleted = 0)");
|
$this->db->query("UPDATE arsse_icons set orphaned = null where id in (select distinct icon from arsse_subscriptions where icon is not null and deleted = 0)");
|
||||||
// next mark any newly orphaned icons with the current date and time
|
// next mark any newly orphaned icons with the current date and time
|
||||||
$this->db->query("UPDATE arsse_icons set orphaned = CURRENT_TIMESTAMP where orphaned is null and id not in (select distinct icon from arsse_subscriptions where icon is not null and delete = 0)");
|
$this->db->query("UPDATE arsse_icons set orphaned = CURRENT_TIMESTAMP where orphaned is null and id not in (select distinct icon from arsse_subscriptions where icon is not null and deleted = 0)");
|
||||||
// finally delete icons that have been orphaned longer than the feed retention period, if a a purge threshold has been specified
|
// finally delete icons that have been orphaned longer than the feed retention period, if a a purge threshold has been specified
|
||||||
$out = 0;
|
$out = 0;
|
||||||
if (Arsse::$conf->purgeFeeds) {
|
if (Arsse::$conf->purgeFeeds) {
|
||||||
|
|
|
@ -89,8 +89,8 @@ class Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function cleanupPre(): bool {
|
public static function cleanupPre(): bool {
|
||||||
// mark unsubscribed feeds as orphaned and delete orphaned feeds that are beyond their retention period
|
// delete soft-deleted subscriptions that are beyond their retention period
|
||||||
Arsse::$db->feedCleanup();
|
Arsse::$db->subscriptionCleanup();
|
||||||
// do the same for icons
|
// do the same for icons
|
||||||
Arsse::$db->iconCleanup();
|
Arsse::$db->iconCleanup();
|
||||||
// delete expired log-in sessions
|
// delete expired log-in sessions
|
||||||
|
|
|
@ -23,7 +23,7 @@ abstract class AbstractTest extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
use SeriesLabel;
|
use SeriesLabel;
|
||||||
use SeriesTag;
|
use SeriesTag;
|
||||||
use SeriesArticle;
|
use SeriesArticle;
|
||||||
//use SeriesCleanup;
|
use SeriesCleanup;
|
||||||
|
|
||||||
/** @var \JKingWeb\Arsse\Db\Driver */
|
/** @var \JKingWeb\Arsse\Db\Driver */
|
||||||
protected static $drv;
|
protected static $drv;
|
||||||
|
|
|
@ -62,15 +62,6 @@ trait SeriesCleanup {
|
||||||
[3,'http://localhost:8000/Icon/SVG1',null],
|
[3,'http://localhost:8000/Icon/SVG1',null],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'arsse_feeds' => [
|
|
||||||
'columns' => ["id", "url", "title", "orphaned", "size", "icon"],
|
|
||||||
'rows' => [
|
|
||||||
[1,"http://example.com/1","",$daybefore,2,null], //latest two articles should be kept
|
|
||||||
[2,"http://example.com/2","",$yesterday,0,2],
|
|
||||||
[3,"http://example.com/3","",null,0,1],
|
|
||||||
[4,"http://example.com/4","",$nowish,0,null],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'arsse_subscriptions' => [
|
'arsse_subscriptions' => [
|
||||||
'columns' => ["id", "owner", "url", "size", "icon", "deleted", "modified"],
|
'columns' => ["id", "owner", "url", "size", "icon", "deleted", "modified"],
|
||||||
'rows' => [
|
'rows' => [
|
||||||
|
@ -79,21 +70,31 @@ trait SeriesCleanup {
|
||||||
[2,'john.doe@example.com',"http://example.com/1",2,null,0,$daybefore],
|
[2,'john.doe@example.com',"http://example.com/1",2,null,0,$daybefore],
|
||||||
// the other subscriptions are used for subscription cleanup
|
// the other subscriptions are used for subscription cleanup
|
||||||
[3,'jane.doe@example.com',"http://example.com/2",0, 2,1,$yesterday],
|
[3,'jane.doe@example.com',"http://example.com/2",0, 2,1,$yesterday],
|
||||||
|
[4,'jane.doe@example.com',"http://example.com/4",0, 1,1,$nowish],
|
||||||
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'arsse_articles' => [
|
'arsse_articles' => [
|
||||||
'columns' => ["id", "subscription", "url_title_hash", "url_content_hash", "title_content_hash", "modified"],
|
'columns' => ["id", "subscription", "url_title_hash", "url_content_hash", "title_content_hash", "modified", "read", "starred", "hidden", "marked"],
|
||||||
'rows' => [
|
'rows' => [
|
||||||
[1,1,"","","",$weeksago], // is the latest article, thus is kept
|
[ 1,1,"","","",$weeksago,0,0,0,null], // is the latest article, thus is kept
|
||||||
[2,1,"","","",$weeksago], // is the second latest article, thus is kept
|
[ 2,1,"","","",$weeksago,0,0,0,null], // is the second latest article, thus is kept
|
||||||
[3,1,"","","",$weeksago], // is starred by one user, thus is kept
|
[ 3,1,"","","",$weeksago,0,1,0,$weeksago], // is starred by the user, thus is kept
|
||||||
[4,1,"","","",$weeksago], // does not meet the unread threshold due to a recent mark, thus is kept
|
[ 4,1,"","","",$weeksago,1,0,0,$daysago], // does not meet the unread threshold due to a recent mark, thus is kept
|
||||||
[5,1,"","","",$daysago], // does not meet the unread threshold due to age, thus is kept
|
[ 5,1,"","","",$daysago, 0,0,0,null], // does not meet the unread threshold due to age, thus is kept
|
||||||
[6,1,"","","",$weeksago], // does not meet the read threshold due to a recent mark, thus is kept
|
[ 6,1,"","","",$weeksago,1,0,0,$nowish], // does not meet the read threshold due to a recent mark, thus is kept
|
||||||
[7,1,"","","",$weeksago], // meets the unread threshold without marks, thus is deleted
|
[ 7,1,"","","",$weeksago,0,0,0,null], // meets the unread threshold without marks, thus is deleted
|
||||||
[8,1,"","","",$weeksago], // meets the unread threshold even with marks, thus is deleted
|
[ 8,1,"","","",$weeksago,1,0,0,$weeksago], // meets the unread threshold even with marks, thus is deleted
|
||||||
[9,1,"","","",$weeksago], // meets the read threshold, thus is deleted
|
[ 9,1,"","","",$weeksago,1,0,0,$daysago], // meets the read threshold, thus is deleted
|
||||||
|
[1001,2,"","","",$weeksago,0,0,0,null], // is the latest article, thus is kept
|
||||||
|
[1002,2,"","","",$weeksago,0,0,0,null], // is the second latest article, thus is kept
|
||||||
|
[1003,2,"","","",$weeksago,0,0,0,null], // meets the unread threshold without marks, thus is deleted
|
||||||
|
[1004,2,"","","",$weeksago,0,0,0,null], // meets the unread threshold without marks, thus is deleted
|
||||||
|
[1005,2,"","","",$daysago, 0,0,0,null], // does not meet the unread threshold due to age, thus is kept
|
||||||
|
[1006,2,"","","",$weeksago,1,0,0,$weeksago], // meets the unread threshold even with marks, thus is deleted
|
||||||
|
[1007,2,"","","",$weeksago,0,1,1,$weeksago], // hidden overrides starred, thus is deleted
|
||||||
|
[1008,2,"","","",$weeksago,0,0,0,null], // meets the unread threshold without marks, thus is deleted
|
||||||
|
[1009,2,"","","",$weeksago,0,0,1,$daysago], // meets the read threshold because hidden is equivalent to read, thus is deleted
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'arsse_editions' => [
|
'arsse_editions' => [
|
||||||
|
@ -110,19 +111,17 @@ trait SeriesCleanup {
|
||||||
[9,9],
|
[9,9],
|
||||||
[201,1],
|
[201,1],
|
||||||
[102,2],
|
[102,2],
|
||||||
],
|
[1001,1001],
|
||||||
],
|
[1002,1002],
|
||||||
'arsse_marks' => [
|
[1003,1003],
|
||||||
'columns' => ["article", "subscription", "read", "starred", "hidden", "modified"],
|
[1004,1004],
|
||||||
'rows' => [
|
[1005,1005],
|
||||||
[3,1,0,1,0,$weeksago],
|
[1006,1006],
|
||||||
[4,1,1,0,0,$daysago],
|
[1007,1007],
|
||||||
[6,1,1,0,0,$nowish],
|
[1008,1008],
|
||||||
[6,2,1,0,0,$weeksago],
|
[1009,1009],
|
||||||
[7,2,0,1,1,$weeksago], // hidden takes precedence over starred
|
[1201,1001],
|
||||||
[8,1,1,0,0,$weeksago],
|
[1102,1002],
|
||||||
[9,1,1,0,0,$daysago],
|
|
||||||
[9,2,0,0,1,$daysago], // hidden is the same as read for the purposes of cleanup
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
@ -134,13 +133,10 @@ trait SeriesCleanup {
|
||||||
|
|
||||||
public function testCleanUpDeletedSubscriptions(): void {
|
public function testCleanUpDeletedSubscriptions(): void {
|
||||||
Arsse::$db->subscriptionCleanup();
|
Arsse::$db->subscriptionCleanup();
|
||||||
$now = gmdate("Y-m-d H:i:s");
|
|
||||||
$state = $this->primeExpectations($this->data, [
|
$state = $this->primeExpectations($this->data, [
|
||||||
'arsse_feeds' => ["id","orphaned"],
|
'arsse_subscriptions' => ["id"],
|
||||||
]);
|
]);
|
||||||
$state['arsse_feeds']['rows'][0][1] = null;
|
unset($state['arsse_subscriptions']['rows'][2]);
|
||||||
unset($state['arsse_feeds']['rows'][1]);
|
|
||||||
$state['arsse_feeds']['rows'][2][1] = $now;
|
|
||||||
$this->compareExpectations(static::$drv, $state);
|
$this->compareExpectations(static::$drv, $state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,12 +145,9 @@ trait SeriesCleanup {
|
||||||
'purgeFeeds' => null,
|
'purgeFeeds' => null,
|
||||||
]);
|
]);
|
||||||
Arsse::$db->subscriptionCleanup();
|
Arsse::$db->subscriptionCleanup();
|
||||||
$now = gmdate("Y-m-d H:i:s");
|
|
||||||
$state = $this->primeExpectations($this->data, [
|
$state = $this->primeExpectations($this->data, [
|
||||||
'arsse_feeds' => ["id","orphaned"],
|
'arsse_subscriptions' => ["id"],
|
||||||
]);
|
]);
|
||||||
$state['arsse_feeds']['rows'][0][1] = null;
|
|
||||||
$state['arsse_feeds']['rows'][2][1] = $now;
|
|
||||||
$this->compareExpectations(static::$drv, $state);
|
$this->compareExpectations(static::$drv, $state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -858,17 +858,17 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCleanUpBeforeUpdate(): void {
|
public function testCleanUpBeforeUpdate(): void {
|
||||||
$this->dbMock->feedCleanup->with()->returns(true);
|
$this->dbMock->subscriptionCleanup->with()->returns(true);
|
||||||
$exp = HTTP::respEmpty(204);
|
$exp = HTTP::respEmpty(204);
|
||||||
$this->assertMessage($exp, $this->req("GET", "/cleanup/before-update"));
|
$this->assertMessage($exp, $this->req("GET", "/cleanup/before-update"));
|
||||||
$this->dbMock->feedCleanup->calledWith();
|
$this->dbMock->subscriptionCleanup->calledWith();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCleanUpBeforeUpdateWithoutAuthority(): void {
|
public function testCleanUpBeforeUpdateWithoutAuthority(): void {
|
||||||
$this->userMock->propertiesGet->returns(['admin' => false]);
|
$this->userMock->propertiesGet->returns(['admin' => false]);
|
||||||
$exp = HTTP::respEmpty(403);
|
$exp = HTTP::respEmpty(403);
|
||||||
$this->assertMessage($exp, $this->req("GET", "/cleanup/before-update"));
|
$this->assertMessage($exp, $this->req("GET", "/cleanup/before-update"));
|
||||||
$this->dbMock->feedCleanup->never()->called();
|
$this->dbMock->subscriptionCleanup->never()->called();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCleanUpAfterUpdate(): void {
|
public function testCleanUpAfterUpdate(): void {
|
||||||
|
@ -882,7 +882,7 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$this->userMock->propertiesGet->returns(['admin' => false]);
|
$this->userMock->propertiesGet->returns(['admin' => false]);
|
||||||
$exp = HTTP::respEmpty(403);
|
$exp = HTTP::respEmpty(403);
|
||||||
$this->assertMessage($exp, $this->req("GET", "/cleanup/after-update"));
|
$this->assertMessage($exp, $this->req("GET", "/cleanup/after-update"));
|
||||||
$this->dbMock->feedCleanup->never()->called();
|
$this->dbMock->subscriptionCleanup->never()->called();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueryTheUserStatus(): void {
|
public function testQueryTheUserStatus(): void {
|
||||||
|
|
|
@ -45,7 +45,7 @@ class TestService extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
|
|
||||||
public function testPerformPreCleanup(): void {
|
public function testPerformPreCleanup(): void {
|
||||||
$this->assertTrue(Service::cleanupPre());
|
$this->assertTrue(Service::cleanupPre());
|
||||||
$this->dbMock->feedCleanup->called();
|
$this->dbMock->subscriptionCleanup->called();
|
||||||
$this->dbMock->iconCleanup->called();
|
$this->dbMock->iconCleanup->called();
|
||||||
$this->dbMock->sessionCleanup->called();
|
$this->dbMock->sessionCleanup->called();
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ class TestService extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
public function testRefreshFeeds(): void {
|
public function testRefreshFeeds(): void {
|
||||||
// set up mock database actions
|
// set up mock database actions
|
||||||
$this->dbMock->metaSet->returns(true);
|
$this->dbMock->metaSet->returns(true);
|
||||||
$this->dbMock->feedCleanup->returns(true);
|
$this->dbMock->subscriptionCleanup->returns(true);
|
||||||
$this->dbMock->sessionCleanup->returns(true);
|
$this->dbMock->sessionCleanup->returns(true);
|
||||||
$this->dbMock->articleCleanup->returns(0);
|
$this->dbMock->articleCleanup->returns(0);
|
||||||
$this->dbMock->feedListStale->returns([1,2,3]);
|
$this->dbMock->feedListStale->returns([1,2,3]);
|
||||||
|
@ -82,7 +82,7 @@ class TestService extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
$d->queue->calledWith(1, 2, 3);
|
$d->queue->calledWith(1, 2, 3);
|
||||||
$d->exec->called();
|
$d->exec->called();
|
||||||
$d->clean->called();
|
$d->clean->called();
|
||||||
$this->dbMock->feedCleanup->called();
|
$this->dbMock->subscriptionCleanup->called();
|
||||||
$this->dbMock->iconCleanup->called();
|
$this->dbMock->iconCleanup->called();
|
||||||
$this->dbMock->sessionCleanup->called();
|
$this->dbMock->sessionCleanup->called();
|
||||||
$this->dbMock->articleCleanup->called();
|
$this->dbMock->articleCleanup->called();
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
<file>cases/Db/SQLite3/TestCreation.php</file>
|
<file>cases/Db/SQLite3/TestCreation.php</file>
|
||||||
<file>cases/Db/SQLite3/TestDriver.php</file>
|
<file>cases/Db/SQLite3/TestDriver.php</file>
|
||||||
<file>cases/Db/SQLite3/TestUpdate.php</file>
|
<file>cases/Db/SQLite3/TestUpdate.php</file>
|
||||||
<!--<file>cases/Db/SQLite3/TestDatabase.php</file>-->
|
<file>cases/Db/SQLite3/TestDatabase.php</file>
|
||||||
<file>cases/Db/SQLite3PDO/TestResult.php</file>
|
<file>cases/Db/SQLite3PDO/TestResult.php</file>
|
||||||
<file>cases/Db/SQLite3PDO/TestStatement.php</file>
|
<file>cases/Db/SQLite3PDO/TestStatement.php</file>
|
||||||
<file>cases/Db/SQLite3PDO/TestCreation.php</file>
|
<file>cases/Db/SQLite3PDO/TestCreation.php</file>
|
||||||
|
@ -89,13 +89,13 @@
|
||||||
<file>cases/Db/PostgreSQL/TestCreation.php</file>
|
<file>cases/Db/PostgreSQL/TestCreation.php</file>
|
||||||
<file>cases/Db/PostgreSQL/TestDriver.php</file>
|
<file>cases/Db/PostgreSQL/TestDriver.php</file>
|
||||||
<file>cases/Db/PostgreSQL/TestUpdate.php</file>
|
<file>cases/Db/PostgreSQL/TestUpdate.php</file>
|
||||||
<!--<file>cases/Db/PostgreSQL/TestDatabase.php</file>-->
|
<file>cases/Db/PostgreSQL/TestDatabase.php</file>
|
||||||
<file>cases/Db/PostgreSQLPDO/TestResult.php</file>
|
<file>cases/Db/PostgreSQLPDO/TestResult.php</file>
|
||||||
<file>cases/Db/PostgreSQLPDO/TestStatement.php</file>
|
<file>cases/Db/PostgreSQLPDO/TestStatement.php</file>
|
||||||
<file>cases/Db/PostgreSQLPDO/TestCreation.php</file>
|
<file>cases/Db/PostgreSQLPDO/TestCreation.php</file>
|
||||||
<file>cases/Db/PostgreSQLPDO/TestDriver.php</file>
|
<file>cases/Db/PostgreSQLPDO/TestDriver.php</file>
|
||||||
<file>cases/Db/PostgreSQLPDO/TestUpdate.php</file>
|
<file>cases/Db/PostgreSQLPDO/TestUpdate.php</file>
|
||||||
<!--<file>cases/Db/PostgreSQLPDO/TestDatabase.php</file>-->
|
<file>cases/Db/PostgreSQLPDO/TestDatabase.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="MySQL">
|
<testsuite name="MySQL">
|
||||||
<file>cases/Db/MySQL/TestResult.php</file>
|
<file>cases/Db/MySQL/TestResult.php</file>
|
||||||
|
@ -103,13 +103,13 @@
|
||||||
<file>cases/Db/MySQL/TestCreation.php</file>
|
<file>cases/Db/MySQL/TestCreation.php</file>
|
||||||
<file>cases/Db/MySQL/TestDriver.php</file>
|
<file>cases/Db/MySQL/TestDriver.php</file>
|
||||||
<file>cases/Db/MySQL/TestUpdate.php</file>
|
<file>cases/Db/MySQL/TestUpdate.php</file>
|
||||||
<!--<file>cases/Db/MySQL/TestDatabase.php</file>-->
|
<file>cases/Db/MySQL/TestDatabase.php</file>
|
||||||
<file>cases/Db/MySQLPDO/TestResult.php</file>
|
<file>cases/Db/MySQLPDO/TestResult.php</file>
|
||||||
<file>cases/Db/MySQLPDO/TestStatement.php</file>
|
<file>cases/Db/MySQLPDO/TestStatement.php</file>
|
||||||
<file>cases/Db/MySQLPDO/TestCreation.php</file>
|
<file>cases/Db/MySQLPDO/TestCreation.php</file>
|
||||||
<file>cases/Db/MySQLPDO/TestDriver.php</file>
|
<file>cases/Db/MySQLPDO/TestDriver.php</file>
|
||||||
<file>cases/Db/MySQLPDO/TestUpdate.php</file>
|
<file>cases/Db/MySQLPDO/TestUpdate.php</file>
|
||||||
<!--<file>cases/Db/MySQLPDO/TestDatabase.php</file>-->
|
<file>cases/Db/MySQLPDO/TestDatabase.php</file>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="REST">
|
<testsuite name="REST">
|
||||||
<file>cases/REST/TestREST.php</file>
|
<file>cases/REST/TestREST.php</file>
|
||||||
|
|
Loading…
Reference in a new issue