From ace94e3ef85e76cffb1f2e37e703532f443e3df1 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 22 Feb 2019 12:34:06 -0500 Subject: [PATCH] Fix context, and context tests --- lib/Misc/Context.php | 7 ++++--- tests/cases/Misc/TestContext.php | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/Misc/Context.php b/lib/Misc/Context.php index fa6241a..87ada39 100644 --- a/lib/Misc/Context.php +++ b/lib/Misc/Context.php @@ -34,7 +34,7 @@ class Context { public $labelName; public $labelled = null; public $annotated = null; - public $searchTerms = []; + public $searchTerms = null; protected $props = []; @@ -67,8 +67,9 @@ class Context { protected function cleanStringArray(array $spec): array { $spec = array_values($spec); - for ($a = 0; $a < sizeof($spec); $a++) { - if (strlen($str = ValueInfo::normalize($spec[$a], ValueInfo::T_STRING))) { + $stop = sizeof($spec); + for ($a = 0; $a < $stop; $a++) { + if (strlen($str = ValueInfo::normalize($spec[$a], ValueInfo::T_STRING | ValueInfo::M_DROP) ?? "")) { $spec[$a] = $str; } else { unset($spec[$a]); diff --git a/tests/cases/Misc/TestContext.php b/tests/cases/Misc/TestContext.php index 07d6adb..b767d11 100644 --- a/tests/cases/Misc/TestContext.php +++ b/tests/cases/Misc/TestContext.php @@ -7,6 +7,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse\TestCase\Misc; use JKingWeb\Arsse\Misc\Context; +use JKingWeb\Arsse\Misc\ValueInfo; /** @covers \JKingWeb\Arsse\Misc\Context */ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { @@ -48,6 +49,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { 'labelName' => "Rush", 'labelled' => true, 'annotated' => true, + 'searchTerms' => ["foo", "bar"], ]; $times = ['modifiedSince','notModifiedSince','markedSince','notMarkedSince']; $c = new Context; @@ -70,7 +72,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { } } - public function testCleanArrayValues() { + public function testCleanIdArrayValues() { $methods = ["articles", "editions"]; $in = [1, "2", 3.5, 3.0, "ook", 0, -20, true, false, null, new \DateTime(), -1.0]; $out = [1,2, 3]; @@ -79,4 +81,15 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertSame($out, $c->$method($in)->$method, "Context method $method did not return the expected results"); } } + + public function testCleanStringArrayValues() { + $methods = ["searchTerms"]; + $now = new \DateTime; + $in = [1, 3.0, "ook", 0, true, false, null, $now, ""]; + $out = ["1", "3", "ook", "0", valueInfo::normalize($now, ValueInfo::T_STRING)]; + $c = new Context; + foreach ($methods as $method) { + $this->assertSame($out, $c->$method($in)->$method, "Context method $method did not return the expected results"); + } + } }