diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-05-07 16:50:20 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-05-07 17:11:22 +0200 |
commit | 813849e5216cb87121e0f778a734575be6a36052 (patch) | |
tree | 45605ad43e3f751eba51d19f8c6955c3824e8d32 /tests/api/controllers/PutLinkTest.php | |
parent | a4af59f47103a3f9c903eeddb1e30ab9cb7344f0 (diff) | |
download | Shaarli-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/controllers/PutLinkTest.php')
-rw-r--r-- | tests/api/controllers/PutLinkTest.php | 23 |
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 | /** |