diff --git a/tests/lib/Database/DriverSQLite3.php b/tests/lib/Database/DriverSQLite3.php index 6e9c411..d1e9fa3 100644 --- a/tests/lib/Database/DriverSQLite3.php +++ b/tests/lib/Database/DriverSQLite3.php @@ -9,4 +9,8 @@ trait DriverSQLite3 { Data::$conf->dbSQLite3File = ":memory:"; $this->drv = new Driver(true); } + + function nextID(string $table): int { + return $this->drv->query("SELECT (case when max(id) then max(id) else 0 end)+1 from $table")->getValue(); + } } \ No newline at end of file diff --git a/tests/lib/Database/SeriesFolder.php b/tests/lib/Database/SeriesFolder.php index 1cc723c..c21cf34 100644 --- a/tests/lib/Database/SeriesFolder.php +++ b/tests/lib/Database/SeriesFolder.php @@ -7,45 +7,16 @@ use Phake; trait SeriesFolder { function setUpSeries() { - $data = [ - 'arsse_folders' => [ - 'columns' => [ - 'id' => "int", - 'owner' => "str", - 'parent' => "int", - 'name' => "str", - ], - /* Layout translates to: - Jane - Politics - John - Technology - Software - Politics - Rocketry - Politics - */ - 'rows' => [ - [1, "john.doe@example.com", null, "Technology"], - [2, "john.doe@example.com", 1, "Software"], - [3, "john.doe@example.com", 1, "Rocketry"], - [4, "jane.doe@example.com", null, "Politics"], - [5, "john.doe@example.com", null, "Politics"], - [6, "john.doe@example.com", 2, "Politics"], - ] - ] - ]; - // merge folder table with base user table - $this->data = array_merge($this->data, $data); $this->primeDatabase($this->data); } function testAddARootFolder() { $user = "john.doe@example.com"; - $this->assertSame(7, Data::$db->folderAdd($user, ['name' => "Entertainment"])); + $folderID = $this->nextID("arsse_folders"); + $this->assertSame($folderID, Data::$db->folderAdd($user, ['name' => "Entertainment"])); Phake::verify(Data::$user)->authorize($user, "folderAdd"); $state = $this->primeExpectations($this->data, ['arsse_folders' => ['id','owner', 'parent', 'name']]); - $state['arsse_folders']['rows'][] = [7, $user, null, "Entertainment"]; + $state['arsse_folders']['rows'][] = [$folderID, $user, null, "Entertainment"]; $this->compareExpectations($state); } @@ -56,10 +27,11 @@ trait SeriesFolder { function testAddANestedFolder() { $user = "john.doe@example.com"; - $this->assertSame(7, Data::$db->folderAdd($user, ['name' => "GNOME", 'parent' => 2])); + $folderID = $this->nextID("arsse_folders"); + $this->assertSame($folderID, Data::$db->folderAdd($user, ['name' => "GNOME", 'parent' => 2])); Phake::verify(Data::$user)->authorize($user, "folderAdd"); $state = $this->primeExpectations($this->data, ['arsse_folders' => ['id','owner', 'parent', 'name']]); - $state['arsse_folders']['rows'][] = [7, $user, 2, "GNOME"]; + $state['arsse_folders']['rows'][] = [$folderID, $user, 2, "GNOME"]; $this->compareExpectations($state); } diff --git a/tests/lib/Database/Setup.php b/tests/lib/Database/Setup.php index 4e628d7..e91c789 100644 --- a/tests/lib/Database/Setup.php +++ b/tests/lib/Database/Setup.php @@ -24,6 +24,32 @@ trait Setup { ["john.doe@example.com", "", "John Doe", UserDriver::RIGHTS_NONE], ], ], + 'arsse_folders' => [ + 'columns' => [ + 'id' => "int", + 'owner' => "str", + 'parent' => "int", + 'name' => "str", + ], + /* Layout translates to: + Jane + Politics + John + Technology + Software + Politics + Rocketry + Politics + */ + 'rows' => [ + [1, "john.doe@example.com", null, "Technology"], + [2, "john.doe@example.com", 1, "Software"], + [3, "john.doe@example.com", 1, "Rocketry"], + [4, "jane.doe@example.com", null, "Politics"], + [5, "john.doe@example.com", null, "Politics"], + [6, "john.doe@example.com", 2, "Politics"], + ] + ], ]; function setUp() {