From 7897585d9887a6f7e58d1630d421b01fd81de4a5 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sat, 16 Jan 2021 17:58:31 -0500 Subject: [PATCH] Test scraping Text search should also match scraped content when appropriate --- lib/Database.php | 16 +++++++++--- tests/cases/Database/SeriesArticle.php | 35 +++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/lib/Database.php b/lib/Database.php index a78ba37..ea70d95 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -1711,10 +1711,10 @@ class Database { } // handle text-matching context options $options = [ - "titleTerms" => ["arsse_articles.title"], - "searchTerms" => ["arsse_articles.title", "arsse_articles.content"], - "authorTerms" => ["arsse_articles.author"], - "annotationTerms" => ["arsse_marks.note"], + "titleTerms" => ["title"], + "searchTerms" => ["title", "content"], + "authorTerms" => ["author"], + "annotationTerms" => ["note"], ]; foreach ($options as $m => $columns) { if (!$context->$m()) { @@ -1722,6 +1722,10 @@ class Database { } elseif (!$context->$m) { 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)); } // further handle exclusionary text-matching context options @@ -1729,6 +1733,10 @@ class Database { if (!$context->not->$m() || !$context->not->$m) { 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)); } // return the query diff --git a/tests/cases/Database/SeriesArticle.php b/tests/cases/Database/SeriesArticle.php index 09342c9..6302f5d 100644 --- a/tests/cases/Database/SeriesArticle.php +++ b/tests/cases/Database/SeriesArticle.php @@ -22,10 +22,11 @@ trait SeriesArticle { 'num' => 'int', ], 'rows' => [ - ["jane.doe@example.com", "",1], - ["john.doe@example.com", "",2], - ["john.doe@example.org", "",3], - ["john.doe@example.net", "",4], + ["jane.doe@example.com", "", 1], + ["john.doe@example.com", "", 2], + ["john.doe@example.org", "", 3], + ["john.doe@example.net", "", 4], + ["jill.doe@example.com", "", 5], ], ], 'arsse_feeds' => [ @@ -110,6 +111,7 @@ trait SeriesArticle { [12,"john.doe@example.net",2, 9,null,0], [13,"john.doe@example.net",3, 8,"Subscription 13",0], [14,"john.doe@example.net",4, 7,null,0], + [15,"jill.doe@example.com",11,null,null,1], ], ], 'arsse_tag_members' => [ @@ -1149,4 +1151,29 @@ trait SeriesArticle { $state = $this->primeExpectations($this->data, $this->checkTables); $this->compareExpectations(static::$drv, $state); } + + public function testSelectScrapedContent(): void { + $exp = [ + ['id' => 101, 'content' => "

Article content 1

"], + ['id' => 102, 'content' => "

Article content 2

"], + ]; + $this->assertResult($exp, Arsse::$db->articleList("john.doe@example.org", (new Context)->subscription(8), ["id", "content"])); + $exp = [ + ['id' => 101, 'content' => "

Scraped content 1

"], + ['id' => 102, 'content' => "

Article content 2

"], + ]; + $this->assertResult($exp, Arsse::$db->articleList("jill.doe@example.com", (new Context)->subscription(15), ["id", "content"])); + } + + public function testSearchScrapedContent(): void { + $exp = [ + ['id' => 101, 'content' => "

Scraped content 1

"], + ['id' => 102, 'content' => "

Article content 2

"], + ]; + $this->assertResult($exp, Arsse::$db->articleList("jill.doe@example.com", (new Context)->subscription(15)->searchTerms(["article"]), ["id", "content"])); + $exp = [ + ['id' => 101, 'content' => "

Scraped content 1

"], + ]; + $this->assertResult($exp, Arsse::$db->articleList("jill.doe@example.com", (new Context)->subscription(15)->searchTerms(["scraped"]), ["id", "content"])); + } }