2017-08-18 02:36:15 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-08-18 02:36:15 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\Test\Database;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2017-08-18 02:36:15 +00:00
|
|
|
use JKingWeb\Arsse\Arsse;
|
|
|
|
use Phake;
|
|
|
|
|
|
|
|
trait SeriesCleanup {
|
2017-08-29 14:50:31 +00:00
|
|
|
public function setUpSeries() {
|
2017-08-18 02:36:15 +00:00
|
|
|
// set up the test data
|
2017-08-29 14:50:31 +00:00
|
|
|
$nowish = gmdate("Y-m-d H:i:s", strtotime("now - 1 minute"));
|
|
|
|
$yesterday = gmdate("Y-m-d H:i:s", strtotime("now - 1 day"));
|
|
|
|
$daybefore = gmdate("Y-m-d H:i:s", strtotime("now - 2 days"));
|
|
|
|
$daysago = gmdate("Y-m-d H:i:s", strtotime("now - 7 days"));
|
|
|
|
$weeksago = gmdate("Y-m-d H:i:s", strtotime("now - 21 days"));
|
2017-09-24 16:45:07 +00:00
|
|
|
$soon = gmdate("Y-m-d H:i:s", strtotime("now + 1 minute"));
|
|
|
|
$faroff = gmdate("Y-m-d H:i:s", strtotime("now + 1 hour"));
|
2017-08-18 02:36:15 +00:00
|
|
|
$this->data = [
|
|
|
|
'arsse_users' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => 'str',
|
|
|
|
'password' => 'str',
|
|
|
|
'name' => 'str',
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
["jane.doe@example.com", "", "Jane Doe"],
|
|
|
|
["john.doe@example.com", "", "John Doe"],
|
|
|
|
],
|
|
|
|
],
|
2017-09-24 16:45:07 +00:00
|
|
|
'arsse_sessions' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => "str",
|
|
|
|
'created' => "datetime",
|
|
|
|
'expires' => "datetime",
|
|
|
|
'user' => "str",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
["a", $nowish, $faroff, "jane.doe@example.com"], // not expired and recently created, thus kept
|
|
|
|
["b", $nowish, $soon, "jane.doe@example.com"], // not expired and recently created, thus kept
|
|
|
|
["c", $daysago, $soon, "jane.doe@example.com"], // created more than a day ago, thus deleted
|
|
|
|
["d", $nowish, $nowish, "jane.doe@example.com"], // recently created but expired, thus deleted
|
|
|
|
["e", $daysago, $nowish, "jane.doe@example.com"], // created more than a day ago and expired, thus deleted
|
|
|
|
],
|
|
|
|
],
|
2017-08-18 02:36:15 +00:00
|
|
|
'arsse_feeds' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => "int",
|
|
|
|
'url' => "str",
|
|
|
|
'title' => "str",
|
|
|
|
'orphaned' => "datetime",
|
|
|
|
'size' => "int",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
[1,"http://example.com/1","",$daybefore,2], //latest two articles should be kept
|
|
|
|
[2,"http://example.com/2","",$yesterday,0],
|
|
|
|
[3,"http://example.com/3","",null,0],
|
|
|
|
[4,"http://example.com/4","",$nowish,0],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'arsse_subscriptions' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => "int",
|
|
|
|
'owner' => "str",
|
|
|
|
'feed' => "int",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
// one feed previously marked for deletion has a subscription again, and so should not be deleted
|
|
|
|
[1,'jane.doe@example.com',1],
|
|
|
|
// other subscriptions exist for article cleanup tests
|
|
|
|
[2,'john.doe@example.com',1],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'arsse_articles' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => "int",
|
|
|
|
'feed' => "int",
|
|
|
|
'url_title_hash' => "str",
|
|
|
|
'url_content_hash' => "str",
|
|
|
|
'title_content_hash' => "str",
|
|
|
|
'modified' => "datetime",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
[1,1,"","","",$weeksago], // is the latest article, thus is kept
|
|
|
|
[2,1,"","","",$weeksago], // is the second latest article, thus is kept
|
|
|
|
[3,1,"","","",$weeksago], // is starred by one user, thus is kept
|
|
|
|
[4,1,"","","",$weeksago], // 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
|
|
|
|
[6,1,"","","",$weeksago], // 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
|
|
|
|
[8,1,"","","",$weeksago], // meets the unread threshold even with marks, thus is deleted
|
|
|
|
[9,1,"","","",$weeksago], // meets the read threshold, thus is deleted
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'arsse_editions' => [
|
|
|
|
'columns' => [
|
|
|
|
'id' => "int",
|
|
|
|
'article' => "int",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
[1,1],
|
|
|
|
[2,2],
|
|
|
|
[3,3],
|
|
|
|
[4,4],
|
|
|
|
[201,1],
|
|
|
|
[102,2],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'arsse_marks' => [
|
|
|
|
'columns' => [
|
|
|
|
'article' => "int",
|
|
|
|
'subscription' => "int",
|
|
|
|
'read' => "bool",
|
|
|
|
'starred' => "bool",
|
|
|
|
'modified' => "datetime",
|
|
|
|
],
|
|
|
|
'rows' => [
|
|
|
|
[3,1,0,1,$weeksago],
|
|
|
|
[4,1,1,0,$daysago],
|
|
|
|
[6,1,1,0,$nowish],
|
|
|
|
[6,2,1,0,$weeksago],
|
|
|
|
[8,1,1,0,$weeksago],
|
|
|
|
[9,1,1,0,$daysago],
|
|
|
|
[9,2,1,0,$daysago],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testCleanUpOrphanedFeeds() {
|
2017-08-18 02:36:15 +00:00
|
|
|
Arsse::$db->feedCleanup();
|
|
|
|
$now = gmdate("Y-m-d H:i:s");
|
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_feeds' => ["id","orphaned"]
|
|
|
|
]);
|
|
|
|
$state['arsse_feeds']['rows'][0][1] = null;
|
|
|
|
unset($state['arsse_feeds']['rows'][1]);
|
|
|
|
$state['arsse_feeds']['rows'][2][1] = $now;
|
|
|
|
$this->compareExpectations($state);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testCleanUpOldArticlesWithStandardRetention() {
|
2017-08-18 02:36:15 +00:00
|
|
|
Arsse::$db->articleCleanup();
|
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_articles' => ["id"]
|
|
|
|
]);
|
2017-08-29 14:50:31 +00:00
|
|
|
foreach ([7,8,9] as $id) {
|
2017-08-18 02:36:15 +00:00
|
|
|
unset($state['arsse_articles']['rows'][$id - 1]);
|
|
|
|
}
|
|
|
|
$this->compareExpectations($state);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testCleanUpOldArticlesWithUnlimitedReadRetention() {
|
2017-08-20 19:46:35 +00:00
|
|
|
Arsse::$conf->purgeArticlesRead = "";
|
2017-08-18 02:36:15 +00:00
|
|
|
Arsse::$db->articleCleanup();
|
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_articles' => ["id"]
|
|
|
|
]);
|
2017-08-29 14:50:31 +00:00
|
|
|
foreach ([7,8] as $id) {
|
2017-08-18 02:36:15 +00:00
|
|
|
unset($state['arsse_articles']['rows'][$id - 1]);
|
|
|
|
}
|
|
|
|
$this->compareExpectations($state);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testCleanUpOldArticlesWithUnlimitedUnreadRetention() {
|
2017-08-20 19:46:35 +00:00
|
|
|
Arsse::$conf->purgeArticlesUnread = "";
|
2017-08-18 02:36:15 +00:00
|
|
|
Arsse::$db->articleCleanup();
|
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_articles' => ["id"]
|
|
|
|
]);
|
2017-08-29 14:50:31 +00:00
|
|
|
foreach ([9] as $id) {
|
2017-08-18 02:36:15 +00:00
|
|
|
unset($state['arsse_articles']['rows'][$id - 1]);
|
|
|
|
}
|
|
|
|
$this->compareExpectations($state);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testCleanUpOldArticlesWithUnlimitedRetention() {
|
2017-08-20 19:46:35 +00:00
|
|
|
Arsse::$conf->purgeArticlesRead = "";
|
|
|
|
Arsse::$conf->purgeArticlesUnread = "";
|
2017-08-18 02:36:15 +00:00
|
|
|
Arsse::$db->articleCleanup();
|
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_articles' => ["id"]
|
|
|
|
]);
|
|
|
|
$this->compareExpectations($state);
|
|
|
|
}
|
2017-09-24 16:45:07 +00:00
|
|
|
|
|
|
|
public function testCleanUpExpiredSessions() {
|
|
|
|
Arsse::$db->sessionCleanup();
|
|
|
|
$state = $this->primeExpectations($this->data, [
|
|
|
|
'arsse_sessions' => ["id"]
|
|
|
|
]);
|
|
|
|
foreach ([3,4,5] as $id) {
|
|
|
|
unset($state['arsse_sessions']['rows'][$id - 1]);
|
|
|
|
}
|
|
|
|
$this->compareExpectations($state);
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|