2017-06-18 14:23:37 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse;
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
use JKingWeb\Arsse\Misc\Context;
|
2017-06-18 14:23:37 +00:00
|
|
|
|
2017-07-20 22:36:03 +00:00
|
|
|
/** @covers \JKingWeb\Arsse\Misc\Context */
|
2017-07-08 01:06:38 +00:00
|
|
|
class TestContext extends Test\AbstractTest {
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testVerifyInitialState() {
|
2017-06-18 14:23:37 +00:00
|
|
|
$c = new Context;
|
2017-08-29 14:50:31 +00:00
|
|
|
foreach ((new \ReflectionObject($c))->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) {
|
|
|
|
if ($m->isConstructor() || $m->isStatic()) {
|
2017-07-21 02:40:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-06-18 14:23:37 +00:00
|
|
|
$method = $m->name;
|
|
|
|
$this->assertFalse($c->$method(), "Context method $method did not initially return false");
|
|
|
|
$this->assertEquals(null, $c->$method, "Context property $method is not initially falsy");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testSetContextOptions() {
|
2017-06-18 14:23:37 +00:00
|
|
|
$v = [
|
|
|
|
'reverse' => true,
|
|
|
|
'limit' => 10,
|
|
|
|
'offset' => 5,
|
|
|
|
'folder' => 42,
|
|
|
|
'subscription' => 2112,
|
|
|
|
'article' => 255,
|
|
|
|
'edition' => 65535,
|
|
|
|
'latestEdition' => 47,
|
|
|
|
'oldestEdition' => 1337,
|
|
|
|
'unread' => true,
|
|
|
|
'starred' => true,
|
|
|
|
'modifiedSince' => new \DateTime(),
|
|
|
|
'notModifiedSince' => new \DateTime(),
|
2017-07-07 02:53:17 +00:00
|
|
|
'editions' => [1,2],
|
|
|
|
'articles' => [1,2],
|
2017-06-18 14:23:37 +00:00
|
|
|
];
|
|
|
|
$times = ['modifiedSince','notModifiedSince'];
|
|
|
|
$c = new Context;
|
2017-08-29 14:50:31 +00:00
|
|
|
foreach ((new \ReflectionObject($c))->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) {
|
|
|
|
if ($m->isConstructor() || $m->isStatic()) {
|
2017-07-21 02:40:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-06-18 14:23:37 +00:00
|
|
|
$method = $m->name;
|
|
|
|
$this->assertArrayHasKey($method, $v, "Context method $method not included in test");
|
|
|
|
$this->assertInstanceOf(Context::class, $c->$method($v[$method]));
|
|
|
|
$this->assertTrue($c->$method());
|
2017-08-29 14:50:31 +00:00
|
|
|
if (in_array($method, $times)) {
|
2017-06-18 14:23:37 +00:00
|
|
|
$this->assertTime($c->$method, $v[$method]);
|
|
|
|
} else {
|
|
|
|
$this->assertSame($c->$method, $v[$method]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-07 02:53:17 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testCleanArrayValues() {
|
2017-07-07 02:53:17 +00:00
|
|
|
$methods = ["articles", "editions"];
|
|
|
|
$in = [1, "2", 3.5, 3.0, "ook", 0, -20, true, false, null, new \DateTime(), -1.0];
|
|
|
|
$out = [1,2, 3];
|
|
|
|
$c = new Context;
|
2017-08-29 14:50:31 +00:00
|
|
|
foreach ($methods as $method) {
|
2017-07-07 02:53:17 +00:00
|
|
|
$this->assertSame($out, $c->$method($in)->$method, "Context method $method did not return the expected results");
|
|
|
|
}
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|