2017-06-18 14:23:37 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-06-18 14:23:37 +00:00
|
|
|
declare(strict_types=1);
|
2017-12-22 03:47:19 +00:00
|
|
|
namespace JKingWeb\Arsse\TestCase\Misc;
|
2017-06-18 14:23:37 +00:00
|
|
|
|
2019-02-26 03:41:12 +00:00
|
|
|
use JKingWeb\Arsse\Context\Context;
|
2019-02-22 17:34:06 +00:00
|
|
|
use JKingWeb\Arsse\Misc\ValueInfo;
|
2017-06-18 14:23:37 +00:00
|
|
|
|
2019-02-26 03:41:12 +00:00
|
|
|
/** @covers \JKingWeb\Arsse\Context\Context<extended> */
|
2017-12-22 03:47:19 +00:00
|
|
|
class TestContext extends \JKingWeb\Arsse\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) {
|
2019-02-25 15:46:43 +00:00
|
|
|
if ($m->isStatic() || strpos($m->name, "__") === 0) {
|
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,
|
2017-11-17 22:52:00 +00:00
|
|
|
'folderShallow' => 42,
|
2019-03-07 16:07:22 +00:00
|
|
|
'tag' => 44,
|
|
|
|
'tagName' => "XLIV",
|
2017-06-18 14:23:37 +00:00
|
|
|
'subscription' => 2112,
|
|
|
|
'article' => 255,
|
|
|
|
'edition' => 65535,
|
2017-11-18 21:06:49 +00:00
|
|
|
'latestArticle' => 47,
|
|
|
|
'oldestArticle' => 1337,
|
2017-06-18 14:23:37 +00:00
|
|
|
'latestEdition' => 47,
|
|
|
|
'oldestEdition' => 1337,
|
|
|
|
'unread' => true,
|
|
|
|
'starred' => true,
|
|
|
|
'modifiedSince' => new \DateTime(),
|
|
|
|
'notModifiedSince' => new \DateTime(),
|
2017-11-17 22:52:00 +00:00
|
|
|
'markedSince' => new \DateTime(),
|
|
|
|
'notMarkedSince' => new \DateTime(),
|
2017-07-07 02:53:17 +00:00
|
|
|
'editions' => [1,2],
|
|
|
|
'articles' => [1,2],
|
2017-10-13 04:04:26 +00:00
|
|
|
'label' => 2112,
|
|
|
|
'labelName' => "Rush",
|
2017-11-17 22:52:00 +00:00
|
|
|
'labelled' => true,
|
2017-11-18 00:08:35 +00:00
|
|
|
'annotated' => true,
|
2019-02-22 17:34:06 +00:00
|
|
|
'searchTerms' => ["foo", "bar"],
|
2019-02-24 01:14:52 +00:00
|
|
|
'annotationTerms' => ["foo", "bar"],
|
2019-02-25 15:46:43 +00:00
|
|
|
'titleTerms' => ["foo", "bar"],
|
|
|
|
'authorTerms' => ["foo", "bar"],
|
|
|
|
'not' => (new Context)->subscription(5),
|
2017-06-18 14:23:37 +00:00
|
|
|
];
|
2017-11-17 22:52:00 +00:00
|
|
|
$times = ['modifiedSince','notModifiedSince','markedSince','notMarkedSince'];
|
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) {
|
2019-02-25 15:46:43 +00:00
|
|
|
if ($m->isStatic() || strpos($m->name, "__") === 0) {
|
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-09-28 14:16:24 +00:00
|
|
|
$this->assertTime($c->$method, $v[$method], "Context method $method did not return the expected results");
|
2017-06-18 14:23:37 +00:00
|
|
|
} else {
|
2017-09-28 14:16:24 +00:00
|
|
|
$this->assertSame($c->$method, $v[$method], "Context method $method did not return the expected results");
|
2017-06-18 14:23:37 +00:00
|
|
|
}
|
2018-12-05 17:54:19 +00:00
|
|
|
// clear the context option
|
|
|
|
$c->$method(null);
|
|
|
|
$this->assertFalse($c->$method());
|
2017-06-18 14:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-07 02:53:17 +00:00
|
|
|
|
2019-02-22 17:34:06 +00:00
|
|
|
public function testCleanIdArrayValues() {
|
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");
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 17:34:06 +00:00
|
|
|
|
|
|
|
public function testCleanStringArrayValues() {
|
2019-02-25 15:46:43 +00:00
|
|
|
$methods = ["searchTerms", "annotationTerms", "titleTerms", "authorTerms"];
|
2019-02-22 17:34:06 +00:00
|
|
|
$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");
|
|
|
|
}
|
|
|
|
}
|
2019-02-26 03:41:12 +00:00
|
|
|
|
|
|
|
public function testCloneAContext() {
|
|
|
|
$c1 = new Context;
|
|
|
|
$c2 = clone $c1;
|
|
|
|
$this->assertEquals($c1, $c2);
|
|
|
|
$this->assertEquals($c1->not, $c2->not);
|
|
|
|
$this->assertNotSame($c1, $c2);
|
|
|
|
$this->assertNotSame($c1->not, $c2->not);
|
2019-02-26 04:37:14 +00:00
|
|
|
$this->assertSame($c1, $c1->not->article(null));
|
|
|
|
$this->assertSame($c2, $c2->not->article(null));
|
2019-02-26 03:41:12 +00:00
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|