2017-07-18 20:38:23 +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-07-18 20:38:23 +00:00
|
|
|
declare(strict_types=1);
|
2018-11-23 15:01:17 +00:00
|
|
|
namespace JKingWeb\Arsse\TestCase\Database;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2017-07-18 20:38:23 +00:00
|
|
|
use JKingWeb\Arsse\Test\Database;
|
|
|
|
use JKingWeb\Arsse\Arsse;
|
|
|
|
|
|
|
|
trait SeriesMeta {
|
2023-02-12 23:30:19 +00:00
|
|
|
protected static $drv;
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
protected function setUpSeriesMeta(): void {
|
2018-11-25 05:03:56 +00:00
|
|
|
$dataBare = [
|
|
|
|
'arsse_meta' => [
|
2022-06-05 21:41:32 +00:00
|
|
|
'columns' => ["key", "value"],
|
2022-09-15 14:12:04 +00:00
|
|
|
'rows' => [
|
2022-06-05 21:41:32 +00:00
|
|
|
//['schema_version', "".\JKingWeb\Arsse\Database::SCHEMA_VERSION],
|
|
|
|
['album',"A Farewell to Kings"],
|
2018-11-25 05:03:56 +00:00
|
|
|
],
|
2017-07-18 20:38:23 +00:00
|
|
|
],
|
2018-11-25 05:03:56 +00:00
|
|
|
];
|
2017-07-18 20:38:23 +00:00
|
|
|
// the schema_version key is a special case, and to avoid jumping through hoops for every test we deal with it now
|
2018-11-25 05:03:56 +00:00
|
|
|
$this->data = $dataBare;
|
2017-07-18 20:38:23 +00:00
|
|
|
// 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
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->primeDatabase(static::$drv, $dataBare);
|
2018-11-25 05:03:56 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
protected function tearDownSeriesMeta(): void {
|
2018-11-25 05:03:56 +00:00
|
|
|
unset($this->data);
|
2017-07-18 20:38:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testAddANewValue(): void {
|
2017-07-18 20:38:23 +00:00
|
|
|
$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"];
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-07-18 20:38:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testAddANewTypedValue(): void {
|
2017-07-18 20:38:23 +00:00
|
|
|
$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"];
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-07-18 20:38:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testChangeAnExistingValue(): void {
|
2017-07-18 20:38:23 +00:00
|
|
|
$this->assertTrue(Arsse::$db->metaSet("album", "Hemispheres"));
|
|
|
|
$state = $this->primeExpectations($this->data, ['arsse_meta' => ['key','value']]);
|
|
|
|
$state['arsse_meta']['rows'][1][1] = "Hemispheres";
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-07-18 20:38:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRemoveAValue(): void {
|
2017-07-18 20:38:23 +00:00
|
|
|
$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]);
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->compareExpectations(static::$drv, $state);
|
2017-07-18 20:38:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 18:52:48 +00:00
|
|
|
public function testRetrieveAValue(): void {
|
2017-07-18 20:38:23 +00:00
|
|
|
$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"));
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|