1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Tests for marking articles hidden

This commit is contained in:
J. King 2020-12-19 10:59:40 -05:00
parent 86c4a30744
commit 97010d8822
2 changed files with 114 additions and 3 deletions

View file

@ -1713,7 +1713,7 @@ class Database {
// set starred, hidden, and/or note marks (unless all requested editions actually do not exist)
if ($context->article || $context->articles) {
$q = $this->articleQuery($user, $context, ["id", "subscription"]);
$q->setWhere("(arsse_marks.note <> coalesce(?,arsse_marks.note) or arsse_marks.starred <> coalesce(?,arsse_marks.starred))", ["str", "bool"], [$data['note'], $data['starred']]);
$q->setWhere("(arsse_marks.note <> coalesce(?,arsse_marks.note) or arsse_marks.starred <> coalesce(?,arsse_marks.starred) or arsse_marks.hidden <> coalesce(?,arsse_marks.hidden))", ["str", "bool", "bool"], [$data['note'], $data['starred'], $data['hidden']]);
$q->pushCTE("target_articles(article,subscription)");
$data = array_filter($data, function($v) {
return isset($v);
@ -1737,7 +1737,7 @@ class Database {
}
}
$q = $this->articleQuery($user, $context, ["id", "subscription"]);
$q->setWhere("(arsse_marks.note <> coalesce(?,arsse_marks.note) or arsse_marks.starred <> coalesce(?,arsse_marks.starred) or arsse_marks.read <> coalesce(?,arsse_marks.read))", ["str", "bool", "bool"], [$data['note'], $data['starred'], $data['read']]);
$q->setWhere("(arsse_marks.note <> coalesce(?,arsse_marks.note) or arsse_marks.starred <> coalesce(?,arsse_marks.starred) or arsse_marks.read <> coalesce(?,arsse_marks.read) or arsse_marks.hidden <> coalesce(?,arsse_marks.hidden))", ["str", "bool", "bool", "bool"], [$data['note'], $data['starred'], $data['read'], $data['hidden']]);
$q->pushCTE("target_articles(article,subscription)");
$data = array_filter($data, function($v) {
return isset($v);

View file

@ -253,6 +253,7 @@ trait SeriesArticle {
[1, 2,0,0,'2010-01-01 00:00:00','Some Note',0],
[3, 5,0,0,'2000-01-01 00:00:00','',1],
[6, 1,0,1,'2010-01-01 00:00:00','',1],
[6, 2,1,0,'2010-01-01 00:00:00','',1],
],
],
'arsse_categories' => [ // author-supplied categories
@ -1035,4 +1036,114 @@ trait SeriesArticle {
yield [$method];
}
}
}
public function testMarkAllArticlesNotHidden(): void {
Arsse::$db->articleMark("jane.doe@example.com", ['hidden' => false]);
$now = Date::transform(time(), "sql");
$state = $this->primeExpectations($this->data, $this->checkTables);
$state['arsse_marks']['rows'][14][6] = 0;
$state['arsse_marks']['rows'][14][4] = $now;
$state['arsse_marks']['rows'][15][6] = 0;
$state['arsse_marks']['rows'][15][4] = $now;
$this->compareExpectations(static::$drv, $state);
}
public function testMarkAllArticlesHidden(): void {
Arsse::$db->articleMark("jane.doe@example.com", ['hidden' => true]);
$now = Date::transform(time(), "sql");
$state = $this->primeExpectations($this->data, $this->checkTables);
$state['arsse_marks']['rows'][3][6] = 1;
$state['arsse_marks']['rows'][3][4] = $now;
$state['arsse_marks']['rows'][] = [7,19,0,0,$now,'',1];
$this->compareExpectations(static::$drv, $state);
}
public function testMarkAllArticlesUnreadAndNotHidden(): void {
Arsse::$db->articleMark("jane.doe@example.com", ['read' => false, 'hidden' => false]);
$now = Date::transform(time(), "sql");
$state = $this->primeExpectations($this->data, $this->checkTables);
$state['arsse_marks']['rows'][3][2] = 0;
$state['arsse_marks']['rows'][3][4] = $now;
$state['arsse_marks']['rows'][14][6] = 0;
$state['arsse_marks']['rows'][14][4] = $now;
$state['arsse_marks']['rows'][15][2] = 0;
$state['arsse_marks']['rows'][15][6] = 0;
$state['arsse_marks']['rows'][15][4] = $now;
$this->compareExpectations(static::$drv, $state);
}
public function testMarkAllArticlesReadAndHidden(): void {
Arsse::$db->articleMark("jane.doe@example.com", ['read' => true, 'hidden' => true]);
$now = Date::transform(time(), "sql");
$state = $this->primeExpectations($this->data, $this->checkTables);
$state['arsse_marks']['rows'][3][6] = 1;
$state['arsse_marks']['rows'][3][4] = $now;
$state['arsse_marks']['rows'][14][2] = 1;
$state['arsse_marks']['rows'][14][4] = $now;
$state['arsse_marks']['rows'][] = [7,19,1,0,$now,'',1];
$this->compareExpectations(static::$drv, $state);
}
public function testMarkAllArticlesUnreadAndHidden(): void {
Arsse::$db->articleMark("jane.doe@example.com", ['read' => false,'hidden' => true]);
$now = Date::transform(time(), "sql");
$state = $this->primeExpectations($this->data, $this->checkTables);
$state['arsse_marks']['rows'][3][2] = 0;
$state['arsse_marks']['rows'][3][6] = 1;
$state['arsse_marks']['rows'][3][4] = $now;
$state['arsse_marks']['rows'][15][2] = 0;
$state['arsse_marks']['rows'][15][4] = $now;
$state['arsse_marks']['rows'][] = [7,19,0,0,$now,'',1];
$this->compareExpectations(static::$drv, $state);
}
public function testMarkAllArticlesReadAndNotHidden(): void {
Arsse::$db->articleMark("jane.doe@example.com", ['read' => true,'hidden' => false]);
$now = Date::transform(time(), "sql");
$state = $this->primeExpectations($this->data, $this->checkTables);
$state['arsse_marks']['rows'][14][2] = 1;
$state['arsse_marks']['rows'][14][6] = 0;
$state['arsse_marks']['rows'][14][4] = $now;
$state['arsse_marks']['rows'][15][6] = 0;
$state['arsse_marks']['rows'][15][4] = $now;
$state['arsse_marks']['rows'][] = [7,19,1,0,$now,'',0];
$this->compareExpectations(static::$drv, $state);
}
public function testMarkMultipleEditionsUnreadAndHiddenWithStale(): void {
Arsse::$db->articleMark("jane.doe@example.com", ['read' => false,'hidden' => true], (new Context)->editions([1,2,19,20]));
$now = Date::transform(time(), "sql");
$state = $this->primeExpectations($this->data, $this->checkTables);
$state['arsse_marks']['rows'][3][6] = 1;
$state['arsse_marks']['rows'][3][4] = $now;
$state['arsse_marks']['rows'][15][2] = 0;
$state['arsse_marks']['rows'][15][6] = 1;
$state['arsse_marks']['rows'][15][4] = $now;
$state['arsse_marks']['rows'][] = [7,19,0,0,$now,'',1];
$this->compareExpectations(static::$drv, $state);
}
public function testMarkAStaleEditionHidden(): void {
Arsse::$db->articleMark("jane.doe@example.com", ['hidden' => true], (new Context)->edition(20));
$now = Date::transform(time(), "sql");
$state = $this->primeExpectations($this->data, $this->checkTables);
$state['arsse_marks']['rows'][3][6] = 1;
$state['arsse_marks']['rows'][3][4] = $now;
$this->compareExpectations(static::$drv, $state);
}
public function testMarkAStaleEditionUnreadAndHidden(): void {
Arsse::$db->articleMark("jane.doe@example.com", ['read' => false,'hidden' => true], (new Context)->edition(20)); // only starred is changed
$now = Date::transform(time(), "sql");
$state = $this->primeExpectations($this->data, $this->checkTables);
$state['arsse_marks']['rows'][3][6] = 1;
$state['arsse_marks']['rows'][3][4] = $now;
$this->compareExpectations(static::$drv, $state);
}
public function testMarkAStaleEditionUnreadAndNotHidden(): void {
Arsse::$db->articleMark("jane.doe@example.com", ['read' => false,'hidden' => false], (new Context)->edition(20)); // no changes occur
$state = $this->primeExpectations($this->data, $this->checkTables);
$this->compareExpectations(static::$drv, $state);
}
}