aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api
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/api
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/api')
-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
7 files changed, 72 insertions, 6 deletions
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 /**