X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fapi%2Fcontrollers%2FPutLinkTest.php;h=8a5625710b5e924cda9d3c5146112b3d3851f353;hb=813849e5216cb87121e0f778a734575be6a36052;hp=4096c1a781e4caf3533bed26d0d8f3c6203e4e3d;hpb=a4af59f47103a3f9c903eeddb1e30ab9cb7344f0;p=github%2Fshaarli%2FShaarli.git 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']); } /**