X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FHistoryTest.php;h=d3bef5a332cec8336455d00fc80c51d43b6bae23;hb=86e1bc713fd7fa74d6a17a7687428fa1c6d3c5f2;hp=79322249d0da8ddf3b099dafe9f5c49388e73709;hpb=4306b184c4471825f916d895b047ed03fdf58985;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php index 79322249..d3bef5a3 100644 --- a/tests/HistoryTest.php +++ b/tests/HistoryTest.php @@ -21,9 +21,19 @@ class HistoryTest extends PHPUnit_Framework_TestCase /** * Test that the history file is created if it doesn't exist. */ - public function testConstructFileCreated() + public function testConstructLazyLoading() { new History(self::$historyFilePath); + $this->assertFileNotExists(self::$historyFilePath); + } + + /** + * Test that the history file is created if it doesn't exist. + */ + public function testAddEventCreateFile() + { + $history = new History(self::$historyFilePath); + $history->updateSettings(); $this->assertFileExists(self::$historyFilePath); } @@ -37,7 +47,8 @@ class HistoryTest extends PHPUnit_Framework_TestCase { touch(self::$historyFilePath); chmod(self::$historyFilePath, 0440); - new History(self::$historyFilePath); + $history = new History(self::$historyFilePath); + $history->updateSettings(); } /** @@ -49,8 +60,9 @@ class HistoryTest extends PHPUnit_Framework_TestCase public function testConstructNotParsable() { file_put_contents(self::$historyFilePath, 'not parsable'); + $history = new History(self::$historyFilePath); // gzinflate generates a warning - @new History(self::$historyFilePath); + @$history->updateSettings(); } /** @@ -62,21 +74,21 @@ class HistoryTest extends PHPUnit_Framework_TestCase $history->addLink(['id' => 0]); $actual = $history->getHistory()[0]; $this->assertEquals(History::CREATED, $actual['event']); - $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); + $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); $this->assertEquals(0, $actual['id']); $history = new History(self::$historyFilePath); $history->addLink(['id' => 1]); $actual = $history->getHistory()[0]; $this->assertEquals(History::CREATED, $actual['event']); - $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); + $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); $this->assertEquals(1, $actual['id']); $history = new History(self::$historyFilePath); $history->addLink(['id' => 'str']); $actual = $history->getHistory()[0]; $this->assertEquals(History::CREATED, $actual['event']); - $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); + $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); $this->assertEquals('str', $actual['id']); } @@ -89,7 +101,7 @@ class HistoryTest extends PHPUnit_Framework_TestCase $history->updateLink(['id' => 1]); $actual = $history->getHistory()[0]; $this->assertEquals(History::UPDATED, $actual['event']); - $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); + $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); $this->assertEquals(1, $actual['id']); } @@ -102,7 +114,7 @@ class HistoryTest extends PHPUnit_Framework_TestCase $history->deleteLink(['id' => 1]); $actual = $history->getHistory()[0]; $this->assertEquals(History::DELETED, $actual['event']); - $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); + $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); $this->assertEquals(1, $actual['id']); } @@ -115,7 +127,7 @@ class HistoryTest extends PHPUnit_Framework_TestCase $history->updateSettings(); $actual = $history->getHistory()[0]; $this->assertEquals(History::SETTINGS, $actual['event']); - $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); + $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); $this->assertEmpty($actual['id']); } @@ -128,13 +140,13 @@ class HistoryTest extends PHPUnit_Framework_TestCase $history->updateLink(['id' => 1]); $actual = $history->getHistory()[0]; $this->assertEquals(History::UPDATED, $actual['event']); - $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); + $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); $this->assertEquals(1, $actual['id']); $history->addLink(['id' => 1]); $actual = $history->getHistory()[0]; $this->assertEquals(History::CREATED, $actual['event']); - $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); + $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); $this->assertEquals(1, $actual['id']); } @@ -148,7 +160,7 @@ class HistoryTest extends PHPUnit_Framework_TestCase $history = new History(self::$historyFilePath); $actual = $history->getHistory()[0]; $this->assertEquals(History::UPDATED, $actual['event']); - $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); + $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); $this->assertEquals(1, $actual['id']); } @@ -164,12 +176,12 @@ class HistoryTest extends PHPUnit_Framework_TestCase $history = new History(self::$historyFilePath); $actual = $history->getHistory()[0]; $this->assertEquals(History::CREATED, $actual['event']); - $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); + $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); $this->assertEquals(1, $actual['id']); $actual = $history->getHistory()[1]; $this->assertEquals(History::UPDATED, $actual['event']); - $this->assertTrue(new DateTime('-2 seconds') < DateTime::createFromFormat(DateTime::ATOM, $actual['datetime'])); + $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); $this->assertEquals(1, $actual['id']); } @@ -182,7 +194,7 @@ class HistoryTest extends PHPUnit_Framework_TestCase $history->updateLink(['id' => 1]); $this->assertEquals(1, count($history->getHistory())); $arr = $history->getHistory(); - $arr[0]['datetime'] = (new DateTime('-1 hour'))->format(DateTime::ATOM); + $arr[0]['datetime'] = new DateTime('-1 hour'); FileUtils::writeFlatDB(self::$historyFilePath, $arr); $history = new History(self::$historyFilePath, 60);