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

Fix context, and context tests

This commit is contained in:
J. King 2019-02-22 12:34:06 -05:00
parent f9fde23708
commit ace94e3ef8
2 changed files with 18 additions and 4 deletions

View file

@ -34,7 +34,7 @@ class Context {
public $labelName; public $labelName;
public $labelled = null; public $labelled = null;
public $annotated = null; public $annotated = null;
public $searchTerms = []; public $searchTerms = null;
protected $props = []; protected $props = [];
@ -67,8 +67,9 @@ class Context {
protected function cleanStringArray(array $spec): array { protected function cleanStringArray(array $spec): array {
$spec = array_values($spec); $spec = array_values($spec);
for ($a = 0; $a < sizeof($spec); $a++) { $stop = sizeof($spec);
if (strlen($str = ValueInfo::normalize($spec[$a], ValueInfo::T_STRING))) { for ($a = 0; $a < $stop; $a++) {
if (strlen($str = ValueInfo::normalize($spec[$a], ValueInfo::T_STRING | ValueInfo::M_DROP) ?? "")) {
$spec[$a] = $str; $spec[$a] = $str;
} else { } else {
unset($spec[$a]); unset($spec[$a]);

View file

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\Misc; namespace JKingWeb\Arsse\TestCase\Misc;
use JKingWeb\Arsse\Misc\Context; use JKingWeb\Arsse\Misc\Context;
use JKingWeb\Arsse\Misc\ValueInfo;
/** @covers \JKingWeb\Arsse\Misc\Context */ /** @covers \JKingWeb\Arsse\Misc\Context */
class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
@ -48,6 +49,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
'labelName' => "Rush", 'labelName' => "Rush",
'labelled' => true, 'labelled' => true,
'annotated' => true, 'annotated' => true,
'searchTerms' => ["foo", "bar"],
]; ];
$times = ['modifiedSince','notModifiedSince','markedSince','notMarkedSince']; $times = ['modifiedSince','notModifiedSince','markedSince','notMarkedSince'];
$c = new Context; $c = new Context;
@ -70,7 +72,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
} }
} }
public function testCleanArrayValues() { public function testCleanIdArrayValues() {
$methods = ["articles", "editions"]; $methods = ["articles", "editions"];
$in = [1, "2", 3.5, 3.0, "ook", 0, -20, true, false, null, new \DateTime(), -1.0]; $in = [1, "2", 3.5, 3.0, "ook", 0, -20, true, false, null, new \DateTime(), -1.0];
$out = [1,2, 3]; $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"); $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");
}
}
} }