aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/controllers/PutLinkTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-05-07 17:40:17 +0200
committerGitHub <noreply@github.com>2017-05-07 17:40:17 +0200
commitb4189928f84758e1589715dfe04e2d966a4f3b88 (patch)
treef17b8fa91fe8244fed7a913d64ce3220551916ff /tests/api/controllers/PutLinkTest.php
parenta4af59f47103a3f9c903eeddb1e30ab9cb7344f0 (diff)
parentb86aeccf6a99a9617c66cded7252a33b1df560cd (diff)
downloadShaarli-b4189928f84758e1589715dfe04e2d966a4f3b88.tar.gz
Shaarli-b4189928f84758e1589715dfe04e2d966a4f3b88.tar.zst
Shaarli-b4189928f84758e1589715dfe04e2d966a4f3b88.zip
Merge pull request #858 from ArthurHoaro/api/history-entries
Add history entries for API endpoint
Diffstat (limited to 'tests/api/controllers/PutLinkTest.php')
-rw-r--r--tests/api/controllers/PutLinkTest.php23
1 files changed, 23 insertions, 0 deletions
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 /**