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

Tests for date ranges in contexts

This commit is contained in:
J. King 2022-04-24 12:25:37 -04:00
parent 33a3478a58
commit f6799e2ab1
5 changed files with 104 additions and 87 deletions

View file

@ -79,7 +79,7 @@ trait ExclusionMembers {
}
}
}
return array_values(array_unique($spec));
return array_values(array_unique($spec, \SORT_REGULAR));
}
public function folder(int $spec = null) {

View file

@ -281,15 +281,19 @@ class ValueInfo {
if (!$out) {
throw new \Exception;
}
return $out;
return $out->setTimezone(new \DateTimeZone("UTC"));
} else {
return new \DateTimeImmutable($value, new \DateTimeZone("UTC"));
$out = new \DateTimeImmutable($value, new \DateTimeZone("UTC"));
if ($out) {
return $out->setTimezone(new \DateTimeZone("UTC"));
} elseif ($strict && !$drop) {
throw new \Exception;
}
}
} catch (\Exception $e) {
if ($strict && !$drop) {
throw new ExceptionType("strictFailure", $type);
}
return null;
}
} elseif ($strict && !$drop) {
throw new ExceptionType("strictFailure", $type);

View file

@ -387,9 +387,11 @@ abstract class BaseDriver extends \JKingWeb\Arsse\Test\AbstractTest {
$integer = $this->drv->sqlToken("InTEGer");
$asc = $this->drv->sqlToken("asc");
$desc = $this->drv->sqlToken("desc");
$least = $this->drv->sqlToken("leASt");
$this->assertSame("NOT_A_TOKEN", $this->drv->sqlToken("NOT_A_TOKEN"));
$this->assertSame("A", $this->drv->query("SELECT $least('Z', 'A')")->getValue());
$this->assertSame("Z", $this->drv->query("SELECT $greatest('Z', 'A')")->getValue());
$this->assertSame("Z", $this->drv->query("SELECT 'Z' collate $nocase")->getValue());
$this->assertSame("Z", $this->drv->query("SELECT 'Z' where 'Z' $like 'z'")->getValue());

View file

@ -8,6 +8,7 @@ namespace JKingWeb\Arsse\TestCase\Misc;
use JKingWeb\Arsse\Context\Context;
use JKingWeb\Arsse\Context\ExclusionContext;
use JKingWeb\Arsse\Misc\Date;
use JKingWeb\Arsse\Misc\ValueInfo;
/**
@ -129,6 +130,16 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
}
}
public function testCleanDateRangeArrayValues(): void {
$methods = ["modifiedRanges", "markedRanges"];
$in = [null, 1, [1, 2, 3], [1], [null, null], ["ook", null], ["2022-09-13T06:46:28 America/Los_angeles", new \DateTime("2022-01-23T00:33:49Z")], [0, null], [null, 0]];
$out = [[Date::normalize("2022-09-13T13:46:28Z"), Date::normalize("2022-01-23T00:33:49Z")], [Date::normalize(0), null], [null, Date::normalize(0)]];
$c = new Context;
foreach ($methods as $method) {
$this->assertEquals($out, $c->$method($in)->$method, "Context method $method did not return the expected results");
}
}
public function testCloneAContext(): void {
$c1 = new Context;
$c2 = clone $c1;

View file

@ -349,7 +349,7 @@ class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest {
// if we're performing a strict comparison and the value is supposed to fail, we should be getting an exception
$this->assertException("strictFailure", "", "ExceptionType");
I::normalize($input, $typeConst | $modeConst);
$this->assertTrue(false, "$typename $modeName test expected exception");
$this->assertTrue(false, "$typeName $modeName test expected exception");
} elseif ($drop && !$pass) {
// if we're performing a drop comparison and the value is supposed to fail, change the expectation to null
$exp = null;
@ -455,7 +455,7 @@ class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest {
[null, [null,true], [false,false], [0, false], [0.0, false], ["", false], [[], false], [null, false]],
["", [null,true], [false,true], [0, false], [0.0, false], ["", true], [[""], false], [null, false]],
[1, [null,true], [true, true], [1, true], [1.0, true], ["1", true], [[1], false], [$this->i("PT1S"), false]],
[PHP_INT_MAX, [null,true], [true, false], [PHP_INT_MAX, true], [(float) PHP_INT_MAX,true], [(string) PHP_INT_MAX, true], [[PHP_INT_MAX], false], [$this->i("P292471208677Y195DT15H30M7S"), false]],
[PHP_INT_MAX, [null,true], [true, false], [PHP_INT_MAX, true], [(float) PHP_INT_MAX, true], [(string) PHP_INT_MAX, true], [[PHP_INT_MAX], false], [$this->i("P292471208677Y195DT15H30M7S"), false]],
[1.0, [null,true], [true, true], [1, true], [1.0, true], ["1", true], [[1.0], false], [$this->i("PT1S"), false]],
["1.0", [null,true], [true, true], [1, true], [1.0, true], ["1.0", true], [["1.0"], false], [null, false]],
["001.0", [null,true], [true, true], [1, true], [1.0, true], ["001.0", true], [["001.0"], false], [null, false]],