From 845b47e65604696817fd3781b0c0906c3c74a58b Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sun, 18 Jun 2017 12:24:19 -0400 Subject: [PATCH] Re-organize test data for Database tests --- tests/lib/Database/SeriesFeed.php | 18 +++++++--- tests/lib/Database/SeriesFolder.php | 40 +++++++++++++++++++++ tests/lib/Database/SeriesSubscription.php | 33 ++++++++++++++++-- tests/lib/Database/SeriesUser.php | 15 ++++++++ tests/lib/Database/Setup.php | 42 +---------------------- 5 files changed, 100 insertions(+), 48 deletions(-) diff --git a/tests/lib/Database/SeriesFeed.php b/tests/lib/Database/SeriesFeed.php index db78c0c8..9657ad44 100644 --- a/tests/lib/Database/SeriesFeed.php +++ b/tests/lib/Database/SeriesFeed.php @@ -29,10 +29,23 @@ trait SeriesFeed { ]; function setUpSeries() { + // set up the test data $past = gmdate("Y-m-d H:i:s",strtotime("now - 1 minute")); $future = gmdate("Y-m-d H:i:s",strtotime("now + 1 minute")); $now = gmdate("Y-m-d H:i:s",strtotime("now")); - $data = [ + $this->data = [ + 'arsse_users' => [ + 'columns' => [ + 'id' => 'str', + 'password' => 'str', + 'name' => 'str', + 'rights' => 'int', + ], + 'rows' => [ + ["jane.doe@example.com", "", "Jane Doe", UserDriver::RIGHTS_NONE], + ["john.doe@example.com", "", "John Doe", UserDriver::RIGHTS_NONE], + ], + ], 'arsse_feeds' => [ 'columns' => [ 'id' => "int", @@ -126,10 +139,7 @@ trait SeriesFeed { ] ], ]; - // merge tables - $this->data = array_merge($this->data, $data); $this->primeDatabase($this->data); - $this->user = "john.doe@example.com"; } function testListLatestItems() { diff --git a/tests/lib/Database/SeriesFolder.php b/tests/lib/Database/SeriesFolder.php index 93110714..e53562b8 100644 --- a/tests/lib/Database/SeriesFolder.php +++ b/tests/lib/Database/SeriesFolder.php @@ -7,6 +7,46 @@ use Phake; trait SeriesFolder { function setUpSeries() { + $this->data = [ + 'arsse_users' => [ + 'columns' => [ + 'id' => 'str', + 'password' => 'str', + 'name' => 'str', + 'rights' => 'int', + ], + 'rows' => [ + ["jane.doe@example.com", "", "Jane Doe", UserDriver::RIGHTS_NONE], + ["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"], + ] + ], + ]; $this->primeDatabase($this->data); } diff --git a/tests/lib/Database/SeriesSubscription.php b/tests/lib/Database/SeriesSubscription.php index 8074d8e5..fa690a74 100644 --- a/tests/lib/Database/SeriesSubscription.php +++ b/tests/lib/Database/SeriesSubscription.php @@ -9,7 +9,36 @@ use Phake; trait SeriesSubscription { function setUpSeries() { - $data = [ + $this->data = [ + 'arsse_users' => [ + 'columns' => [ + 'id' => 'str', + 'password' => 'str', + 'name' => 'str', + 'rights' => 'int', + ], + 'rows' => [ + ["admin@example.net", '$2y$10$PbcG2ZR3Z8TuPzM7aHTF8.v61dtCjzjK78gdZJcp4UePE8T9jEgBW', "Hard Lip Herbert", UserDriver::RIGHTS_GLOBAL_ADMIN], // password is hash of "secret" + ["jane.doe@example.com", "", "Jane Doe", UserDriver::RIGHTS_NONE], + ["john.doe@example.com", "", "John Doe", UserDriver::RIGHTS_NONE], + ], + ], + 'arsse_folders' => [ + 'columns' => [ + 'id' => "int", + 'owner' => "str", + 'parent' => "int", + 'name' => "str", + ], + '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"], + ] + ], 'arsse_feeds' => [ 'columns' => [ 'id' => "int", @@ -83,8 +112,6 @@ trait SeriesSubscription { ] ], ]; - // merge tables - $this->data = array_merge($this->data, $data); $this->primeDatabase($this->data); // initialize a partial mock of the Database object to later manipulate the feedUpdate method Data::$db = Phake::PartialMock(Database::class, $this->drv); diff --git a/tests/lib/Database/SeriesUser.php b/tests/lib/Database/SeriesUser.php index 00cfd2b5..ac2c912e 100644 --- a/tests/lib/Database/SeriesUser.php +++ b/tests/lib/Database/SeriesUser.php @@ -7,6 +7,21 @@ use Phake; trait SeriesUser { function setUpSeries() { + $this->data = [ + 'arsse_users' => [ + 'columns' => [ + 'id' => 'str', + 'password' => 'str', + 'name' => 'str', + 'rights' => 'int', + ], + 'rows' => [ + ["admin@example.net", '$2y$10$PbcG2ZR3Z8TuPzM7aHTF8.v61dtCjzjK78gdZJcp4UePE8T9jEgBW', "Hard Lip Herbert", UserDriver::RIGHTS_GLOBAL_ADMIN], // password is hash of "secret" + ["jane.doe@example.com", "", "Jane Doe", UserDriver::RIGHTS_NONE], + ["john.doe@example.com", "", "John Doe", UserDriver::RIGHTS_NONE], + ], + ], + ]; $this->primeDatabase($this->data); } diff --git a/tests/lib/Database/Setup.php b/tests/lib/Database/Setup.php index 3620da20..093eb246 100644 --- a/tests/lib/Database/Setup.php +++ b/tests/lib/Database/Setup.php @@ -11,47 +11,7 @@ use Phake; trait Setup { protected $drv; - protected $data = [ - 'arsse_users' => [ - 'columns' => [ - 'id' => 'str', - 'password' => 'str', - 'name' => 'str', - 'rights' => 'int', - ], - 'rows' => [ - ["admin@example.net", '$2y$10$PbcG2ZR3Z8TuPzM7aHTF8.v61dtCjzjK78gdZJcp4UePE8T9jEgBW', "Hard Lip Herbert", UserDriver::RIGHTS_GLOBAL_ADMIN], // password is hash of "secret" - ["jane.doe@example.com", "", "Jane Doe", UserDriver::RIGHTS_NONE], - ["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"], - ] - ], - ]; + protected $data = []; function setUp() { // establish a clean baseline