aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-05-07 16:50:20 +0200
committerArthurHoaro <arthur@hoa.ro>2017-05-07 17:11:22 +0200
commit813849e5216cb87121e0f778a734575be6a36052 (patch)
tree45605ad43e3f751eba51d19f8c6955c3824e8d32 /tests
parenta4af59f47103a3f9c903eeddb1e30ab9cb7344f0 (diff)
downloadShaarli-813849e5216cb87121e0f778a734575be6a36052.tar.gz
Shaarli-813849e5216cb87121e0f778a734575be6a36052.tar.zst
Shaarli-813849e5216cb87121e0f778a734575be6a36052.zip
Add history entries for API endpoint
CHANGED: datetime is now store as an object in history store file
Diffstat (limited to 'tests')
-rw-r--r--tests/HistoryTest.php24
-rw-r--r--tests/NetscapeBookmarkUtils/BookmarkImportTest.php4
-rw-r--r--tests/api/controllers/DeleteLinkTest.php22
-rw-r--r--tests/api/controllers/GetLinkIdTest.php1
-rw-r--r--tests/api/controllers/GetLinksTest.php1
-rw-r--r--tests/api/controllers/HistoryTest.php7
-rw-r--r--tests/api/controllers/InfoTest.php1
-rw-r--r--tests/api/controllers/PostLinkTest.php23
-rw-r--r--tests/api/controllers/PutLinkTest.php23
9 files changed, 86 insertions, 20 deletions
diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php
index 91525845..d3bef5a3 100644
--- a/tests/HistoryTest.php
+++ b/tests/HistoryTest.php
@@ -74,21 +74,21 @@ class HistoryTest extends PHPUnit_Framework_TestCase
74 $history->addLink(['id' => 0]); 74 $history->addLink(['id' => 0]);
75 $actual = $history->getHistory()[0]; 75 $actual = $history->getHistory()[0];
76 $this->assertEquals(History::CREATED, $actual['event']); 76 $this->assertEquals(History::CREATED, $actual['event']);
77 $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); 77 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
78 $this->assertEquals(0, $actual['id']); 78 $this->assertEquals(0, $actual['id']);
79 79
80 $history = new History(self::$historyFilePath); 80 $history = new History(self::$historyFilePath);
81 $history->addLink(['id' => 1]); 81 $history->addLink(['id' => 1]);
82 $actual = $history->getHistory()[0]; 82 $actual = $history->getHistory()[0];
83 $this->assertEquals(History::CREATED, $actual['event']); 83 $this->assertEquals(History::CREATED, $actual['event']);
84 $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); 84 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
85 $this->assertEquals(1, $actual['id']); 85 $this->assertEquals(1, $actual['id']);
86 86
87 $history = new History(self::$historyFilePath); 87 $history = new History(self::$historyFilePath);
88 $history->addLink(['id' => 'str']); 88 $history->addLink(['id' => 'str']);
89 $actual = $history->getHistory()[0]; 89 $actual = $history->getHistory()[0];
90 $this->assertEquals(History::CREATED, $actual['event']); 90 $this->assertEquals(History::CREATED, $actual['event']);
91 $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); 91 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
92 $this->assertEquals('str', $actual['id']); 92 $this->assertEquals('str', $actual['id']);
93 } 93 }
94 94
@@ -101,7 +101,7 @@ class HistoryTest extends PHPUnit_Framework_TestCase
101 $history->updateLink(['id' => 1]); 101 $history->updateLink(['id' => 1]);
102 $actual = $history->getHistory()[0]; 102 $actual = $history->getHistory()[0];
103 $this->assertEquals(History::UPDATED, $actual['event']); 103 $this->assertEquals(History::UPDATED, $actual['event']);
104 $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); 104 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
105 $this->assertEquals(1, $actual['id']); 105 $this->assertEquals(1, $actual['id']);
106 } 106 }
107 107
@@ -114,7 +114,7 @@ class HistoryTest extends PHPUnit_Framework_TestCase
114 $history->deleteLink(['id' => 1]); 114 $history->deleteLink(['id' => 1]);
115 $actual = $history->getHistory()[0]; 115 $actual = $history->getHistory()[0];
116 $this->assertEquals(History::DELETED, $actual['event']); 116 $this->assertEquals(History::DELETED, $actual['event']);
117 $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); 117 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
118 $this->assertEquals(1, $actual['id']); 118 $this->assertEquals(1, $actual['id']);
119 } 119 }
120 120
@@ -127,7 +127,7 @@ class HistoryTest extends PHPUnit_Framework_TestCase
127 $history->updateSettings(); 127 $history->updateSettings();
128 $actual = $history->getHistory()[0]; 128 $actual = $history->getHistory()[0];
129 $this->assertEquals(History::SETTINGS, $actual['event']); 129 $this->assertEquals(History::SETTINGS, $actual['event']);
130 $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); 130 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
131 $this->assertEmpty($actual['id']); 131 $this->assertEmpty($actual['id']);
132 } 132 }
133 133
@@ -140,13 +140,13 @@ class HistoryTest extends PHPUnit_Framework_TestCase
140 $history->updateLink(['id' => 1]); 140 $history->updateLink(['id' => 1]);
141 $actual = $history->getHistory()[0]; 141 $actual = $history->getHistory()[0];
142 $this->assertEquals(History::UPDATED, $actual['event']); 142 $this->assertEquals(History::UPDATED, $actual['event']);
143 $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); 143 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
144 $this->assertEquals(1, $actual['id']); 144 $this->assertEquals(1, $actual['id']);
145 145
146 $history->addLink(['id' => 1]); 146 $history->addLink(['id' => 1]);
147 $actual = $history->getHistory()[0]; 147 $actual = $history->getHistory()[0];
148 $this->assertEquals(History::CREATED, $actual['event']); 148 $this->assertEquals(History::CREATED, $actual['event']);
149 $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); 149 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
150 $this->assertEquals(1, $actual['id']); 150 $this->assertEquals(1, $actual['id']);
151 } 151 }
152 152
@@ -160,7 +160,7 @@ class HistoryTest extends PHPUnit_Framework_TestCase
160 $history = new History(self::$historyFilePath); 160 $history = new History(self::$historyFilePath);
161 $actual = $history->getHistory()[0]; 161 $actual = $history->getHistory()[0];
162 $this->assertEquals(History::UPDATED, $actual['event']); 162 $this->assertEquals(History::UPDATED, $actual['event']);
163 $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); 163 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
164 $this->assertEquals(1, $actual['id']); 164 $this->assertEquals(1, $actual['id']);
165 } 165 }
166 166
@@ -176,12 +176,12 @@ class HistoryTest extends PHPUnit_Framework_TestCase
176 $history = new History(self::$historyFilePath); 176 $history = new History(self::$historyFilePath);
177 $actual = $history->getHistory()[0]; 177 $actual = $history->getHistory()[0];
178 $this->assertEquals(History::CREATED, $actual['event']); 178 $this->assertEquals(History::CREATED, $actual['event']);
179 $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); 179 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
180 $this->assertEquals(1, $actual['id']); 180 $this->assertEquals(1, $actual['id']);
181 181
182 $actual = $history->getHistory()[1]; 182 $actual = $history->getHistory()[1];
183 $this->assertEquals(History::UPDATED, $actual['event']); 183 $this->assertEquals(History::UPDATED, $actual['event']);
184 $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); 184 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
185 $this->assertEquals(1, $actual['id']); 185 $this->assertEquals(1, $actual['id']);
186 } 186 }
187 187
@@ -194,7 +194,7 @@ class HistoryTest extends PHPUnit_Framework_TestCase
194 $history->updateLink(['id' => 1]); 194 $history->updateLink(['id' => 1]);
195 $this->assertEquals(1, count($history->getHistory())); 195 $this->assertEquals(1, count($history->getHistory()));
196 $arr = $history->getHistory(); 196 $arr = $history->getHistory();
197 $arr[0]['datetime'] = (new DateTime('-1 hour'))->format(DateTime::ATOM); 197 $arr[0]['datetime'] = new DateTime('-1 hour');
198 FileUtils::writeFlatDB(self::$historyFilePath, $arr); 198 FileUtils::writeFlatDB(self::$historyFilePath, $arr);
199 199
200 $history = new History(self::$historyFilePath, 60); 200 $history = new History(self::$historyFilePath, 60);
diff --git a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
index f838f259..5fc1d1e8 100644
--- a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
+++ b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
@@ -628,7 +628,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
628 $this->assertEquals($nbLinks, count($history)); 628 $this->assertEquals($nbLinks, count($history));
629 foreach ($history as $value) { 629 foreach ($history as $value) {
630 $this->assertEquals(History::CREATED, $value['event']); 630 $this->assertEquals(History::CREATED, $value['event']);
631 $this->assertTrue(new DateTime('-5 seconds') < DateTime::createFromFormat(DateTime::ATOM, $value['datetime'])); 631 $this->assertTrue(new DateTime('-5 seconds') < $value['datetime']);
632 $this->assertTrue(is_int($value['id'])); 632 $this->assertTrue(is_int($value['id']));
633 } 633 }
634 634
@@ -638,7 +638,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
638 $this->assertEquals($nbLinks * 2, count($history)); 638 $this->assertEquals($nbLinks * 2, count($history));
639 for ($i = 0 ; $i < $nbLinks ; $i++) { 639 for ($i = 0 ; $i < $nbLinks ; $i++) {
640 $this->assertEquals(History::UPDATED, $history[$i]['event']); 640 $this->assertEquals(History::UPDATED, $history[$i]['event']);
641 $this->assertTrue(new DateTime('-5 seconds') < DateTime::createFromFormat(DateTime::ATOM, $history[$i]['datetime'])); 641 $this->assertTrue(new DateTime('-5 seconds') < $history[$i]['datetime']);
642 $this->assertTrue(is_int($history[$i]['id'])); 642 $this->assertTrue(is_int($history[$i]['id']));
643 } 643 }
644 } 644 }
diff --git a/tests/api/controllers/DeleteLinkTest.php b/tests/api/controllers/DeleteLinkTest.php
index 6894e8a2..7d797137 100644
--- a/tests/api/controllers/DeleteLinkTest.php
+++ b/tests/api/controllers/DeleteLinkTest.php
@@ -17,6 +17,11 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
17 protected static $testDatastore = 'sandbox/datastore.php'; 17 protected static $testDatastore = 'sandbox/datastore.php';
18 18
19 /** 19 /**
20 * @var string datastore to test write operations
21 */
22 protected static $testHistory = 'sandbox/history.php';
23
24 /**
20 * @var ConfigManager instance 25 * @var ConfigManager instance
21 */ 26 */
22 protected $conf; 27 protected $conf;
@@ -32,6 +37,11 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
32 protected $linkDB; 37 protected $linkDB;
33 38
34 /** 39 /**
40 * @var \History instance.
41 */
42 protected $history;
43
44 /**
35 * @var Container instance. 45 * @var Container instance.
36 */ 46 */
37 protected $container; 47 protected $container;
@@ -50,9 +60,13 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
50 $this->refDB = new \ReferenceLinkDB(); 60 $this->refDB = new \ReferenceLinkDB();
51 $this->refDB->write(self::$testDatastore); 61 $this->refDB->write(self::$testDatastore);
52 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 62 $this->linkDB = new \LinkDB(self::$testDatastore, true, false);
63 $refHistory = new \ReferenceHistory();
64 $refHistory->write(self::$testHistory);
65 $this->history = new \History(self::$testHistory);
53 $this->container = new Container(); 66 $this->container = new Container();
54 $this->container['conf'] = $this->conf; 67 $this->container['conf'] = $this->conf;
55 $this->container['db'] = $this->linkDB; 68 $this->container['db'] = $this->linkDB;
69 $this->container['history'] = $this->history;
56 70
57 $this->controller = new Links($this->container); 71 $this->controller = new Links($this->container);
58 } 72 }
@@ -63,6 +77,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
63 public function tearDown() 77 public function tearDown()
64 { 78 {
65 @unlink(self::$testDatastore); 79 @unlink(self::$testDatastore);
80 @unlink(self::$testHistory);
66 } 81 }
67 82
68 /** 83 /**
@@ -83,6 +98,13 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
83 98
84 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 99 $this->linkDB = new \LinkDB(self::$testDatastore, true, false);
85 $this->assertFalse(isset($this->linkDB[$id])); 100 $this->assertFalse(isset($this->linkDB[$id]));
101
102 $historyEntry = $this->history->getHistory()[0];
103 $this->assertEquals(\History::DELETED, $historyEntry['event']);
104 $this->assertTrue(
105 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
106 );
107 $this->assertEquals($id, $historyEntry['id']);
86 } 108 }
87 109
88 /** 110 /**
diff --git a/tests/api/controllers/GetLinkIdTest.php b/tests/api/controllers/GetLinkIdTest.php
index 45b18e6a..57528d5a 100644
--- a/tests/api/controllers/GetLinkIdTest.php
+++ b/tests/api/controllers/GetLinkIdTest.php
@@ -62,6 +62,7 @@ class GetLinkIdTest extends \PHPUnit_Framework_TestCase
62 $this->container = new Container(); 62 $this->container = new Container();
63 $this->container['conf'] = $this->conf; 63 $this->container['conf'] = $this->conf;
64 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 64 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false);
65 $this->container['history'] = null;
65 66
66 $this->controller = new Links($this->container); 67 $this->controller = new Links($this->container);
67 } 68 }
diff --git a/tests/api/controllers/GetLinksTest.php b/tests/api/controllers/GetLinksTest.php
index 10330cd9..84ae7f7a 100644
--- a/tests/api/controllers/GetLinksTest.php
+++ b/tests/api/controllers/GetLinksTest.php
@@ -61,6 +61,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
61 $this->container = new Container(); 61 $this->container = new Container();
62 $this->container['conf'] = $this->conf; 62 $this->container['conf'] = $this->conf;
63 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 63 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false);
64 $this->container['history'] = null;
64 65
65 $this->controller = new Links($this->container); 66 $this->controller = new Links($this->container);
66 } 67 }
diff --git a/tests/api/controllers/HistoryTest.php b/tests/api/controllers/HistoryTest.php
index 21e9c0ba..61046d97 100644
--- a/tests/api/controllers/HistoryTest.php
+++ b/tests/api/controllers/HistoryTest.php
@@ -30,11 +30,6 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
30 protected $refHistory = null; 30 protected $refHistory = null;
31 31
32 /** 32 /**
33 * @var \History instance.
34 */
35 protected $history;
36
37 /**
38 * @var Container instance. 33 * @var Container instance.
39 */ 34 */
40 protected $container; 35 protected $container;
@@ -52,10 +47,10 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
52 $this->conf = new ConfigManager('tests/utils/config/configJson.json.php'); 47 $this->conf = new ConfigManager('tests/utils/config/configJson.json.php');
53 $this->refHistory = new \ReferenceHistory(); 48 $this->refHistory = new \ReferenceHistory();
54 $this->refHistory->write(self::$testHistory); 49 $this->refHistory->write(self::$testHistory);
55 $this->conf->set('resource.history', self::$testHistory);
56 $this->container = new Container(); 50 $this->container = new Container();
57 $this->container['conf'] = $this->conf; 51 $this->container['conf'] = $this->conf;
58 $this->container['db'] = true; 52 $this->container['db'] = true;
53 $this->container['history'] = new \History(self::$testHistory);
59 54
60 $this->controller = new History($this->container); 55 $this->controller = new History($this->container);
61 } 56 }
diff --git a/tests/api/controllers/InfoTest.php b/tests/api/controllers/InfoTest.php
index 4beef3f7..e85eb281 100644
--- a/tests/api/controllers/InfoTest.php
+++ b/tests/api/controllers/InfoTest.php
@@ -54,6 +54,7 @@ class InfoTest extends \PHPUnit_Framework_TestCase
54 $this->container = new Container(); 54 $this->container = new Container();
55 $this->container['conf'] = $this->conf; 55 $this->container['conf'] = $this->conf;
56 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 56 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false);
57 $this->container['history'] = null;
57 58
58 $this->controller = new Info($this->container); 59 $this->controller = new Info($this->container);
59 } 60 }
diff --git a/tests/api/controllers/PostLinkTest.php b/tests/api/controllers/PostLinkTest.php
index 3ed7bcb0..31954e39 100644
--- a/tests/api/controllers/PostLinkTest.php
+++ b/tests/api/controllers/PostLinkTest.php
@@ -24,6 +24,11 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase
24 protected static $testDatastore = 'sandbox/datastore.php'; 24 protected static $testDatastore = 'sandbox/datastore.php';
25 25
26 /** 26 /**
27 * @var string datastore to test write operations
28 */
29 protected static $testHistory = 'sandbox/history.php';
30
31 /**
27 * @var ConfigManager instance 32 * @var ConfigManager instance
28 */ 33 */
29 protected $conf; 34 protected $conf;
@@ -34,6 +39,11 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase
34 protected $refDB = null; 39 protected $refDB = null;
35 40
36 /** 41 /**
42 * @var \History instance.
43 */
44 protected $history;
45
46 /**
37 * @var Container instance. 47 * @var Container instance.
38 */ 48 */
39 protected $container; 49 protected $container;
@@ -57,9 +67,14 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase
57 $this->refDB = new \ReferenceLinkDB(); 67 $this->refDB = new \ReferenceLinkDB();
58 $this->refDB->write(self::$testDatastore); 68 $this->refDB->write(self::$testDatastore);
59 69
70 $refHistory = new \ReferenceHistory();
71 $refHistory->write(self::$testHistory);
72 $this->history = new \History(self::$testHistory);
73
60 $this->container = new Container(); 74 $this->container = new Container();
61 $this->container['conf'] = $this->conf; 75 $this->container['conf'] = $this->conf;
62 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 76 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false);
77 $this->container['history'] = new \History(self::$testHistory);
63 78
64 $this->controller = new Links($this->container); 79 $this->controller = new Links($this->container);
65 80
@@ -85,6 +100,7 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase
85 public function tearDown() 100 public function tearDown()
86 { 101 {
87 @unlink(self::$testDatastore); 102 @unlink(self::$testDatastore);
103 @unlink(self::$testHistory);
88 } 104 }
89 105
90 /** 106 /**
@@ -112,6 +128,13 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase
112 $this->assertEquals(false, $data['private']); 128 $this->assertEquals(false, $data['private']);
113 $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])); 129 $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created']));
114 $this->assertEquals('', $data['updated']); 130 $this->assertEquals('', $data['updated']);
131
132 $historyEntry = $this->history->getHistory()[0];
133 $this->assertEquals(\History::CREATED, $historyEntry['event']);
134 $this->assertTrue(
135 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
136 );
137 $this->assertEquals(43, $historyEntry['id']);
115 } 138 }
116 139
117 /** 140 /**
diff --git a/tests/api/controllers/PutLinkTest.php b/tests/api/controllers/PutLinkTest.php
index 4096c1a7..8a562571 100644
--- a/tests/api/controllers/PutLinkTest.php
+++ b/tests/api/controllers/PutLinkTest.php
@@ -18,6 +18,11 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
18 protected static $testDatastore = 'sandbox/datastore.php'; 18 protected static $testDatastore = 'sandbox/datastore.php';
19 19
20 /** 20 /**
21 * @var string datastore to test write operations
22 */
23 protected static $testHistory = 'sandbox/history.php';
24
25 /**
21 * @var ConfigManager instance 26 * @var ConfigManager instance
22 */ 27 */
23 protected $conf; 28 protected $conf;
@@ -28,6 +33,11 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
28 protected $refDB = null; 33 protected $refDB = null;
29 34
30 /** 35 /**
36 * @var \History instance.
37 */
38 protected $history;
39
40 /**
31 * @var Container instance. 41 * @var Container instance.
32 */ 42 */
33 protected $container; 43 protected $container;
@@ -51,9 +61,14 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
51 $this->refDB = new \ReferenceLinkDB(); 61 $this->refDB = new \ReferenceLinkDB();
52 $this->refDB->write(self::$testDatastore); 62 $this->refDB->write(self::$testDatastore);
53 63
64 $refHistory = new \ReferenceHistory();
65 $refHistory->write(self::$testHistory);
66 $this->history = new \History(self::$testHistory);
67
54 $this->container = new Container(); 68 $this->container = new Container();
55 $this->container['conf'] = $this->conf; 69 $this->container['conf'] = $this->conf;
56 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 70 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false);
71 $this->container['history'] = new \History(self::$testHistory);
57 72
58 $this->controller = new Links($this->container); 73 $this->controller = new Links($this->container);
59 74
@@ -71,6 +86,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
71 public function tearDown() 86 public function tearDown()
72 { 87 {
73 @unlink(self::$testDatastore); 88 @unlink(self::$testDatastore);
89 @unlink(self::$testHistory);
74 } 90 }
75 91
76 /** 92 /**
@@ -100,6 +116,13 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
100 \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) 116 \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
101 ); 117 );
102 $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])); 118 $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']));
119
120 $historyEntry = $this->history->getHistory()[0];
121 $this->assertEquals(\History::UPDATED, $historyEntry['event']);
122 $this->assertTrue(
123 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
124 );
125 $this->assertEquals($id, $historyEntry['id']);
103 } 126 }
104 127
105 /** 128 /**