Browse Source
- Fixes #55 - Included test for Context - Adjusted Database::editionLatest() to use Context - Adjusted NCN handler and tests accordingly - Also refined experimental Database::articleList() method and added experimental Database::articlePropertiesSet() methodmicrosub
J. King
7 years ago
8 changed files with 356 additions and 64 deletions
@ -0,0 +1,87 @@ |
|||||
|
<?php |
||||
|
declare(strict_types=1); |
||||
|
namespace JKingWeb\Arsse\Misc; |
||||
|
|
||||
|
class Context { |
||||
|
use DateFormatter; |
||||
|
|
||||
|
public $reverse = false; |
||||
|
public $limit = 0; |
||||
|
public $offset = 0; |
||||
|
public $folder; |
||||
|
public $subscription; |
||||
|
public $oldestEdition; |
||||
|
public $latestEdition; |
||||
|
public $unread = false; |
||||
|
public $starred = false; |
||||
|
public $modifiedSince; |
||||
|
public $notModifiedSince; |
||||
|
public $edition; |
||||
|
public $article; |
||||
|
|
||||
|
protected $props = []; |
||||
|
|
||||
|
protected function act(string $prop, int $set, $value) { |
||||
|
if($set) { |
||||
|
$this->props[$prop] = true; |
||||
|
$this->$prop = $value; |
||||
|
return $this; |
||||
|
} else { |
||||
|
return isset($this->props[$prop]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function reverse(bool $spec = null) { |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function limit(int $spec = null) { |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function offset(int $spec = null) { |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function folder(int $spec = null) { |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function subscription(int $spec = null) { |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function latestEdition(int $spec = null) { |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function oldestEdition(int $spec = null) { |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function unread(bool $spec = null) { |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function starred(bool $spec = null) { |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function modifiedSince($spec = null) { |
||||
|
$spec = $this->dateNormalize($spec); |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function notModifiedSince($spec = null) { |
||||
|
$spec = $this->dateNormalize($spec); |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function edition(int $spec = null) { |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
|
||||
|
function article(int $spec = null) { |
||||
|
return $this->act(__FUNCTION__, func_num_args(), $spec); |
||||
|
} |
||||
|
} |
@ -0,0 +1,51 @@ |
|||||
|
<?php |
||||
|
declare(strict_types=1); |
||||
|
namespace JKingWeb\Arsse; |
||||
|
use JKingWeb\Arsse\Misc\Context; |
||||
|
|
||||
|
|
||||
|
class TestContext extends \PHPUnit\Framework\TestCase { |
||||
|
use Test\Tools; |
||||
|
|
||||
|
function testVerifyInitialState() { |
||||
|
$c = new Context; |
||||
|
foreach((new \ReflectionObject($c))->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) { |
||||
|
if($m->isConstructor() || $m->isStatic()) continue; |
||||
|
$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"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function testSetContextOptions() { |
||||
|
$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(), |
||||
|
]; |
||||
|
$times = ['modifiedSince','notModifiedSince']; |
||||
|
$c = new Context; |
||||
|
foreach((new \ReflectionObject($c))->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) { |
||||
|
if($m->isConstructor() || $m->isStatic()) continue; |
||||
|
$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()); |
||||
|
if(in_array($method, $times)) { |
||||
|
$this->assertTime($c->$method, $v[$method]); |
||||
|
} else { |
||||
|
$this->assertSame($c->$method, $v[$method]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue