From 813849e5216cb87121e0f778a734575be6a36052 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 7 May 2017 16:50:20 +0200 Subject: Add history entries for API endpoint CHANGED: datetime is now store as an object in history store file --- tests/api/controllers/DeleteLinkTest.php | 22 ++++++++++++++++++++++ tests/api/controllers/GetLinkIdTest.php | 1 + tests/api/controllers/GetLinksTest.php | 1 + tests/api/controllers/HistoryTest.php | 7 +------ tests/api/controllers/InfoTest.php | 1 + tests/api/controllers/PostLinkTest.php | 23 +++++++++++++++++++++++ tests/api/controllers/PutLinkTest.php | 23 +++++++++++++++++++++++ 7 files changed, 72 insertions(+), 6 deletions(-) (limited to 'tests/api') 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 @@ -16,6 +16,11 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase */ protected static $testDatastore = 'sandbox/datastore.php'; + /** + * @var string datastore to test write operations + */ + protected static $testHistory = 'sandbox/history.php'; + /** * @var ConfigManager instance */ @@ -31,6 +36,11 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase */ protected $linkDB; + /** + * @var \History instance. + */ + protected $history; + /** * @var Container instance. */ @@ -50,9 +60,13 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); $this->linkDB = new \LinkDB(self::$testDatastore, true, false); + $refHistory = new \ReferenceHistory(); + $refHistory->write(self::$testHistory); + $this->history = new \History(self::$testHistory); $this->container = new Container(); $this->container['conf'] = $this->conf; $this->container['db'] = $this->linkDB; + $this->container['history'] = $this->history; $this->controller = new Links($this->container); } @@ -63,6 +77,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase public function tearDown() { @unlink(self::$testDatastore); + @unlink(self::$testHistory); } /** @@ -83,6 +98,13 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase $this->linkDB = new \LinkDB(self::$testDatastore, true, false); $this->assertFalse(isset($this->linkDB[$id])); + + $historyEntry = $this->history->getHistory()[0]; + $this->assertEquals(\History::DELETED, $historyEntry['event']); + $this->assertTrue( + (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] + ); + $this->assertEquals($id, $historyEntry['id']); } /** 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 $this->container = new Container(); $this->container['conf'] = $this->conf; $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); + $this->container['history'] = null; $this->controller = new Links($this->container); } 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 $this->container = new Container(); $this->container['conf'] = $this->conf; $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); + $this->container['history'] = null; $this->controller = new Links($this->container); } 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 @@ -29,11 +29,6 @@ class HistoryTest extends \PHPUnit_Framework_TestCase */ protected $refHistory = null; - /** - * @var \History instance. - */ - protected $history; - /** * @var Container instance. */ @@ -52,10 +47,10 @@ class HistoryTest extends \PHPUnit_Framework_TestCase $this->conf = new ConfigManager('tests/utils/config/configJson.json.php'); $this->refHistory = new \ReferenceHistory(); $this->refHistory->write(self::$testHistory); - $this->conf->set('resource.history', self::$testHistory); $this->container = new Container(); $this->container['conf'] = $this->conf; $this->container['db'] = true; + $this->container['history'] = new \History(self::$testHistory); $this->controller = new History($this->container); } 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 $this->container = new Container(); $this->container['conf'] = $this->conf; $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); + $this->container['history'] = null; $this->controller = new Info($this->container); } 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 @@ -23,6 +23,11 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase */ protected static $testDatastore = 'sandbox/datastore.php'; + /** + * @var string datastore to test write operations + */ + protected static $testHistory = 'sandbox/history.php'; + /** * @var ConfigManager instance */ @@ -33,6 +38,11 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase */ protected $refDB = null; + /** + * @var \History instance. + */ + protected $history; + /** * @var Container instance. */ @@ -57,9 +67,14 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); + $refHistory = new \ReferenceHistory(); + $refHistory->write(self::$testHistory); + $this->history = new \History(self::$testHistory); + $this->container = new Container(); $this->container['conf'] = $this->conf; $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); + $this->container['history'] = new \History(self::$testHistory); $this->controller = new Links($this->container); @@ -85,6 +100,7 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase public function tearDown() { @unlink(self::$testDatastore); + @unlink(self::$testHistory); } /** @@ -112,6 +128,13 @@ class PostLinkTest extends \PHPUnit_Framework_TestCase $this->assertEquals(false, $data['private']); $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])); $this->assertEquals('', $data['updated']); + + $historyEntry = $this->history->getHistory()[0]; + $this->assertEquals(\History::CREATED, $historyEntry['event']); + $this->assertTrue( + (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] + ); + $this->assertEquals(43, $historyEntry['id']); } /** 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 @@ -17,6 +17,11 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase */ protected static $testDatastore = 'sandbox/datastore.php'; + /** + * @var string datastore to test write operations + */ + protected static $testHistory = 'sandbox/history.php'; + /** * @var ConfigManager instance */ @@ -27,6 +32,11 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase */ protected $refDB = null; + /** + * @var \History instance. + */ + protected $history; + /** * @var Container instance. */ @@ -51,9 +61,14 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase $this->refDB = new \ReferenceLinkDB(); $this->refDB->write(self::$testDatastore); + $refHistory = new \ReferenceHistory(); + $refHistory->write(self::$testHistory); + $this->history = new \History(self::$testHistory); + $this->container = new Container(); $this->container['conf'] = $this->conf; $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); + $this->container['history'] = new \History(self::$testHistory); $this->controller = new Links($this->container); @@ -71,6 +86,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase public function tearDown() { @unlink(self::$testDatastore); + @unlink(self::$testHistory); } /** @@ -100,6 +116,13 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) ); $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])); + + $historyEntry = $this->history->getHistory()[0]; + $this->assertEquals(\History::UPDATED, $historyEntry['event']); + $this->assertTrue( + (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] + ); + $this->assertEquals($id, $historyEntry['id']); } /** -- cgit v1.2.3