Browse Source

Enforce minimum array size (for now)

microsub
J. King 5 years ago
parent
commit
98f6fca7e3
  1. 3
      lib/Database.php
  2. 27
      tests/cases/Database/SeriesArticle.php

3
lib/Database.php

@ -1418,6 +1418,9 @@ class Database {
$col = $opt['cte_cols'][$named ? 2 : 1];
if ($context->$m()) {
$seen = true;
if (!$context->$m) {
throw new Db\ExceptionInput("tooShort", ['field' => $m, 'action' => $this->caller(), 'min' => 1]); // must have at least one array element
}
if ($multi) {
list($test, $types, $values) = $this->generateIn($context->$m, $named ? "str" : "int");
$test = "in ($test)";

27
tests/cases/Database/SeriesArticle.php

@ -789,11 +789,6 @@ trait SeriesArticle {
$this->compareExpectations($state);
}
public function testMarkTooFewMultipleArticles() {
$this->assertException("tooShort", "Db", "ExceptionInput");
Arsse::$db->articleMark($this->user, ['read'=>false,'starred'=>true], (new Context)->articles([]));
}
public function testMarkTooManyMultipleArticles() {
$this->assertSame(7, Arsse::$db->articleMark($this->user, ['read'=>false,'starred'=>true], (new Context)->articles(range(1, Database::LIMIT_SET_SIZE * 3))));
}
@ -860,11 +855,6 @@ trait SeriesArticle {
$this->compareExpectations($state);
}
public function testMarkTooFewMultipleEditions() {
$this->assertException("tooShort", "Db", "ExceptionInput");
Arsse::$db->articleMark($this->user, ['read'=>false,'starred'=>true], (new Context)->editions([]));
}
public function testMarkTooManyMultipleEditions() {
$this->assertSame(7, Arsse::$db->articleMark($this->user, ['read'=>false,'starred'=>true], (new Context)->editions(range(1, 51))));
}
@ -1036,13 +1026,20 @@ trait SeriesArticle {
Arsse::$db->articleCategoriesGet($this->user, 19);
}
public function testSearchTooFewTerms() {
/** @dataProvider provideArrayContextOptions */
public function testUseTooFewValuesInArrayContext(string $option) {
$this->assertException("tooShort", "Db", "ExceptionInput");
Arsse::$db->articleList($this->user, (new Context)->searchTerms([]));
Arsse::$db->articleList($this->user, (new Context)->annotationTerms([]));
}
public function testSearchTooFewTermsInNote() {
$this->assertException("tooShort", "Db", "ExceptionInput");
Arsse::$db->articleList($this->user, (new Context)->annotationTerms([]));
public function provideArrayContextOptions() {
foreach([
"articles", "editions",
"subscriptions", "foldersShallow", //"folders",
"tags", "tagNames", "labels", "labelNames",
"searchTerms", "authorTerms", "annotationTerms",
] as $method) {
yield [$method];
}
}
}

Loading…
Cancel
Save