J. King
7 years ago
8 changed files with 114 additions and 23 deletions
@ -0,0 +1,9 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
namespace JKingWeb\Arsse; |
|||
|
|||
class TestDatabaseMetaSQLite3 extends Test\AbstractTest { |
|||
use Test\Database\Setup; |
|||
use Test\Database\DriverSQLite3; |
|||
use Test\Database\SeriesMeta; |
|||
} |
@ -0,0 +1,70 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
namespace JKingWeb\Arsse\Test\Database; |
|||
use JKingWeb\Arsse\Test\Database; |
|||
use JKingWeb\Arsse\Arsse; |
|||
|
|||
trait SeriesMeta { |
|||
protected $dataBare = [ |
|||
'arsse_meta' => [ |
|||
'columns' => [ |
|||
'key' => 'str', |
|||
'value' => 'str', |
|||
], |
|||
'rows' => [ |
|||
//['schema_version', "".\JKingWeb\Arsse\Database::SCHEMA_VERSION], |
|||
['album',"A Farewell to Kings"], |
|||
], |
|||
], |
|||
]; |
|||
|
|||
function setUpSeries() { |
|||
// the schema_version key is a special case, and to avoid jumping through hoops for every test we deal with it now |
|||
$this->data = $this->dataBare; |
|||
// as far as tests are concerned the schema version is part of the expectations primed into the database |
|||
array_unshift($this->data['arsse_meta']['rows'], ['schema_version', "".Database::SCHEMA_VERSION]); |
|||
// but it's already been inserted by the driver, so we prime without it |
|||
$this->primeDatabase($this->dataBare); |
|||
} |
|||
|
|||
function testAddANewValue() { |
|||
$this->assertTrue(Arsse::$db->metaSet("favourite", "Cygnus X-1")); |
|||
$state = $this->primeExpectations($this->data, ['arsse_meta' => ['key','value']]); |
|||
$state['arsse_meta']['rows'][] = ["favourite","Cygnus X-1"]; |
|||
$this->compareExpectations($state); |
|||
} |
|||
|
|||
function testAddANewTypedValue() { |
|||
$this->assertTrue(Arsse::$db->metaSet("answer", 42, "int")); |
|||
$this->assertTrue(Arsse::$db->metaSet("true", true, "bool")); |
|||
$this->assertTrue(Arsse::$db->metaSet("false", false, "bool")); |
|||
$this->assertTrue(Arsse::$db->metaSet("millennium", new \DateTime("2000-01-01T00:00:00Z"), "datetime")); |
|||
$state = $this->primeExpectations($this->data, ['arsse_meta' => ['key','value']]); |
|||
$state['arsse_meta']['rows'][] = ["answer","42"]; |
|||
$state['arsse_meta']['rows'][] = ["true","1"]; |
|||
$state['arsse_meta']['rows'][] = ["false","0"]; |
|||
$state['arsse_meta']['rows'][] = ["millennium","2000-01-01 00:00:00"]; |
|||
$this->compareExpectations($state); |
|||
} |
|||
|
|||
function testChangeAnExistingValue() { |
|||
$this->assertTrue(Arsse::$db->metaSet("album", "Hemispheres")); |
|||
$state = $this->primeExpectations($this->data, ['arsse_meta' => ['key','value']]); |
|||
$state['arsse_meta']['rows'][1][1] = "Hemispheres"; |
|||
$this->compareExpectations($state); |
|||
} |
|||
|
|||
function testRemoveAValue() { |
|||
$this->assertTrue(Arsse::$db->metaRemove("album")); |
|||
$this->assertFalse(Arsse::$db->metaRemove("album")); |
|||
$state = $this->primeExpectations($this->data, ['arsse_meta' => ['key','value']]); |
|||
unset($state['arsse_meta']['rows'][1]); |
|||
$this->compareExpectations($state); |
|||
} |
|||
|
|||
function testRetrieveAValue() { |
|||
$this->assertSame("".Database::SCHEMA_VERSION, Arsse::$db->metaGet("schema_version")); |
|||
$this->assertSame("A Farewell to Kings", Arsse::$db->metaGet("album")); |
|||
$this->assertSame(null, Arsse::$db->metaGet("this_key_does_not_exist")); |
|||
} |
|||
} |
Loading…
Reference in new issue