aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/utils
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-05-07 16:08:10 +0200
committerGitHub <noreply@github.com>2017-05-07 16:08:10 +0200
commita4af59f47103a3f9c903eeddb1e30ab9cb7344f0 (patch)
tree3585b6c24c808e75eec93978682bba1a051f7817 /tests/utils
parentb8fcb7d4403a344158ab5d2c8979bdd002e6001d (diff)
parent61d406933e7311a3eb3c0379f1dea8b790459722 (diff)
downloadShaarli-a4af59f47103a3f9c903eeddb1e30ab9cb7344f0.tar.gz
Shaarli-a4af59f47103a3f9c903eeddb1e30ab9cb7344f0.tar.zst
Shaarli-a4af59f47103a3f9c903eeddb1e30ab9cb7344f0.zip
Merge pull request #857 from ArthurHoaro/api/history-get
API: Get History endpoint
Diffstat (limited to 'tests/utils')
-rw-r--r--tests/utils/ReferenceHistory.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/utils/ReferenceHistory.php b/tests/utils/ReferenceHistory.php
new file mode 100644
index 00000000..20284770
--- /dev/null
+++ b/tests/utils/ReferenceHistory.php
@@ -0,0 +1,82 @@
1<?php
2
3/**
4 * Populates a reference history
5 */
6class ReferenceHistory
7{
8 private $count;
9
10 private $history = [];
11
12 /**
13 * Populates the test DB with reference data
14 */
15 public function __construct()
16 {
17 $this->addEntry(
18 History::CREATED,
19 DateTime::createFromFormat('Ymd_His', '20170101_121212'),
20 123
21 );
22
23 $this->addEntry(
24 History::CREATED,
25 DateTime::createFromFormat('Ymd_His', '20170201_121214'),
26 124
27 );
28
29 $this->addEntry(
30 History::UPDATED,
31 DateTime::createFromFormat('Ymd_His', '20170301_121214'),
32 123
33 );
34
35 $this->addEntry(
36 History::SETTINGS,
37 DateTime::createFromFormat('Ymd_His', '20170302_121215')
38 );
39
40 $this->addEntry(
41 History::DELETED,
42 DateTime::createFromFormat('Ymd_His', '20170303_121216'),
43 124
44 );
45 }
46
47 /**
48 * Adds a new history entry
49 *
50 * @param string $event Event identifier
51 * @param DateTime $datetime creation date
52 * @param int $id optional: related link ID
53 */
54 protected function addEntry($event, $datetime, $id = null)
55 {
56 $link = [
57 'event' => $event,
58 'datetime' => $datetime,
59 'id' => $id,
60 ];
61 $this->history[] = $link;
62 $this->count++;
63 }
64
65 /**
66 * Writes data to the datastore
67 *
68 * @param string $filename write history content to.
69 */
70 public function write($filename)
71 {
72 FileUtils::writeFlatDB($filename, $this->history);
73 }
74
75 /**
76 * Returns the number of links in the reference data
77 */
78 public function count()
79 {
80 return $this->count;
81 }
82}