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

Test scraping

Text search should also match scraped content when appropriate
This commit is contained in:
J. King 2021-01-16 17:58:31 -05:00
parent 76f70119fd
commit 7897585d98
2 changed files with 43 additions and 8 deletions

View file

@ -1711,10 +1711,10 @@ class Database {
} }
// handle text-matching context options // handle text-matching context options
$options = [ $options = [
"titleTerms" => ["arsse_articles.title"], "titleTerms" => ["title"],
"searchTerms" => ["arsse_articles.title", "arsse_articles.content"], "searchTerms" => ["title", "content"],
"authorTerms" => ["arsse_articles.author"], "authorTerms" => ["author"],
"annotationTerms" => ["arsse_marks.note"], "annotationTerms" => ["note"],
]; ];
foreach ($options as $m => $columns) { foreach ($options as $m => $columns) {
if (!$context->$m()) { if (!$context->$m()) {
@ -1722,6 +1722,10 @@ class Database {
} elseif (!$context->$m) { } elseif (!$context->$m) {
throw new Db\ExceptionInput("tooShort", ['field' => $m, 'action' => $this->caller(), 'min' => 1]); // must have at least one array element throw new Db\ExceptionInput("tooShort", ['field' => $m, 'action' => $this->caller(), 'min' => 1]); // must have at least one array element
} }
$columns = array_map(function ($c) use ($colDefs) {
assert(isset($colDefs[$c]), new Exception("constantUnknown", $c));
return $colDefs[$c];
}, $columns);
$q->setWhere(...$this->generateSearch($context->$m, $columns)); $q->setWhere(...$this->generateSearch($context->$m, $columns));
} }
// further handle exclusionary text-matching context options // further handle exclusionary text-matching context options
@ -1729,6 +1733,10 @@ class Database {
if (!$context->not->$m() || !$context->not->$m) { if (!$context->not->$m() || !$context->not->$m) {
continue; continue;
} }
$columns = array_map(function ($c) use ($colDefs) {
assert(isset($colDefs[$c]), new Exception("constantUnknown", $c));
return $colDefs[$c];
}, $columns);
$q->setWhereNot(...$this->generateSearch($context->not->$m, $columns, true)); $q->setWhereNot(...$this->generateSearch($context->not->$m, $columns, true));
} }
// return the query // return the query

View file

@ -22,10 +22,11 @@ trait SeriesArticle {
'num' => 'int', 'num' => 'int',
], ],
'rows' => [ 'rows' => [
["jane.doe@example.com", "",1], ["jane.doe@example.com", "", 1],
["john.doe@example.com", "",2], ["john.doe@example.com", "", 2],
["john.doe@example.org", "",3], ["john.doe@example.org", "", 3],
["john.doe@example.net", "",4], ["john.doe@example.net", "", 4],
["jill.doe@example.com", "", 5],
], ],
], ],
'arsse_feeds' => [ 'arsse_feeds' => [
@ -110,6 +111,7 @@ trait SeriesArticle {
[12,"john.doe@example.net",2, 9,null,0], [12,"john.doe@example.net",2, 9,null,0],
[13,"john.doe@example.net",3, 8,"Subscription 13",0], [13,"john.doe@example.net",3, 8,"Subscription 13",0],
[14,"john.doe@example.net",4, 7,null,0], [14,"john.doe@example.net",4, 7,null,0],
[15,"jill.doe@example.com",11,null,null,1],
], ],
], ],
'arsse_tag_members' => [ 'arsse_tag_members' => [
@ -1149,4 +1151,29 @@ trait SeriesArticle {
$state = $this->primeExpectations($this->data, $this->checkTables); $state = $this->primeExpectations($this->data, $this->checkTables);
$this->compareExpectations(static::$drv, $state); $this->compareExpectations(static::$drv, $state);
} }
public function testSelectScrapedContent(): void {
$exp = [
['id' => 101, 'content' => "<p>Article content 1</p>"],
['id' => 102, 'content' => "<p>Article content 2</p>"],
];
$this->assertResult($exp, Arsse::$db->articleList("john.doe@example.org", (new Context)->subscription(8), ["id", "content"]));
$exp = [
['id' => 101, 'content' => "<p>Scraped content 1</p>"],
['id' => 102, 'content' => "<p>Article content 2</p>"],
];
$this->assertResult($exp, Arsse::$db->articleList("jill.doe@example.com", (new Context)->subscription(15), ["id", "content"]));
}
public function testSearchScrapedContent(): void {
$exp = [
['id' => 101, 'content' => "<p>Scraped content 1</p>"],
['id' => 102, 'content' => "<p>Article content 2</p>"],
];
$this->assertResult($exp, Arsse::$db->articleList("jill.doe@example.com", (new Context)->subscription(15)->searchTerms(["article"]), ["id", "content"]));
$exp = [
['id' => 101, 'content' => "<p>Scraped content 1</p>"],
];
$this->assertResult($exp, Arsse::$db->articleList("jill.doe@example.com", (new Context)->subscription(15)->searchTerms(["scraped"]), ["id", "content"]));
}
} }