Browse Source

Re-organize test data for Database tests

microsub
J. King 7 years ago
parent
commit
845b47e656
  1. 18
      tests/lib/Database/SeriesFeed.php
  2. 40
      tests/lib/Database/SeriesFolder.php
  3. 33
      tests/lib/Database/SeriesSubscription.php
  4. 15
      tests/lib/Database/SeriesUser.php
  5. 42
      tests/lib/Database/Setup.php

18
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() {

40
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);
}

33
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);

15
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);
}

42
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

Loading…
Cancel
Save