From f4a74eec5d3680c017cbe935488869e748e787bb Mon Sep 17 00:00:00 2001 From: "J. King" Date: Mon, 25 Feb 2019 10:46:43 -0500 Subject: [PATCH] Add all the other context options allowed by the TTRSS search syntax --- lib/Misc/Context.php | 26 ++++++++++++++++++++++++++ tests/cases/Misc/TestContext.php | 9 ++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/Misc/Context.php b/lib/Misc/Context.php index 1dd1a171..9263fa1d 100644 --- a/lib/Misc/Context.php +++ b/lib/Misc/Context.php @@ -10,6 +10,7 @@ use JKingWeb\Arsse\Misc\Date; use JKingWeb\Arsse\Misc\ValueInfo; class Context { + public $not = null; public $reverse = false; public $limit = 0; public $offset = 0; @@ -36,9 +37,16 @@ class Context { public $annotated = null; public $annotationTerms = null; public $searchTerms = null; + public $titleTerms = null; + public $authorTerms = null; protected $props = []; + public function __clone() { + // clone the negation context, if any + $this->not = $this->not ? clone $this->not : null; + } + protected function act(string $prop, int $set, $value) { if ($set) { if (is_null($value)) { @@ -198,4 +206,22 @@ class Context { } return $this->act(__FUNCTION__, func_num_args(), $spec); } + + public function titleTerms(array $spec = null) { + if (isset($spec)) { + $spec = $this->cleanStringArray($spec); + } + return $this->act(__FUNCTION__, func_num_args(), $spec); + } + + public function authorTerms(array $spec = null) { + if (isset($spec)) { + $spec = $this->cleanStringArray($spec); + } + return $this->act(__FUNCTION__, func_num_args(), $spec); + } + + public function not(self $spec = null) { + return $this->act(__FUNCTION__, func_num_args(), $spec); + } } diff --git a/tests/cases/Misc/TestContext.php b/tests/cases/Misc/TestContext.php index 902a6bad..12a99693 100644 --- a/tests/cases/Misc/TestContext.php +++ b/tests/cases/Misc/TestContext.php @@ -14,7 +14,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { public function testVerifyInitialState() { $c = new Context; foreach ((new \ReflectionObject($c))->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) { - if ($m->isConstructor() || $m->isStatic()) { + if ($m->isStatic() || strpos($m->name, "__") === 0) { continue; } $method = $m->name; @@ -51,11 +51,14 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { 'annotated' => true, 'searchTerms' => ["foo", "bar"], 'annotationTerms' => ["foo", "bar"], + 'titleTerms' => ["foo", "bar"], + 'authorTerms' => ["foo", "bar"], + 'not' => (new Context)->subscription(5), ]; $times = ['modifiedSince','notModifiedSince','markedSince','notMarkedSince']; $c = new Context; foreach ((new \ReflectionObject($c))->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) { - if ($m->isConstructor() || $m->isStatic()) { + if ($m->isStatic() || strpos($m->name, "__") === 0) { continue; } $method = $m->name; @@ -84,7 +87,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { } public function testCleanStringArrayValues() { - $methods = ["searchTerms", "annotationTerms"]; + $methods = ["searchTerms", "annotationTerms", "titleTerms", "authorTerms"]; $now = new \DateTime; $in = [1, 3.0, "ook", 0, true, false, null, $now, ""]; $out = ["1", "3", "ook", "0", valueInfo::normalize($now, ValueInfo::T_STRING)];