aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/controllers/DeleteLinkTest.php
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/controllers/DeleteLinkTest.php
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/controllers/DeleteLinkTest.php')
-rw-r--r--tests/api/controllers/DeleteLinkTest.php22
1 files changed, 22 insertions, 0 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 /**